Lazy implementation¶
LazyFrameLabeledArray is the implementation backed entirely by
Narwhals LazyFrames, which evaluates operations
lazily and stores data in a long, relational format. It is in early development and does not
yet support the whole protocol. See Lazy arrays for a guide,
including which features are available today.
LazyFrameLabeledArray
dataclass
¶
Bases: Generic[ExternalFrameType, InternalFrameType], FrameLabeledArray[ExternalFrameType, ndarray]
A variant of FrameLabeledArray that stores all data (labels and values) in a table (long) format, and resolves into an array lazily.
from_values_and_labels
classmethod
¶
from_values_and_labels(values: AnyArray, labels: Sequence[ExternalFrameType | None]) -> LazyFrameLabeledArray[ExternalFrameType, AnyInternalFrame]
Construct a lazy array from a value array and one label frame per axis.
The values are converted to NumPy and stored in long format, with one row per
element. Complex-valued arrays are not supported. Prefer the
from_values_and_labels function in the top-level package, passing
implementation=LAZY, over constructing this class directly.
from_frame
classmethod
¶
from_frame(frame: ExternalFrameType, *, value_column: str = 'value') -> LazyFrameLabeledArray[ExternalFrameType, AnyInternalFrame]
Construct a one-dimensional lazy array from a single frame in long format.
The value_column holds the values and the remaining columns become the labels of
the single axis. Prefer the from_frame function in the top-level package over
constructing this class directly.
values ¶
Resolve the lazy computation and return the values as a NumPy array.
The backing frames are collected and reshaped into an array of the array's shape, regardless of the underlying DataFrame backend. This is where pending lazy work is actually performed.
labels ¶
labels(axis: int) -> ExternalFrameType | None
labels(axis: int | slice | None = None) -> ExternalFrameType | None | Sequence[ExternalFrameType | None]
Return the label frame for a single axis, or all axes.
The internal ordering column is dropped and the frames are collected into the external DataFrame backend before being returned.
shape ¶
The shape of the array, as a tuple with one size per axis.
Resolving the shape forces the separate shape computation, which also validates that the array is well formed.