elasticai.creator.ir.attribute#
Module Contents#
Classes#
Functions#
Create AttributeMapping from other (native) data types recursively. |
API#
- class elasticai.creator.ir.attribute.AttributeMapping(**kwargs: elasticai.creator.ir.attribute.Attribute)[source]#
Bases:
collections.abc.Mapping[str,elasticai.creator.ir.attribute.Attribute]- update_path(path: tuple[str, ...], value: elasticai.creator.ir.attribute.Attribute) Self[source]#
update the entry found when following the path into nested Mappings
- merge(other: collections.abc.Mapping) Self[source]#
merge over nested mappings recursively
So instead of replacing a value found under a key, this checks wether that value is again an AttributeMapping and if so, updates it by the corresponding Mapping found in other. This happens recursively.
Opposed to that
new_withand the|operator only allow to update values in the most outer AttributeMapping. Therefore using these to update a value in a nested structure, users would have to recreate the whole outer mapping structure until they reach the mapping they want to update.Use Case:
If you would want to write
data = dict(a=dict(b=1, c=2)) data["a"]["b"] = 3 assert data["a"]["c"] == 2
You can instead
data = AttributeMapping(a=AttributeMapping(b=1, c=2)) data = data.merge(dict(a=dict(b=3))) assert data["a"]["c"] == 2
If you want to update a single value, you can use the
update_path()function instead to avoid having to build all the nested dictionaries.
- new_with(**kwargs: elasticai.creator.ir.attribute.Attribute) elasticai.creator.ir.attribute.AttributeMapping[source]#
replace key, value pairs in self by key, value pairs in kwargs
- classmethod from_dict(data: dict) elasticai.creator.ir.attribute.AttributeMapping[source]#
- elasticai.creator.ir.attribute.attribute(arg: collections.abc.Mapping[str, elasticai.creator.ir.attribute.AttributeConvertable] | elasticai.creator.ir.attribute.AttributeMapping | elasticai.creator.ir.attribute.Attribute | None = None, /, **kwargs: elasticai.creator.ir.attribute.AttributeConvertable) elasticai.creator.ir.attribute.AttributeMapping | tuple[elasticai.creator.ir.attribute.Attribute] | elasticai.creator.ir.attribute.Attribute[source]#
Create AttributeMapping from other (native) data types recursively.
The implementation assumes that any encountered AttributeMapping objects are correct, ie. they only contain Attributes themselves.