Skip to content

mypy claims Variable +/* DataArray not supported #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 2 tasks
apfelix opened this issue Mar 25, 2025 · 0 comments · Fixed by #454
Closed
1 of 2 tasks

mypy claims Variable +/* DataArray not supported #435

apfelix opened this issue Mar 25, 2025 · 0 comments · Fixed by #454
Labels
bug Something isn't working

Comments

@apfelix
Copy link
Contributor

apfelix commented Mar 25, 2025

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

Hi,

as far as I know Linopy supports type checking via mypy. However, when I add/multiply a linopy.Variable with a xarray.DataArray I get a
Unsupported operand types for <...> ("Variable" and "DataArray") error from mypy.
Executing the code works as expected.

Tested with latest versions of all 3 packages: linopy-0.5.2 mypy-1.15.0 xarray-2025.3.0

Reproducible Example

import linopy
import xarray as xr

m = linopy.Model()

a: xr.DataArray = xr.DataArray([1, 2, 3])
v: linopy.Variable = m.add_variables(lower=a, name="v")

# this gives
# > error: Unsupported operand types for * ("Variable" and "DataArray")  [operator]
m.add_constraints(v * a * 10.0 <= 0.0)
# > error: Unsupported operand types for + ("Variable" and "DataArray")  [operator]
m.add_constraints(v + a * 10.0 <= 0.0)

Expected Behavior

No mypy error, as the code works as expected.

Installed Versions

linopy-0.5.2 mypy-1.15.0 xarray-2025.3.0
@apfelix apfelix added the bug Something isn't working label Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant