Skip to content

Commit 4944b9e

Browse files
authored
Fix binning when labels are provided. (#7205)
Closes #7198
1 parent 97c70cf commit 4944b9e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

xarray/core/groupby.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,7 @@ def _flox_reduce(
771771
# the bin edge labels have a default precision of 3
772772
# reassign to fix that.
773773
assert self._full_index is not None
774-
new_coord = [
775-
pd.Interval(inter.left, inter.right) for inter in self._full_index
776-
]
777-
result[self._group.name] = new_coord
774+
result[self._group.name] = self._full_index
778775
# Fix dimension order when binning a dimension coordinate
779776
# Needed as long as we do a separate code path for pint;
780777
# For some reason Datasets and DataArrays behave differently!

xarray/tests/test_groupby.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,9 @@ def test_groupby_bins(self):
13701370
actual = array.groupby_bins("dim_0", bins=bins).sum()
13711371
assert_identical(expected, actual)
13721372

1373+
actual = array.groupby_bins("dim_0", bins=bins, labels=[1.2, 3.5]).sum()
1374+
assert_identical(expected.assign_coords(dim_0_bins=[1.2, 3.5]), actual)
1375+
13731376
actual = array.groupby_bins("dim_0", bins=bins).map(lambda x: x.sum())
13741377
assert_identical(expected, actual)
13751378

0 commit comments

Comments
 (0)