treevalue.tree.general¶
FastTreeValue¶
-
class
treevalue.tree.general.
FastTreeValue
(*args, **kwargs)[source]¶ - Overview:
Fast tree value, can do almost anything with this.
-
__add__
(other)¶ - Overview:
Add tree values together.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 11, 'b': 22, 'x': {'c': 30, 'd': 40}}) >>> t1 + t2 # FastTreeValue({'a': 12, 'b': 24, 'x': {'c': 33, 'd': 44}})
-
__and__
(other)¶ - Overview:
Bitwise and tree values.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 2, 'b': 3, 'x': {'c': 4, 'd': 5}}) >>> t1 & t2 # FastTreeValue({'a': 0, 'b': 2, 'x': {'c': 0, 'd': 4}})
-
__call__
(*args, **kwargs)¶ - Overview:
Call of tree values.
- Example:
>>> class Container: >>> def __init__(self, value): >>> self.__value = value >>> >>> def append(self, v): >>> return self.__value + v >>> >>> t = FastTreeValue({'a': Container(1), 'b': Container(2)}) >>> t.append(2) # FastTreeValue({'a': 3, 'b': 4}) >>> t.append(FastTreeValue({'a': 10, 'b': 20})) # FastTreeValue({'a': 11, 'b': 22})
-
__delattr__
(key)¶ - Overview:
Delete attribute from tree value.
- Arguments:
key (
str
): Attribute name.
- Example:
>>> t = TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> del t.a # t will be TreeValue({'b': 2, 'x': {'c': 3, 'd': 4}}) >>> del t.x.c # t will be TreeValue({'b': 2, 'x': {'d': 4}})
-
__delitem__
(key)¶ - Overview:
Delete item of tree values.
- Examples:
>>> t1 = FastTreeValue({'a': [1, 2], 'b': [2, 3], 'x': {'c': [3, 4], 'd': [4, 5]}}) >>> del t1[0] # FastTreeValue({'a': [2], 'b': [3], 'x': {'c': [4], 'd': [5]}})
-
__eq__
(other)¶ - Overview:
Check the equality of two tree values.
- Arguments:
other (
TreeValue
): Another tree value.
- Returns:
equal (
bool
): Equality.
- Example:
>>> t = TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> clone(t) == t # True >>> t == TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 5}}) # False >>> t == TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) # True >>> t == FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) # False (type not match)
-
__floordiv__
(other)¶ - Overview:
Floor divide tree values.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 10, 'b': 25, 'x': {'c': 30, 'd': 40}}) >>> t2 // t1 # FastTreeValue({'a': 10, 'b': 12, 'x': {'c': 10, 'd': 10}})
-
__getattr__
(key)¶ - Overview:
Get item from this tree value.
- Arguments:
key (
str
): Attribute name.
- Returns:
attr (:obj:): Target attribute value.
- Example:
>>> t = TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.a # 1 >>> t.b # 2 >>> t.x.c # 3
-
__getitem__
(item)¶ - Overview:
Get item of tree values.
- Examples:
>>> t1 = FastTreeValue({'a': [1, 2], 'b': [2, 3], 'x': {'c': [3, 4], 'd': [4, 5]}}) >>> t1[0] # FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t1[-1] # FastTreeValue({'a': 2, 'b': 3, 'x': {'c': 4, 'd': 5}}) >>> t1[::-1] # FastTreeValue({'a': [2, 1], 'b': [3, 2], 'x': {'c': [4, 3], 'd': [5, 4]}})
-
__hash__
()¶ - Overview:
Hash value of current object.
- Returns:
hash (
int
): Hash code of current object.
-
__invert__
()¶ - Overview:
Bitwise invert tree values.
- Examples:
>>> t1 = FastTreeValue({'a': 1, 'b': -2, 'x': {'c': 3, 'd': -4}}) >>> ~t1 # FastTreeValue({'a': -2, 'b': 1, 'x': {'c': -4, 'd': 3}})
-
__iter__
()¶ - Overview:
Get iterator of this tree value.
- Returns:
iter (
iter
): Iterator for keys and values.
- Example:
>>> t = TreeValue({'a': 1, 'b': 2, 'x': 3}) >>> for key, value in t: >>> print(key, value)
The output will be:
>>> a 1 >>> b 2 >>> x 3
-
__lshift__
(other)¶ - Overview:
Left shift tree values.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 2, 'b': 3, 'x': {'c': 4, 'd': 5}}) >>> t1 << t2 # FastTreeValue({'a': 4, 'b': 16, 'x': {'c': 48, 'd': 128}})
-
__matmul__
(other)¶ - Overview:
Matrix tree values together, can be used in numpy or torch.
-
__mod__
(other)¶ - Overview:
Mod tree values.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 10, 'b': 25, 'x': {'c': 30, 'd': 40}}) >>> t2 % t1 # FastTreeValue({'a': 0, 'b': 1, 'x': {'c': 0, 'd': 0}})
-
__mul__
(other)¶ - Overview:
Multiply tree values together.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 11, 'b': 22, 'x': {'c': 30, 'd': 40}}) >>> t1 * t2 # FastTreeValue({'a': 11, 'b': 44, 'x': {'c': 90, 'd': 160}})
-
__neg__
()¶ - Overview:
Negative tree values.
- Examples:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> -t1 # FastTreeValue({'a': -1, 'b': -2, 'x': {'c': -3, 'd': -4}})
-
__or__
(other)¶ - Overview:
Bitwise or tree values.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 2, 'b': 3, 'x': {'c': 4, 'd': 5}}) >>> t1 | t2 # FastTreeValue({'a': 3, 'b': 3, 'x': {'c': 7, 'd': 5}})
-
__pos__
()¶ - Overview:
Positive tree values.
- Examples:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> +t1 # FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}})
-
__pow__
(power)¶ - Overview:
Mod tree values.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 2, 'b': 3, 'x': {'c': 4, 'd': 5}}) >>> t1 ** t2 # FastTreeValue({'a': 1, 'b': 8, 'x': {'c': 81, 'd': 1024}})
-
__radd__
(other)¶ - Overview:
Right version of __add__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 1 + t1 # FastTreeValue({'a': 2, 'b': 3, 'x': {'c': 4, 'd': 5}})
-
__rand__
(other)¶ - Overview:
Right version of __and__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 5 & t1 # FastTreeValue({'a': 1, 'b': 0, 'x': {'c': 1, 'd': 4}})
-
__repr__
()¶ - Overview:
Get representation format of tree value.
- Returns:
repr (
str
): Representation string.
- Example:
>>> t = TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> repr(t) # <TreeValue 0xffffffff keys: ['a', 'b', 'x']>, the is may be different
-
__rfloordiv__
(other)¶ - Overview:
Right version of __floordiv__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 6 // t1 # FastTreeValue({'a': 6, 'b': 3, 'x': {'c': 2, 'd': 1}})
-
__rlshift__
(other)¶ - Overview:
Right version of __lshift__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 3 << t1 # FastTreeValue({'a': 6, 'b': 12, 'x': {'c': 24, 'd': 48}})
-
__rmatmul__
(other)¶ - Overview:
Right version of __matmul__.
-
__rmod__
(other)¶ - Overview:
Right version of __mod__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 6 % t1 # FastTreeValue({'a': 0, 'b': 0, 'x': {'c': 0, 'd': 2}})
-
__rmul__
(other)¶ - Overview:
Right version of __mul__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 2 * t1 # FastTreeValue({'a': 2, 'b': 4, 'x': {'c': 6, 'd': 8}})
-
__ror__
(other)¶ - Overview:
Right version of __or__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 5 | t1 # FastTreeValue({'a': 5, 'b': 7, 'x': {'c': 7, 'd': 5}})
-
__rpow__
(other)¶ - Overview:
Right version of __pow__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 2 ** t1 # FastTreeValue({'a': 2, 'b': 4, 'x': {'c': 8, 'd': 16}})
-
__rrshift__
(other)¶ - Overview:
Right version of __rshift__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 64 >> t1 # FastTreeValue({'a': 32, 'b': 16, 'x': {'c': 8, 'd': 4}})
-
__rshift__
(other)¶ - Overview:
Left shift tree values.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 20, 'b': 30, 'x': {'c': 40, 'd': 50}}) >>> t2 >> t1 # FastTreeValue({'a': 10, 'b': 7, 'x': {'c': 5, 'd': 3}})
-
__rsub__
(other)¶ - Overview:
Right version of __sub__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 1 - t1 # FastTreeValue({'a': 0, 'b': -1, 'x': {'c': -2, 'd': -3}})
-
__rtruediv__
(other)¶ - Overview:
Right version of __truediv__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 6 / t1 # FastTreeValue({'a': 6, 'b': 3, 'x': {'c': 2, 'd': 1.5}})
-
__rxor__
(other)¶ - Overview:
Right version of __xor__.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> 5 ^ t1 # FastTreeValue({'a': 4, 'b': 7, 'x': {'c': 6, 'd': 1}})
-
__setattr__
(key, value)¶ - Overview:
Set sub node to this tree value.
- Arguments:
key (
str
): Attribute name.value (:obj:): Sub value.
- Example:
>>> t = TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.a = 3 # t will be TreeValue({'a': 3, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.b = {'x': 1, 'y': 2} # t will be TreeValue({'a': 3, 'b': {'x': 1, 'y': 2}, 'x': {'c': 3, 'd': 4}})
-
__setitem__
(key, value)¶ - Overview:
Set item of tree values.
- Examples:
>>> t1 = FastTreeValue({'a': [1, 2], 'b': [2, 3], 'x': {'c': [3, 4], 'd': [4, 5]}}) >>> t1[0] = -2 # FastTreeValue({'a': [-2, 2], 'b': [-2, 3], 'x': {'c': [-2, 4], 'd': [-2, 5]}}) >>> t1[0] = FastTreeValue({'a': 2, 'b': 3, 'x': {'c': 4, 'd': 5}}) >>> # FastTreeValue({'a': [2, 2], 'b': [3, 3], 'x': {'c': [4, 4], 'd': [5, 5]}})
-
__str__
()¶ - Overview:
Get the structure of the tree.
- Returns:
str (
str
): Returned string.
-
__sub__
(other)¶ - Overview:
Substract tree values.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 11, 'b': 22, 'x': {'c': 30, 'd': 40}}) >>> t1 - t2 # FastTreeValue({'a': -10, 'b': -20, 'x': {'c': -27, 'd': -36}})
-
__truediv__
(other)¶ - Overview:
True divide tree values.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 10, 'b': 25, 'x': {'c': 30, 'd': 40}}) >>> t1 / t2 # FastTreeValue({'a': 0.1, 'b': 0.08, 'x': {'c': 0.1, 'd': 0.1}})
-
__xor__
(other)¶ - Overview:
Bitwise or tree values.
- Example:
>>> t1 = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t2 = FastTreeValue({'a': 2, 'b': 3, 'x': {'c': 4, 'd': 5}}) >>> t1 ^ t2 # FastTreeValue({'a': 3, 'b': 1, 'x': {'c': 7, 'd': 1}})
-
_attr_extern
(key)¶ - Overview:
External protected function for support the unfounded attributes. In FastTreeValue it is extended to support the access to values’ attribute.
- Arguments:
key (
str
): Attribute name.
- Returns:
return (:obj:): TreeValue of the values’ attribute.
- Example:
>>> class Container: >>> def __init__(self, value): >>> self.__value = value >>> >>> @property >>> def value(self): >>> return self.__value >>> >>> def append(self, v): >>> return self.__value + v >>> >>> t = FastTreeValue({'a': Container(1), 'b': Container(2)}) >>> t.value # FastTreeValue({'a': 1, 'b': 2}) >>> t.append # FastTreeValue({'a': <method 'append' of Container(1)>, 'b': <method 'append' of Container(2)>})
-
clone
(copy_value: Union[None, bool, Callable, Any] = None)¶ - Overview:
Create a fully clone of the current tree.
- Returns:
tree (
_TreeValue
): Cloned tree value object.copy_value (
Union[None, bool, Callable, Any]
): Deep copy value or not, default is None which means do not deep copy the values. If deep copy is required, just set it to True.
- Example:
>>> t = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.x.clone() # FastTreeValue({'c': 3, 'd': 4})
-
filter
(func, remove_empty: bool = True)¶ - Overview:
Filter the element in the tree with a predict function.
- Arguments:
func (:obj:): Function for filtering
remove_empty (
bool
): Remove empty tree node automatically, default is True.
- Returns:
tree (
_TreeValue
): Filtered tree value object.
- Example:
>>> t = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.filter(lambda x: x < 3) # FastTreeValue({'a': 1, 'b': 2}) >>> t.filter(lambda x: x < 3, False) # FastTreeValue({'a': 1, 'b': 2, 'x': {}}) >>> t.filter(lambda x: x % 2 == 1) # FastTreeValue({'a': 1, 'x': {'c': 3}}) >>> t.filter(lambda x, p: p[0] in {'b', 'x'}) # FastTreeValue({'b': 2, 'x': {'c': 3, 'd': 4}})
-
json
()¶ - Overview:
Dump current TreeValue object to json data.
- Returns:
json (
dict
): Dumped json data.
- Example:
>>> t = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.json() # {'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}
-
map
(mapper)¶ - Overview:
Do mapping on every value in this tree.
- Arguments:
func (:obj:): Function for mapping
- Returns:
tree (
_TreeValue
): Mapped tree value object.
- Example:
>>> t = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.map(lambda x: x + 2) # FastTreeValue({'a': 3, 'b': 4, 'x': {'c': 5, 'd': 6}}) >>> t.map(lambda: 1) # FastTreeValue({'a': 1, 'b': 1, 'x': {'c': 1, 'd': 1}}) >>> t.map(lambda x, p: p) # FastTreeValue({'a': ('a',), 'b': ('b',), 'x': {'c': ('x', 'c'), 'd': ('x', 'd')}})
-
mask
(mask_: treevalue.tree.tree.tree.TreeValue, remove_empty: bool = True)¶ - Overview:
Filter the element in the tree with a mask
- Arguments:
mask_ (
TreeValue
): Tree value mask objectremove_empty (
bool
): Remove empty tree node automatically, default is True.
- Returns:
tree (
_TreeValue
): Filtered tree value object.
- Example:
>>> t = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.mask(TreeValue({'a': True, 'b': False, 'x': False})) # FastTreeValue({'a': 1}) >>> t.mask(TreeValue({'a': True, 'b': False, 'x': {'c': True, 'd': False}})) # FastTreeValue({'a': 1, 'x': {'c': 3}})
-
reduce
(func)¶ - Overview
Reduce the tree to value.
- Arguments:
func (:obj:): Function for reducing
- Returns:
result (:obj:): Reduce result
- Examples:
>>> from functools import reduce >>> >>> t = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.reduce(lambda **kwargs: sum(kwargs.values())) # 10, 1 + 2 + (3 + 4) >>> t.reduce(lambda **kwargs: reduce(lambda x, y: x * y, list(kwargs.values()))) # 24, 1 * 2 * (3 * 4)
-
rise
(dict_: bool = True, list_: bool = True, tuple_: bool = True, template=<SingletonMark 'no_rise_template'>)¶ - Overview:
Make the structure (dict, list, tuple) in value rise up to the top, above the tree value.
- Arguments:
dict_ (
bool
): Enable dict rise, default is True.list_ (
bool
): Enable list rise, default is True.tuple_ (
bool
): Enable list rise, default is True.template (:obj:): Rising template, default is NO_RISE_TEMPLATE, which means auto detect.
- Returns:
risen (:obj:): Risen value.
- Example:
>>> t = FastTreeValue({'x': raw({'a': [1, 2], 'b': [2, 3]}), 'y': raw({'a': [5, 6, 7], 'b': [7, 8]})}) >>> dt = t.rise() >>> # dt will be {'a': <FastTreeValue 1>, 'b': [<FastTreeValue 2>, <FastTreeValue 3>]} >>> # FastTreeValue 1 will be FastTreeValue({'x': [1, 2], 'y': [5, 6, 7]}) >>> # FastTreeValue 2 will be FastTreeValue({'x': 2, 'y': 7}) >>> # FastTreeValue 3 will be FastTreeValue({'x': 3, 'y': 8}) >>> >>> t2 = FastTreeValue({'x': raw({'a': [1, 2], 'b': [2, 3]}), 'y': raw({'a': [5, 6], 'b': [7, 8]})}) >>> dt2 = t2.rise() >>> # dt2 will be {'a': [<FastTreeValue 1>, <FastTreeValue 2>], 'b': [<FastTreeValue 3>, <FastTreeValue 4>]} >>> # FastTreeValue 1 will be FastTreeValue({'x': 1, 'y': 5}) >>> # FastTreeValue 2 will be FastTreeValue({'x': 2, 'y': 6}) >>> # FastTreeValue 3 will be FastTreeValue({'x': 2, 'y': 7}) >>> # FastTreeValue 4 will be FastTreeValue({'x': 3, 'y': 8}) >>> >>> dt3 = t2.rise(template={'a': None, 'b': None}) >>> # dt3 will be {'a': <FastTreeValue 1>, 'b': <FastTreeValue 2>} >>> # FastTreeValue 1 will be FastTreeValue({'x': [1, 2], 'y': [5, 6]}) >>> # FastTreeValue 2 will be FastTreeValue({'x': [2, 3], 'y': [7, 8]})
-
classmethod
subside
(value, dict_: bool = True, list_: bool = True, tuple_: bool = True, return_type: Optional[Type[_TreeValue]] = None, **kwargs)¶ - Overview:
Drift down the structures (list, tuple, dict) down to the tree’s value.
- Arguments:
value (:obj:): Original value object, may be nested dict, list or tuple.
dict_ (
bool
): Enable dict subside, default is True.list_ (
bool
): Enable list subside, default is True.tuple_ (
bool
): Enable list subside, default is True.mode (:obj:): Mode of the wrapping (string or TreeMode both okay), default is strict.
return_type (
Optional[Type[_ClassType]]
): Return type of the wrapped function, will be auto detected when there is exactly one tree value type in this original value, otherwise the default will be TreeValue.inherit (
bool
): Allow inherit in wrapped function, default is True.missing (:obj:): Missing value or lambda generator of when missing, default is MISSING_NOT_ALLOW, which means raise KeyError when missing detected.
- Returns:
return (
_TreeValue
): Subsided tree value.
- Example:
>>> data = { >>> 'a': TreeValue({'a': 1, 'b': 2}), >>> 'x': { >>> 'c': TreeValue({'a': 3, 'b': 4}), >>> 'd': [ >>> TreeValue({'a': 5, 'b': 6}), >>> TreeValue({'a': 7, 'b': 8}), >>> ] >>> }, >>> 'k': '233' >>> } >>> >>> tree = FastTreeValue.subside(data) >>> # tree should be --> FastTreeValue({ >>> # 'a': raw({'a': 1, 'k': '233', 'x': {'c': 3, 'd': [5, 7]}}), >>> # 'b': raw({'a': 2, 'k': '233', 'x': {'c': 4, 'd': [6, 8]}}), >>> #}), all structures above the tree values are subsided to the bottom of the tree.
-
type
(clazz: Type[_TreeValue]) → _TreeValue¶ - Overview:
Transform tree value object to another tree value type. Attention that in this function, no copy will be made, the original tree value and the transformed tree value are using the same space area.
- Arguments:
return_type (
Type[_TreeValue]
): Target tree value type
- Returns:
tree (
_TreeValue
): Transformed tree value object.
- Example:
>>> t = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.type(TreeValue) # TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}})
-
classmethod
union
(*trees, return_type=None, **kwargs)¶ - Overview:
Union tree values together.
- Arguments:
trees (
_TreeValue
): Tree value objects.mode (:obj:): Mode of the wrapping (string or TreeMode both okay), default is strict.
return_type (
Optional[Type[_ClassType]]
): Return type of the wrapped function, default is TreeValue.inherit (
bool
): Allow inherit in wrapped function, default is True.missing (:obj:): Missing value or lambda generator of when missing, default is MISSING_NOT_ALLOW, which means raise KeyError when missing detected.
- Returns:
result (
TreeValue
): Unionised tree value.
- Example:
>>> t = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> tx = t.map(lambda v: v % 2 == 1) >>> FastTreeValue.union(t, tx) # FastTreeValue({'a': (1, True), 'b': (2, False), 'x': {'c': (3, True), 'd': (4, False)}})
-
view
(path: List[str])¶ - Overview:
Create a TreeValue object which is a view of the current tree.
- Arguments:
path (
List[str]
): Path of the view.
- Returns:
tree (
_TreeValue
): Viewed tree value object.
- Example:
>>> t = FastTreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) >>> t.view(['x']) # FastTreeValue({'c': 3, 'd': 4}), it is a view not the real node
general_tree_value¶
-
treevalue.tree.general.
general_tree_value
(base: Optional[Mapping[str, Any]] = None, methods: Optional[Mapping[str, Optional[Mapping[str, Any]]]] = None)[source]¶ - Overview:
Get general tree value class.
- Arguments:
base (
Optional[Mapping[str, Any]]
): Base configuration of func_treelize.methods (
Optional[Mapping[str, Optional[Mapping[str, Any]]]]
): Method configurations of func_treelize.
- Returns:
clazz (
Type[TreeValue]
): General tree value class.