shnitsel.data.tree.data_group#

Attributes#

Classes#

GroupInfo

Class to hold auxiliary info of a group/collection of Data in ShnitselDB

DataGroup

Module Contents#

DataType#
ResType#
KeyType#
NewChildType#
class GroupInfo#

Class to hold auxiliary info of a group/collection of Data in ShnitselDB

group_name: str#
group_attributes: dict[str, Any] | None = None#
grouped_properties: dict[str, float | str | int] | None = None#
class DataGroup(*, name=None, group_info=None, children=None, attrs=None, level_name=None, **kwargs)#

Bases: Generic[DataType], shnitsel.data.tree.node.TreeNode[DataGroup[DataType]|DataLeaf[DataType], DataType]

Parameters:
  • name (str | None)

  • group_info (GroupInfo | None)

  • children (Mapping[Hashable, DataGroup[DataType]|DataLeaf[DataType]] | None)

  • attrs (Mapping[str, Any] | None)

  • level_name (str | None)

_group_info: GroupInfo | None = None#
construct_copy(children: Mapping[Hashable, DataGroup[DataType] | DataLeaf[DataType]] | None = None, dtype: None = None, data: DataType | None = None, **kwargs) Self#
construct_copy(children: None = None, dtype: type[ResType] | types.UnionType | None = None, data: ResType | None = None, **kwargs) DataGroup[ResType]
construct_copy(children: Mapping[Hashable, NewChildType] | None = None, dtype: type[ResType] | types.UnionType | None = None, data: None = None, **kwargs) DataGroup[ResType]

Helper function to create a copy of this tree structure, but with potential changes to metadata, data or children

Parameters:#

data: None, optional

Data setting not supported on this type of node.

children: Mapping[Hashable, DataGroup[ResType]], optional

The mapping of children with a potentially new DataType. If not provided, will be copied from the current node’s child nodes.

dtype: type[ResType] | TypeForm[ResType], optional

The data type of the data in the copy constructed tree.

Returns:#

Self: A copy of this node with recursively copied children if children is not set with an appropriate mapping.

collect_data_nodes()#

Function to retrieve all nodes with data in this subtree

Returns:

List of all nodes with DataLeaf Type in this tree.

Return type:

list[DataLeaf[DataType]]

property is_flat_group: bool#

Boolean flag that is true if there are no more sub-groups beneath this group, thus making the children of this group exclusively data-nodes.

Return type:

bool

property group_info: GroupInfo#
Return type:

GroupInfo

property subgroups: Mapping[Hashable, DataGroup[DataType]]#
Return type:

Mapping[Hashable, DataGroup[DataType]]

property subleaves: Mapping[Hashable, DataLeaf[DataType]]#
Return type:

Mapping[Hashable, DataLeaf[DataType]]

group_children_by(key_func, group_leaves_only=False)#

Specialization of the group_children_by function for group nodes, where grouping may need to be performed on subsets of their children.

Returns:

Generally returns the same node type, potentially with updated children and an additional layer of DataGroup nodes underneath

Return type:

Self

Parameters: