22"""
33from typing import Tuple , Union
44
5+ from vflow .utils import combine_keys
6+
57class 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