Skip to content

Commit 2cea052

Browse files
committed
WIP 2
1 parent 1ef22a9 commit 2cea052

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

xarray/core/groupby.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,11 @@ def _binary_op(self, other, f, reflexive=False):
489489
# import IPython; IPython.core.debugger.set_trace()
490490
try:
491491
if self._bins is not None:
492-
other = other.sel({f"{name}_bins": self._group})
492+
if self._stacked_dim is not None:
493+
group = self._group.unstack()
494+
# idx = pd.factorize(group.data.ravel())[0]
495+
# group_idx = group.copy(data=idx.reshape(group.data.shape))
496+
other = other.sel({f"{name}_bins": group})
493497
if isinstance(group, _DummyGroup):
494498
# When binning by unindexed coordinate we need to reindex obj.
495499
# _full_index is IntervalIndex, so idx will be -1 where
@@ -525,13 +529,12 @@ def _binary_op(self, other, f, reflexive=False):
525529

526530
result = g(obj, other)
527531

528-
# backcompat: concat during the "combine" step places
529-
# `dim` as the first dimension
530-
if dim in result.dims:
531-
# guards against self._group_dim being "stacked"
532-
result = result.transpose(dim, ...)
533-
# for var in set(obj.coords) - set(obj.xindexes):
534-
# result[var] = result[var].broadcast_like(other)
532+
# backcompat:
533+
for var in set(obj.coords) - set(obj.xindexes):
534+
print(var)
535+
if dim not in obj[var]:
536+
print(f"excluding {dim}, broadcasting {var}")
537+
result[var] = obj[var].reset_coords(drop=True).broadcast_like(result)
535538
return result
536539

537540
def _maybe_restore_empty_groups(self, combined):

0 commit comments

Comments
 (0)