segram.datastruct.collections module
Enhanced collections.abc classes implementing
generic data filtering and transformation method.
- class segram.datastruct.collections.DataABC[source]
Bases:
IterableAbstract base class for data classes.
- class segram.datastruct.collections.DataIterable[source]
Bases:
DataABCAbstract base class for data iterables.
- map(func: str | Callable[[Any, ...], Any], *args: Any, **kwds: Any) Self[source]
Map data iterator.
- filter(func: str | Callable[[Any, ...], bool] | None, *args: Any, **kwds: Any) Self[source]
Filter data iterator.
- unique(key: str | Callable[[Any, ...], Any] | None = None) Self[source]
Return unique values (only first unique occurences are returned).
- groupby(*args: Any, **kwds: Any) Self[source]
Group by key attribute or function/method.
Importantly, the key function/values must be sortable.
- Parameters:
*args – First argument is interpreted as key function (or its name). The rest is passed as actual
*argsto the function. No grouping is done if no function/name is passed.**kwds – Passed to the function.
- class segram.datastruct.collections.DataIterator(data: Iterable, /)[source]
Bases:
Iterator,DataIterableData iterators class.
- class segram.datastruct.collections.DataSequence[source]
Bases:
Sequence,DataIterableData sequence class.
- sort(*args: Any, reverse: bool = False, show_keys: bool = False, **kwds: Any) Self[source]
Sort elements.
It is typically best to first flatten the sequence in case it contains nested sequences.
- Parameters:
*args – Name of an attribute or a method defined on items. Alternatively a callable. Further positional arguments are passed to the key function. If no positional arguments are used then standard data item sorting is used. Alternatively, an iterable of values used for sorting can be passed.
show_keys – Should sorting key values be returned together with the objects (so 2-tuples are returned).
**kwds – Passed to the sorting callable.
- class segram.datastruct.collections.DataMapping[source]
Bases:
Mapping,DataABCAbstract base class for data mappings.
- map(_what: Literal['items', 'keys', 'values'], *args: Any, **kwds: Any) Self[source]
Map over keys, values or items and return a transformed dictionary.
- Parameters:
_what – Part of dictionary to process.
*args – Passed to
DataIteratorABC.map().**kwds – Passed to
DataIteratorABC.map().
- filter(_what: Literal['items', 'keys', 'values'], *args: Any, **kwds: Any) Self[source]
Filter dictonary by keys, values or items.
- Parameters:
_what – Part of dictionary to process.
*args – Passed to
DataIteratorABC.map().**kwds – Passed to
DataIteratorABC.map().
- sort(_what: Literal['items', 'keys', 'values'], *args: Any, **kwds: Any) Self[source]
Sort dictionary.
- Parameters:
_what – Part of dictionary to process.
*args – Passed to
DataSequenceABC.sort(), which is called onself.items().**kwds – Passed to
DataSequenceABC.sort(), which is called onself.items().
- class segram.datastruct.collections.DataTuple(iterable=(), /)[source]
Bases:
tuple,DataSequenceData tuple class.
- class segram.datastruct.collections.DataList(iterable=(), /)[source]
Bases:
list,DataSequenceData list class.