dataeval.data.Operation

class dataeval.data.Operation

Abstract base for a single step in a View pipeline.

A View is built from an ordered list of operations, each applied in turn to the source dataset. An operation may do any combination of three things by mutating the view it is handed in apply():

  • change cardinality / order — set or reorder View.selection, the list of surviving source indices (filter, reorder, limit, resample).

  • rewrite content — register a per-datum transform via View.map(); a transform may target every datum or only a subset of source indices.

  • rewrite metadata — override apply_metadata(), folded once at build.

Operations run in the order given, and each reads the source through the transforms registered by earlier operations (see View.read()), so a filter placed after Relabel sees the relabeled targets.

requires

The MAITE datum shape this operation needs when it reads each datum’s target. View aggregates the requires of all operations and validates the source dataset once, upfront, raising MaiteShapeError before any operation runs. Leave as None when the operation ignores targets.

Type:

DatasetKind or None, default None

Examples

A custom operation that keeps only even-indexed items:

>>> from dataeval.data import View, Operation
>>>
>>> class KeepEven(Operation):
...     def apply(self, view: View) -> None:
...         view.selection = [i for i in view.selection if i % 2 == 0]
>>>
>>> view = View(dataset, [KeepEven()])
abstractmethod apply(view)

Apply this operation by mutating view in place.

apply_metadata(metadata)

Return possibly-updated dataset-level metadata (default: unchanged).