Skip to content

dimension error when multiplying variable/expression with numpy float #478

@jacob-mannhardt

Description

@jacob-mannhardt

Version Checks (indicate both or one)

  • I have confirmed this bug exists on the lastest release of Linopy.

  • I have confirmed this bug exists on the current master branch of Linopy.

Issue Description

When multiplying a variable or expression with a scalar numpy float, I receive a ValueError: different number of dimensions on data and dims: 0 vs 1.

Reproducible Example

import pandas as pd
from linopy import Model
import numpy as np

m = Model()
b = np.float64(5.0)
index = pd.Index(["a", "b", "c"], name="index")
m.add_variables(lower=0, name="var", coords=[index])
expr = m.variables["var"] * b

# workaround
expr = m.variables["var"] * b.item()

Expected Behavior

No ValueError in expr = m.variables["var"] * b

Installed Versions

Details Bottleneck==1.5.0 click==8.2.1 cloudpickle==3.1.1 colorama==0.4.6 dask==2025.7.0 deprecation==2.1.0 fsspec==2025.7.0 linopy==0.5.5 locket==1.0.0 numexpr==2.11.0 numpy==2.3.2 packaging==25.0 pandas==2.3.1 partd==1.4.2 polars==1.31.0 python-dateutil==2.9.0.post0 pytz==2025.2 PyYAML==6.0.2 scipy==1.16.1 setuptools==78.1.1 six==1.17.0 toolz==1.0.0 tqdm==4.67.1 tzdata==2025.2 wheel==0.45.1 xarray==2025.7.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions