Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from xarray.core.types import (
Dims,
QuantileMethods,
T_DataArray,
T_DataWithCoords,
T_Xarray,
)
Expand Down Expand Up @@ -173,11 +172,12 @@ def _inverse_permutation_indices(positions, N: int | None = None) -> np.ndarray

if isinstance(positions[0], slice):
positions = _consolidate_slices(positions)
if positions == slice(None):
if positions == [slice(None)] or positions == [slice(0, None)]:
return None
positions = [np.arange(sl.start, sl.stop, sl.step) for sl in positions]

newpositions = nputils.inverse_permutation(np.concatenate(positions), N)
newpositions = nputils.inverse_permutation(
np.concatenate(tuple(p for p in positions if len(p) > 0)), N
)
return newpositions[newpositions != -1]


Expand Down Expand Up @@ -990,7 +990,7 @@ def _maybe_reindex(self, combined):
if (has_missing_groups and index is not None) or (
len(self.groupers) > 1
and not isinstance(grouper.full_index, pd.RangeIndex)
and not index.index.equals(grouper.full_index)
and not (index is not None and index.index.equals(grouper.full_index))
):
indexers[grouper.name] = grouper.full_index
if indexers:
Expand Down
14 changes: 14 additions & 0 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3850,6 +3850,20 @@ def test_groupby_bins_mean_time_series():
assert ds_agged.time.dtype == np.dtype("datetime64[ns]")


def test_groupby_multi_map():
# https://github.com/pydata/xarray/issues/11004
d = xr.DataArray(
[[0, 1], [2, 3]],
coords={
"lon": (["ny", "nx"], [[30, 40], [40, 50]]),
"lat": (["ny", "nx"], [[10, 10], [20, 20]]),
},
dims=["ny", "nx"],
)
xr.testing.assert_equal(d, d.groupby("lon").map(lambda x: x))
xr.testing.assert_equal(d, d.groupby(("lon", "lat")).map(lambda x: x))


# TODO: Possible property tests to add to this module
# 1. lambda x: x
# 2. grouped-reduce on unique coords is identical to array
Expand Down
Loading