Skip to content

v1 convention: pair unlabeled operands with dimensions by size, raise on ambiguity #736

Description

@FBumann

Part of the v1 convention (#714, spec in arithmetics-design/convention.md, introduced by #717). The rule is specified but not yet implemented — this issue tracks the implementation.

The rule

Unlabeled operands — numpy arrays, lists, polars Series — carry no labels to align by, so they pair with the linopy operand's dimensions by size: each axis adopts the dimension (and the coordinates) whose length matches. The pairing must be determined by the sizes alone — when it would be a guess, raise.

Spec vs. today

With x(time: 5), rect(a: 4, time: 5), sq(a: 4, b: 4):

OperationToday (leading-positional)v1 spec (size-determined)
np.arange(5.) + xmaps to timemaps to time (unique match)
np.arange(4.) + xraises (opaque xarray error)raises with a linopy message (no size match)
np.arange(4.) * rectmaps to amaps to a (unique match)
np.arange(5.) * rectraisesmaps to time (unique match, not the leading dim)
np.arange(4.) * sqsilently maps to araises — ambiguous (a or b?)
np.arange(16.).reshape(4,4) * sqmaps to (a, b) in orderraises — ambiguous (sizes cannot tell (a, b) from (b, a))
[1., 2., 3., 4.] + xlegacy: silent left-join / v1: coord-mismatch raiseraises with a linopy message (no size match)

The fix for an ambiguous case is to name the dimensions: wrap the array in an xarray.DataArray (or use a pandas Series/DataFrame with a named index).

Implementation notes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions