DatasetWrapperMixin#

class tpcp.DatasetWrapperMixin[source]#

Provide common behavior for datasets that wrap another dataset.

This mixin expands the index of wrapped_dataset through _create_wrapped_index, links the wrapper’s initial grouping to the wrapped dataset, and resolves the source datapoint represented by a wrapper datapoint through wrapped_datapoint.

The mixin deliberately does not inherit from Dataset. A concrete wrapper must inherit from both this mixin and the domain-specific dataset interface implemented by the wrapped dataset.

Important

DatasetWrapperMixin must be listed before the dataset base class. The order controls Python’s method resolution order and ensures that this mixin’s create_index implementation is used. Reversing the bases raises a TypeError when the wrapper class is defined.

Attributes:
wrapped_datapoint

Return the wrapped datapoint represented by the current wrapper group.

Examples

The mixin comes first and the shared dataset interface comes second:

class AugmentedDataset(
    DatasetWrapperMixin[SourceDataset],
    SourceDataset,
):
    _wrapper_groupby_cols = ("augmentation",)

    def _create_wrapped_index(self, source_index): ...

Methods

create_index()

Create the wrapper index and link its initial grouping to the wrapped dataset.

__init__(*args, **kwargs)#
create_index() DataFrame[source]#

Create the wrapper index and link its initial grouping to the wrapped dataset.

property wrapped_datapoint: WrappedDatasetT#

Return the wrapped datapoint represented by the current wrapper group.

Examples using tpcp.DatasetWrapperMixin#

Transforming training datasets

Transforming training datasets