shnitsel.data.tree.data_leaf#

Attributes#

Classes#

DataLeaf

Class to represent a leaf node holding data in the ShnitselDB tree hierarchy.

ProvidesDelayedData

Helper class to encapsulate data that is not immediately accessible but may be provided by asynchronous loading or by

DelayedDataLeaf

Class to hold data in a leaf of the tree structure,

Module Contents#

DataType#
ResType#
NewChildType#
class DataLeaf(*, name=None, data=None, **kwargs)#

Bases: Generic[DataType], shnitsel.data.tree.node.TreeNode[None, DataType]

Class to represent a leaf node holding data in the ShnitselDB tree hierarchy.

May be inherited from to provide leaves with more advanced features like provision of delayed results for support of parallel processing or delayed loading from disc, etc.

Parameters:
  • name (str | None)

  • data (DataType | None)

construct_copy(children: Mapping[Hashable, None] | 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) DataLeaf[ResType]
construct_copy(children: Mapping[Hashable, NewChildType] | None = None, dtype: type[ResType] | types.UnionType | None = None, data: None = None, **kwargs) DataLeaf[ResType]

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

Parameters:#

data: ResType | None, optional

Data to replace the current data in the copy of this node

children: None, optional

Parameter not supported by this type of node.

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

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

raises AssertionError:

If dtype is set without a new data entry being provided

raises Returns::

raises ———–:
Self

A copy of this node with recursively copied children if data is not set .

DataLeaf[ResType]

A new leaf with a new data type if data is provided.

group_children_by(key_func=None, group_leaves_only=False, recurse=True)#

Specialization of the grouping operation for leaf nodes.

Simply returns a copy of the current node.

Parameters:
  • key_func (Any, optional) – Unused, by default None

  • group_leaves_only (bool, optional) – Unused, by default False

  • recurse (bool, optional) – Unused, by default True

Returns:

A copy of the current node. No further grouping possible at the leaf layer.

Return type:

Self

class ProvidesDelayedData#

Bases: Generic[DataType], Protocol

Helper class to encapsulate data that is not immediately accessible but may be provided by asynchronous loading or by computation in parallel/another process.

get_data()#

May be blocking if async processing is required

Return type:

DataType

data_ready()#

Should not be blocking

Return type:

bool

class DelayedDataLeaf(*, name=None, data_provider=None, attrs=None)#

Bases: DataLeaf[DataType]

Class to hold data in a leaf of the tree structure, where the data is not immediately accessible but may be the delayed result of asynchronous processing.

Parameters:
_data_provider: ProvidesDelayedData[DataType] | None#
_data_is_set: bool#
property has_data: bool#
Return type:

bool

property data: DataType#
Return type:

DataType