Skip to content
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

Can not create constraints when a coordinate is named "sign" #359

Open
tom-welfonder opened this issue Oct 10, 2024 · 0 comments
Open

Can not create constraints when a coordinate is named "sign" #359

tom-welfonder opened this issue Oct 10, 2024 · 0 comments

Comments

@tom-welfonder
Copy link

When I name a coordinate "sign", an error is raised when I try to create an constraint.

Here a short example to reproduce the issue:

import pandas as pd
import linopy

coords = [pd.Index(range(10), name="sign")]

m = linopy.Model()
x = m.add_variables(lower=0, coords=coords, name="x")
x>=0

Error message:

File ~/.env/lib/python3.10/site-packages/linopy/constraints.py:295, in __repr__(self)
    293         else:
    294             line = f"{print_coord(coord)}: None"
--> 295         lines.append(line)
    296 lines = align_lines_by_delimiter(lines, list(SIGNS_pretty.values()))
    298 shape_str = ", ".join(f"{d}: {s}" for d, s in zip(dims, dim_sizes))

KeyError: 0

When I add at least one additional coordinate to coords, a different error is raised:

File ~/.env/lib/python3.10/site-packages/linopy/constraints.py:295, in __repr__(self)
    293         else:
    294             line = f"{print_coord(coord)}: None"
--> 295         lines.append(line)
    296 lines = align_lines_by_delimiter(lines, list(SIGNS_pretty.values()))
    298 shape_str = ", ".join(f"{d}: {s}" for d, s in zip(dims, dim_sizes))

IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

I was able to reproduce some (different) errors for the names: "labels", "coeffs", "vars", "rhs". I found these in constraint.py in line 671:

dataset_attrs = ["labels", "coeffs", "vars", "sign", "rhs"]
tom-welfonder added a commit to tom-welfonder/linopy that referenced this issue Oct 10, 2024
Add function to ensure that added variables do not use unvalid dimension names.
tom-welfonder added a commit to tom-welfonder/linopy that referenced this issue Oct 10, 2024
Add function to ensure that added variables do not use unvalid dimension names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant