Skip to content

Commit c2768a4

Browse files
committed
define subkey, vkey, vdict interface
1 parent 7c61c96 commit c2768a4

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

vflow/subkey.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def mismatches(self, other: object):
6666
cond2 = self.origin == other.origin and self.value != other.value
6767
return (cond0 or cond1) and cond2
6868
return True
69+
70+
def __copy__(self):
71+
"""Return a copy of this Subkey
72+
"""
73+
pass
6974

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

vflow/vdict.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Vdict key tuple wrapper class
2+
"""
3+
from typing import Tuple, Union
4+
5+
class Vdict:
6+
7+
def __init__(self):
8+
pass
9+
10+
def to_pandas(self, copy=False):
11+
"""Return a pandas.DataFrame representation of the Vdict.
12+
"""
13+
pass
14+
15+
def __getitem__(self, *subkeys: Union[str, Tuple[str, str]], copy=False):
16+
"""Return a new Vdict with a subset of the items in self by filtering keys
17+
based on subkey values. If copy=True, then make a deep copy of Vkeys and values.
18+
19+
Examples:
20+
preds[`preproc_0`, `RF`] => Vdict with all items that have subkey
21+
with value `preproc_0` and another with `RF`
22+
`preproc_0` in preds => bool
23+
(`model`, `RF`) in preds => bool
24+
"""
25+
pass

vflow/vkey.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""Vdict key tuple wrapper class
2+
"""
3+
from typing import Tuple, Union
4+
5+
class Vkey:
6+
7+
def __init__(self, subkeys, origin: str, method: str):
8+
"""
9+
Parameters
10+
----------
11+
subkeys: tuple
12+
tuple of subkeys to associate with this Vkey
13+
origin: str
14+
string attribute that identifies the Vset that created this Vkey
15+
method: str
16+
String attribute that identifies the Vset method that was called to create
17+
this Vkey
18+
"""
19+
self._subkeys = subkeys
20+
self.origin = origin
21+
self.method = method
22+
23+
def subkeys(self):
24+
"""Return a tuple of the Subkeys in this Vkey.
25+
"""
26+
return self._subkeys
27+
28+
def get_origins(self):
29+
"""Return a tuple of strings with the origins of the Subkeys in this Vkey.
30+
"""
31+
return (sk.origin for sk in self.subkeys())
32+
33+
def get_values(self):
34+
"""Return a tuple of strings with the values of the Subkeys in this Vkey.
35+
"""
36+
return (sk.value for sk in self.subkeys())
37+
38+
def __contains__(self, *subkeys: Union[str, Tuple[str, str]]):
39+
"""Returns True if subkeys that are strings overlap with self.get_values()
40+
and if subkeys that are string tuples like (`origin`, `value`) have
41+
corresponding matches in both self.get_origins() and self.get_values().
42+
43+
Examples:
44+
`preproc_0` in vkey => bool
45+
(`model`, `RF`) in vkey => bool
46+
"""
47+
pass
48+
49+
def __add__(self, other: 'Vkey'):
50+
"""Return a new Vkey by combining this Vkey with other, following Subkey
51+
matching rules. Returns an empty Vkey if there are any Subkey mismatches.
52+
"""
53+
pass
54+
55+
def __copy__(self):
56+
"""Return a copy of this Vkey (but not its Subkeys).
57+
"""
58+
pass
59+
60+
def __deepcopy__(self):
61+
"""Return a copy of this Vkey and its Subkeys.
62+
"""
63+
pass
64+
65+
def __len__(self):
66+
"""Return the number of Subkeys in this Vkey.
67+
"""
68+
return len(self.subkeys())

0 commit comments

Comments
 (0)