Skip to content

Commit 1bab496

Browse files
committed
ensure mask broadcasting still works as expected, even with misaligned coords
1 parent b87a896 commit 1bab496

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

linopy/model.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,10 @@ def add_variables(
555555
self._check_valid_dim_names(data)
556556

557557
if mask is not None:
558-
mask = as_dataarray(mask, coords=data.coords, dims=data.dims).astype(bool)
558+
# TODO: Simplify when removing Future Warning from broadcast_mask
559+
if not isinstance(mask, DataArray):
560+
mask = as_dataarray(mask, coords=data.coords, dims=data.dims)
561+
mask = mask.astype(bool)
559562
mask = broadcast_mask(mask, data.labels)
560563

561564
# Auto-mask based on NaN in bounds (use numpy for speed)
@@ -750,7 +753,10 @@ def add_constraints(
750753
(data,) = xr.broadcast(data, exclude=[TERM_DIM])
751754

752755
if mask is not None:
753-
mask = as_dataarray(mask, coords=data.coords, dims=data.dims).astype(bool)
756+
# TODO: Simplify when removing Future Warning from broadcast_mask
757+
if not isinstance(mask, DataArray):
758+
mask = as_dataarray(mask, coords=data.coords, dims=data.dims)
759+
mask = mask.astype(bool)
754760
mask = broadcast_mask(mask, data.labels)
755761

756762
# Auto-mask based on null expressions or NaN RHS (use numpy for speed)

0 commit comments

Comments
 (0)