Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Variable.update() / Constraint.update() should validate inputs the same way add_variables() / add_constraints() do

Aperta
#731 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
backend, data

Direzione di ricerca

Inizia da Variable._validate_update e dalle posizioni analoghe di Constraint.update, quindi confrontale con add_variables e add_constraints. Leggi la ridenominazione dell'helper #726 e la semantica più restrittiva di as_dataarray prima di modificare il percorso di aggiornamento. Il lavoro è completo quando la modifica di bounds, coefficients, signs o rhs usa la stessa validazione, gli stessi errori e le stesse coercizioni delle coordinate della creazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

data-model enhancement

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.
Lingua principale
Python
Stelle
257
Fork
86
Merge medio
21h 29m
PR unite (30g)
42

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PyPSA/linopy

Tutte le issue di PyPSA/linopy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.