Skip to content
forked from pydata/xarray

Commit f30da34

Browse files
committed
Cleanup + fix typnig
1 parent e798786 commit f30da34

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

xarray/core/groupby.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def check_reduce_dims(reduce_dims, dimensions):
5959

6060
def unique_value_groups(
6161
ar, sort: bool = True
62-
) -> tuple[np.ndarray | pd.Index, list[list[int]]]:
62+
) -> tuple[np.ndarray | pd.Index, list[list[int]], np.ndarray]:
6363
"""Group an array by its unique values.
6464
6565
Parameters
@@ -706,6 +706,7 @@ def _flox_reduce(
706706
from xarray.core.dataset import Dataset
707707

708708
obj = self._original_obj
709+
group = self._original_group
709710

710711
if keep_attrs is None:
711712
keep_attrs = _get_keep_attrs(default=True)
@@ -735,32 +736,23 @@ def _flox_reduce(
735736
if index.is_unique and self._squeeze:
736737
raise ValueError(f"cannot reduce over dimensions {self._group.name!r}")
737738

738-
if isinstance(self._original_group, _DummyGroup):
739-
group = self._original_group.name
740-
else:
741-
group = self._original_group
742-
743-
unindexed_dims: tuple[str, ...] = tuple()
744-
if isinstance(group, str):
745-
if group in obj.dims and group not in obj._indexes and self._bins is None:
746-
unindexed_dims = (group,)
747-
group = self._original_obj[group]
739+
unindexed_dims: tuple[Hashable, ...] = tuple()
740+
if isinstance(group, _DummyGroup) and self._bins is None:
741+
unindexed_dims = (group.name,)
748742

749743
parsed_dim: tuple[Hashable, ...]
750744
if isinstance(dim, str):
751745
parsed_dim = (dim,)
752746
elif dim is None:
753747
parsed_dim = group.dims
754748
elif dim is ...:
755-
parsed_dim = tuple(self._original_obj.dims)
749+
parsed_dim = tuple(obj.dims)
756750
else:
757751
parsed_dim = tuple(dim)
758752

759753
# Do this so we raise the same error message whether flox is present or not.
760754
# Better to control it here than in flox.
761-
if any(
762-
d not in group.dims and d not in self._original_obj.dims for d in parsed_dim
763-
):
755+
if any(d not in group.dims and d not in obj.dims for d in parsed_dim):
764756
raise ValueError(f"cannot reduce over dimensions {dim}.")
765757

766758
if kwargs["func"] not in ["all", "any", "count"]:

0 commit comments

Comments
 (0)