Skip to content

Operators align coordinates inconsistently (* by label, + - / by position) #708

@FBumann

Description

@FBumann

Issue Description

linopy's binary operators disagree on how to align coordinates when two operands share a same-size dimension:

Operator Alignment
* by label
+, -, / by position — coordinate labels discarded (override join)
<=, >=, == (constraint creation) by label

Because some operators align by label and others by position, algebraically identical expressions produce different results.

Reproducible Example

import pandas as pd
import linopy

m = linopy.Model()
x = m.add_variables(coords=[["A1", "A5", "A11", "A100"]], name="x")
coef = pd.Series([100, 1, 5, 11], index=["A100", "A1", "A5", "A11"])
# coef["A1"] == 1  (coef's first entry is A100 == 100)

(x + coef).const.sel(dim_0="A1")     # 100   positional — should be 1
(x - coef).const.sel(dim_0="A1")     # -100  positional — should be -1
(x * coef).coeffs.sel(dim_0="A1")    # 1     by label   — correct
(x / coef).coeffs.sel(dim_0="A1")    # 0.01  positional — should be 1

Broken equivalences

Mixing a positional operator with a by-label one makes identical forms disagree:

Expected Behavior

Every operator should align coordinates the same way — by label — and a label mismatch should raise rather than silently pair by position.

Context

Confirmed on linopy 0.7.0. Related: #586, #670, #707. The strict-alignment convention in #591 makes all operators align by label uniformly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions