dantro.mixins.indexing module

This module implement mixin classes that provide indexing capabilities

class dantro.mixins.indexing.IntegerItemAccessMixin[source]

Bases: object

This mixin allows accessing items via integer keys and also supports calling the __contains__ magic method with integer keys. It is meant to be used to add features to an AbstractDataGroup-derived class, although this is not enforced.

Note

The __setitem__ method is not covered by this!

Note

The class using this mixin has to implement index access methods and the __contains__ magic method independently from this mixin!

_parse_key(key: Union[str, int]) → str[source]

Makes sure a key is a string

__getitem__(key: Union[str, int])[source]

Adjusts the parent method to allow integer key item access

__setitem__(key: Union[str, int])[source]

Adjusts the parent method to allow item setting by integer key

__delitem__(key: Union[str, int])[source]

Adjusts the parent method to allow item deletion by integer key

__contains__(key: Union[str, int]) → bool[source]

Adjusts the parent method to allow checking for integers

class dantro.mixins.indexing.PaddedIntegerItemAccessMixin[source]

Bases: dantro.mixins.indexing.IntegerItemAccessMixin

This mixin allows accessing items via integer keys that map to members that have a zero-padded integer name. It can only be used as mixin for AbstractDataGroup-derived classes!

The __contains__ magic method is also supported in this mixin.

Note

The class using this mixin has to implement index access methods and the __contains__ magic method independently from this mixin!

_PADDED_INT_KEY_WIDTH = None
_PADDED_INT_FSTR = None
_PADDED_INT_STRICT_CHECKING = True
_PADDED_INT_MAX_VAL = None
property padded_int_key_width

Returns the width of the zero-padded integer key or None, if it is not already specified.

_parse_key(key: Union[str, int]) → str[source]

Parse a potentially integer key to a zero-padded string

__contains__(key: Union[str, int]) → bool

Adjusts the parent method to allow checking for integers

__delitem__(key: Union[str, int])

Adjusts the parent method to allow item deletion by integer key

__getitem__(key: Union[str, int])

Adjusts the parent method to allow integer key item access

__setitem__(key: Union[str, int])

Adjusts the parent method to allow item setting by integer key

_check_cont(cont: dantro.abc.AbstractDataContainer) → None[source]

This method is invoked when adding a member to a group and makes sure the name of the added group is correctly zero-padded.

Also, upon first call, communicates the zero padded integer key width, i.e.: the length of the container name, to the PaddedIntegerItemAccessMixin.

Parameters

cont – The member container to add

Returns

None: No return value needed