Variable.update() / Constraint.update() should validate inputs the same way add_variables() / add_constraints() do
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start with Variable._validate_update and the analogous Constraint.update locations, then compare them with add_variables and add_constraints. Read the #726 helper rename and the tightened as_dataarray semantics before changing the update path. Done means changing bounds, coefficients, signs, or rhs uses the same validation, errors, and coordinate coercions as creation.
Written by the indexing model from the issue text.
Description
This is a tracking issue
Problem
Variable.update() and Constraint.update() currently validate inputs differently from their corresponding add_* constructors. Coord-aware checks (extra dims, mismatched coord values, reindex on equal-but-reordered) live in add_variables / add_constraints but not in the update path.
Concretely on feat/typed-update-api:
# Variable._validate_update — current
new_val = DataArray(val).broadcast_like(ref)
if not set(new_val.dims).issubset(own_dims):
raise ValueError("Cannot assign new dimensions to existing variable.")
vs.
# add_variables — current
if isinstance(lower, DataArray):
lower = _validate_dataarray_bounds(lower, coords)
as_dataarray(lower, coords, **kwargs)
The add_* path catches a strict superset of what update() catches: pandas Series with a wrong-named index, DataArrays with extra dims, DataArrays with shared dims but mismatched coord values, etc. update() silently broadcasts in those cases.
What should happen
After #726 lands (which renames _validate_dataarray_bounds → assert_compatible_with_coords and tightens as_dataarray's semantics), rebase Variable._validate_update and the analogous places in Constraint.update onto the same as_dataarray + assert_compatible_with_coords pipeline used by add_variables / add_constraints.
Net effect: the validation contract for changing a bound, coefficient, sign, or rhs becomes identical to the contract for creating one. Same errors, same coord coercions, no surprise behavior at the update site.
Notes
- Tracked as a follow-up to #727 ("Variable.update() / Constraint.update() as canonical mutation API"). The pipeline rewrite was reverted from #727 because it would conflict with #726 / #722 on rebase.
- Stack: #722 → #725 (merged) → #726 → this issue.
- Should land after #726 to avoid double-touching the helpers.
- Dominant language
- Python
- Stars
- 257
- Forks
- 87
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 32
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PyPSA/linopy
-
bug solver interface
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
performance sparse
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
documentation sparse
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
enhancement sparse
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Make the sparse path observable and controllable (.is_sparse, densify warning, per-call sparse=) Openenhancement sparse
Difficulty 5/5 Over a week Newbie friendliness 35/100
Similar issues
-
bug confirmed issue
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
open-webui/open-webui#30750 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 90/100