Skip to content

Commit 73e85d2

Browse files
committed
Update docstrings for as_dataarray and add_variables
Document the coord validation and broadcasting behavior from the user perspective.
1 parent 047f288 commit 73e85d2

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

linopy/common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ def as_dataarray(
273273
-------
274274
DataArray:
275275
The converted DataArray.
276+
277+
Raises
278+
------
279+
ValueError
280+
If arr is a DataArray and coords is provided: raised when
281+
coordinates for shared dimensions do not match, or when the
282+
DataArray has dimensions not covered by coords (unless
283+
allow_extra_dims is True). The DataArray's dimensions may be
284+
a subset of coords — missing dimensions are added via
285+
expand_dims.
276286
"""
277287
if isinstance(arr, pd.Series | pd.DataFrame):
278288
arr = pandas_to_dataarray(arr, coords=coords, dims=dims, **kwargs)

linopy/model.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,12 @@ def add_variables(
449449
Upper bound of the variable(s). Ignored if `binary` is True.
450450
The default is inf.
451451
coords : list/xarray.Coordinates, optional
452-
The coords of the variable array.
453-
These are directly passed to the DataArray creation of
454-
`lower` and `upper`. For every single combination of
455-
coordinates a optimization variable is added to the model.
452+
The coords of the variable array. For every single
453+
combination of coordinates an optimization variable is
454+
added to the model. Data for `lower`, `upper` and `mask`
455+
is fitted to these coords: shared dimensions must have
456+
matching coordinates, and missing dimensions are broadcast.
457+
A ValueError is raised if the data is not compatible.
456458
The default is None.
457459
name : str, optional
458460
Reference name of the added variables. The default None results in
@@ -474,7 +476,9 @@ def add_variables(
474476
------
475477
ValueError
476478
If neither lower bound and upper bound have coordinates, nor
477-
`coords` are directly given.
479+
`coords` are directly given. Also raised if `lower` or
480+
`upper` are DataArrays whose coordinates do not match the
481+
provided `coords`.
478482
479483
Returns
480484
-------

0 commit comments

Comments
 (0)