Skip to content

Commit 05098a2

Browse files
committed
implement vkey
implements vkey according to current Subkey obj TODO: consider Subkey.meta and try smart Vkey/Subkey partitioning
1 parent c2768a4 commit 05098a2

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

vflow/subkey.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def mismatches(self, other: object):
7070
def __copy__(self):
7171
"""Return a copy of this Subkey
7272
"""
73-
pass
7473

7574
def __eq__(self, other: object):
7675
"""Mainly used for testing purposes.

vflow/vdict.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
class Vdict:
66

77
def __init__(self):
8-
pass
8+
self._dict = {}
99

1010
def to_pandas(self, copy=False):
1111
"""Return a pandas.DataFrame representation of the Vdict.
1212
"""
13-
pass
1413

1514
def __getitem__(self, *subkeys: Union[str, Tuple[str, str]], copy=False):
1615
"""Return a new Vdict with a subset of the items in self by filtering keys
@@ -21,5 +20,4 @@ def __getitem__(self, *subkeys: Union[str, Tuple[str, str]], copy=False):
2120
with value `preproc_0` and another with `RF`
2221
`preproc_0` in preds => bool
2322
(`model`, `RF`) in preds => bool
24-
"""
25-
pass
23+
"""

vflow/vkey.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22
"""
33
from typing import Tuple, Union
44

5+
from vflow.utils import combine_keys
6+
57
class Vkey:
68

79
def __init__(self, subkeys, origin: str, method: str):
810
"""
911
Parameters
1012
----------
1113
subkeys: tuple
12-
tuple of subkeys to associate with this Vkey
14+
Tuple of Subkey objects to associate with this Vkey.
1315
origin: str
14-
string attribute that identifies the Vset that created this Vkey
16+
String attribute that identifies the Vset that created this Vkey.
1517
method: str
1618
String attribute that identifies the Vset method that was called to create
17-
this Vkey
19+
this Vkey.
1820
"""
1921
self._subkeys = subkeys
2022
self.origin = origin
2123
self.method = method
2224

2325
def subkeys(self):
24-
"""Return a tuple of the Subkeys in this Vkey.
26+
"""Return a tuple of the Subkey objects in this Vkey.
2527
"""
2628
return self._subkeys
2729

@@ -44,23 +46,30 @@ def __contains__(self, *subkeys: Union[str, Tuple[str, str]]):
4446
`preproc_0` in vkey => bool
4547
(`model`, `RF`) in vkey => bool
4648
"""
47-
pass
49+
_values = self.get_values()
50+
_sktuples = zip(self.get_origins(), _values)
51+
for subkey in subkeys:
52+
if isinstance(subkey, str) and subkey in _values:
53+
return True
54+
if isinstance(subkey, tuple) and subkey in _sktuples:
55+
return True
56+
return False
4857

4958
def __add__(self, other: 'Vkey'):
5059
"""Return a new Vkey by combining this Vkey with other, following Subkey
5160
matching rules. Returns an empty Vkey if there are any Subkey mismatches.
5261
"""
53-
pass
62+
return Vkey(combine_keys(self.subkeys(), other.subkeys()), self.origin, self.method)
5463

5564
def __copy__(self):
5665
"""Return a copy of this Vkey (but not its Subkeys).
5766
"""
58-
pass
67+
return Vkey(self.subkeys(), self.origin, self.method)
5968

60-
def __deepcopy__(self):
69+
def __deepcopy__(self, memo):
6170
"""Return a copy of this Vkey and its Subkeys.
6271
"""
63-
pass
72+
return Vkey((sk.__copy__() for sk in self.subkeys()), self.origin, self.method)
6473

6574
def __len__(self):
6675
"""Return the number of Subkeys in this Vkey.

0 commit comments

Comments
 (0)