Skip to content

Commit fea8f9b

Browse files
committed
ensure mask broadcasting still works as expected, even with misaligned coords
1 parent 2905fd4 commit fea8f9b

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
@@ -574,7 +574,10 @@ def add_variables(
574574
self._check_valid_dim_names(data)
575575

576576
if mask is not None:
577-
mask = as_dataarray(mask, coords=data.coords, dims=data.dims).astype(bool)
577+
# TODO: Simplify when removing Future Warning from broadcast_mask
578+
if not isinstance(mask, DataArray):
579+
mask = as_dataarray(mask, coords=data.coords, dims=data.dims)
580+
mask = mask.astype(bool)
578581
mask = broadcast_mask(mask, data.labels)
579582

580583
# Auto-mask based on NaN in bounds (use numpy for speed)
@@ -799,7 +802,10 @@ def add_constraints(
799802
(data,) = xr.broadcast(data, exclude=[TERM_DIM])
800803

801804
if mask is not None:
802-
mask = as_dataarray(mask, coords=data.coords, dims=data.dims).astype(bool)
805+
# TODO: Simplify when removing Future Warning from broadcast_mask
806+
if not isinstance(mask, DataArray):
807+
mask = as_dataarray(mask, coords=data.coords, dims=data.dims)
808+
mask = mask.astype(bool)
803809
mask = broadcast_mask(mask, data.labels)
804810

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

0 commit comments

Comments
 (0)