Skip to content

kups.core.data.wrappers

WithCache

Bases: Generic[TData, TCache]

Data paired with an associated cache.

Attributes:

Name Type Description
data TData

Primary data.

cache TCache

Cached auxiliary values derived from or associated with data.

Source code in src/kups/core/data/wrappers.py
@dataclass
class WithCache(Generic[TData, TCache]):
    """Data paired with an associated cache.

    Attributes:
        data: Primary data.
        cache: Cached auxiliary values derived from or associated with `data`.
    """

    data: TData
    cache: TCache

WithIndices

Bases: Batched, Generic[I, TData]

Data paired with an :class:Index selecting a subset of elements.

Attributes:

Name Type Description
indices Index[I]

Index array mapping entries to labeled elements.

data TData

Associated data for the selected elements.

Source code in src/kups/core/data/wrappers.py
@dataclass
class WithIndices(Batched, Generic[I, TData]):
    """Data paired with an :class:`Index` selecting a subset of elements.

    Attributes:
        indices: Index array mapping entries to labeled elements.
        data: Associated data for the selected elements.
    """

    indices: Index[I]
    data: TData

    def map_data[NewData](
        self, f: Callable[[TData], NewData]
    ) -> WithIndices[I, NewData]:
        """Apply ``f`` to ``data``, keeping the same indices."""
        return WithIndices(self.indices, f(self.data))

map_data(f)

Apply f to data, keeping the same indices.

Source code in src/kups/core/data/wrappers.py
def map_data[NewData](
    self, f: Callable[[TData], NewData]
) -> WithIndices[I, NewData]:
    """Apply ``f`` to ``data``, keeping the same indices."""
    return WithIndices(self.indices, f(self.data))