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
This is a tracking issue
Problem
Variable.update()andConstraint.update()currently validate inputs differently from their correspondingadd_*constructors. Coord-aware checks (extra dims, mismatched coord values, reindex on equal-but-reordered) live inadd_variables/add_constraintsbut not in the update path.Concretely on
feat/typed-update-api:vs.
The
add_*path catches a strict superset of whatupdate()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_coordsand tightensas_dataarray's semantics), rebaseVariable._validate_updateand the analogous places inConstraint.updateonto the sameas_dataarray+assert_compatible_with_coordspipeline used byadd_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