Skip to content

Eager implementation

EagerFrameLabeledArray is the array-backed implementation of the protocol. It supports the full protocol and works with any array following the array API, with tested support for NumPy and JAX. See Eager arrays for a guide.

EagerFrameLabeledArray dataclass

Bases: FrameLabeledArray[LabelFrameType, SomeValueArray]

The array-backed implementation of the protocol, resolving every operation immediately.

The values are held in a real array following the array API, with tested support for NumPy and JAX, and the labels are held as Narwhals DataFrames. This implementation supports the full protocol. It is immutable, so every operation returns a new array, and it is registered as a JAX pytree so it can be traced and differentiated.

Prefer the from_values_and_labels function in the top-level package over constructing this class directly.

from_values_and_labels classmethod

from_values_and_labels(values: SomeValueArray, labels: Sequence[LabelFrameType | None]) -> Self

Construct an eager array from a value array and one label frame per axis.

labels

labels(axis: int) -> LabelFrameType | None
labels(axis: slice | None = None) -> tuple[LabelFrameType | None, ...]
labels(axis: int | slice | None = None) -> LabelFrameType | None | tuple[LabelFrameType | None, ...]

Return the label frame for a single axis, or all axes.

With an integer axis, the frame for that axis is returned, or None if the axis is unlabeled. With a slice or None, a tuple with one frame (or None) per axis is returned.

values

values(*indices: ArrayAxisIndices[SomeValueArray]) -> SomeValueArray

Return the underlying value array, optionally indexed.

Called with no arguments it returns the whole array. It can also be subscripted, as in array.values[0], to index the values directly and possibly avoid a copy.

shape

shape() -> tuple[int, ...]

The shape of the array, as a tuple with one size per axis.