Skip to content

Commit

Permalink
implement vkey
Browse files Browse the repository at this point in the history
implements vkey according to current Subkey obj

TODO: consider Subkey.meta and try smart Vkey/Subkey partitioning
  • Loading branch information
rushk014 committed Apr 10, 2022
1 parent b96dc7e commit 4434616
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
1 change: 0 additions & 1 deletion vflow/subkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def mismatches(self, other: object):
def __copy__(self):
"""Return a copy of this Subkey
"""
pass

def __eq__(self, other: object):
"""Mainly used for testing purposes.
Expand Down
6 changes: 2 additions & 4 deletions vflow/vdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
class Vdict:

def __init__(self):
pass
self._dict = {}

def to_pandas(self, copy=False):
"""Return a pandas.DataFrame representation of the Vdict.
"""
pass

def __getitem__(self, *subkeys: Union[str, Tuple[str, str]], copy=False):
"""Return a new Vdict with a subset of the items in self by filtering keys
Expand All @@ -21,5 +20,4 @@ def __getitem__(self, *subkeys: Union[str, Tuple[str, str]], copy=False):
with value `preproc_0` and another with `RF`
`preproc_0` in preds => bool
(`model`, `RF`) in preds => bool
"""
pass
"""
27 changes: 18 additions & 9 deletions vflow/vkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
"""
from typing import Tuple, Union

from vflow.utils import combine_keys

class Vkey:

def __init__(self, subkeys, origin: str, method: str):
"""
Parameters
----------
subkeys: tuple
tuple of subkeys to associate with this Vkey
Tuple of Subkey objects to associate with this Vkey.
origin: str
string attribute that identifies the Vset that created this Vkey
String attribute that identifies the Vset that created this Vkey.
method: str
String attribute that identifies the Vset method that was called to create
this Vkey
this Vkey.
"""
self._subkeys = subkeys
self.origin = origin
self.method = method

def subkeys(self):
"""Return a tuple of the Subkeys in this Vkey.
"""Return a tuple of the Subkey objects in this Vkey.
"""
return self._subkeys

Expand All @@ -44,23 +46,30 @@ def __contains__(self, *subkeys: Union[str, Tuple[str, str]]):
`preproc_0` in vkey => bool
(`model`, `RF`) in vkey => bool
"""
pass
_values = self.get_values()
_sktuples = zip(self.get_origins(), _values)
for subkey in subkeys:
if isinstance(subkey, str) and subkey in _values:
return True
if isinstance(subkey, tuple) and subkey in _sktuples:
return True
return False

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

def __copy__(self):
"""Return a copy of this Vkey (but not its Subkeys).
"""
pass
return Vkey(self.subkeys(), self.origin, self.method)

def __deepcopy__(self):
def __deepcopy__(self, memo):
"""Return a copy of this Vkey and its Subkeys.
"""
pass
return Vkey((sk.__copy__() for sk in self.subkeys()), self.origin, self.method)

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

0 comments on commit 4434616

Please sign in to comment.