Skip to content
forked from pydata/xarray

Commit

Permalink
Automatically chunk other in GroupBy binary ops.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Mar 27, 2023
1 parent a28e9b5 commit 836f497
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,19 @@ def _binary_op(self, other, f, reflexive=False):
)

other, _ = align(other, coord, join="outer")
expanded = other.sel({name: group})

# if other is dask-backed, that's a hint that the
# "expanded" dataset is too big to hold in memory.
# this can be the case when `other` was read from disk
# We need to check for dask-backed Datasets
# so utils.is_duck_dask_array does not work for this check
if obj.__dask_graph__() is not None and other.__dask_graph__() is None:
# a chunk size of 1 seems reasonable since we expect it to be repeated
# TODO: what about dims other than `name``
# TODO: What about datasets with some dask vars, and others not?
other = other.chunk({name: 1})

expanded = other.sel({name: group}).drop_vars(name)

result = g(obj, expanded)

Expand Down

0 comments on commit 836f497

Please sign in to comment.