Skip to content

Commit 9962d61

Browse files
committed
DOC: Add the description for fixing unexpected sort in groupby in whatsnew note
1 parent 7b23e65 commit 9962d61

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ Groupby/Resample/Rolling
625625
- Bug in ``.rolling(...).apply(...)`` with a ``DataFrame`` with a ``DatetimeIndex``, a ``window`` of a timedelta-convertible and ``min_periods >= 1` (:issue:`15305`)
626626
- Bug in ``DataFrame.groupby`` where index and column keys were not recognized correctly when the number of keys equaled the number of elements on the groupby axis (:issue:`16859`)
627627
- Bug in ``groupby.nunique()`` with ``TimeGrouper`` which cannot handle ``NaT`` correctly (:issue:`17575`)
628+
- Bug in ``DataFrame.groupby`` where a single level selection from a ``MultiIndex`` unexpectedly sorts (:issue:`17537`)
628629

629630
Sparse
630631
^^^^^^

pandas/tests/groupby/test_groupby.py

+3
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,7 @@ def aggfun(ser):
17931793

17941794
@pytest.mark.parametrize('sort', [True, False])
17951795
def test_groupby_level(self, sort):
1796+
# GH 17537
17961797
frame = self.mframe
17971798
deleveled = frame.reset_index()
17981799

@@ -1838,6 +1839,7 @@ def test_groupby_level_index_names(self):
18381839

18391840
@pytest.mark.parametrize('sort', [True, False])
18401841
def test_groupby_level_with_nas(self, sort):
1842+
# GH 17537
18411843
index = MultiIndex(levels=[[1, 0], [0, 1, 2, 3]],
18421844
labels=[[1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 2, 3, 0, 1,
18431845
2, 3]])
@@ -1943,6 +1945,7 @@ def test_groupby_complex(self):
19431945
[False, [0, 0, 0, 1, 1, 2, 2, 3, 3, 3]]
19441946
])
19451947
def test_level_preserve_order(self, sort, labels):
1948+
# GH 17537
19461949
grouped = self.mframe.groupby(level=0, sort=sort)
19471950
exp_labels = np.array(labels, np.intp)
19481951
assert_almost_equal(grouped.grouper.labels[0], exp_labels)

pandas/tests/groupby/test_whitelist.py

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def test_regression_whitelist_methods(
183183
raw_frame, op, level,
184184
axis, skipna, sort):
185185
# GH6944
186+
# GH 17537
186187
# explicity test the whitelest methods
187188

188189
if axis == 0:

pandas/tests/test_multilevel.py

+2
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,7 @@ def test_count(self):
13941394

13951395
@pytest.mark.parametrize('sort', [True, False])
13961396
def test_series_group_min_max(self, sort):
1397+
# GH 17537
13971398
for op, level, skipna in cart_product(self.AGG_FUNCTIONS, lrange(2),
13981399
[False, True]):
13991400
grouped = self.series.groupby(level=level, sort=sort)
@@ -1407,6 +1408,7 @@ def test_series_group_min_max(self, sort):
14071408

14081409
@pytest.mark.parametrize('sort', [True, False])
14091410
def test_frame_group_ops(self, sort):
1411+
# GH 17537
14101412
self.frame.iloc[1, [1, 2]] = np.nan
14111413
self.frame.iloc[7, [0, 1]] = np.nan
14121414

0 commit comments

Comments
 (0)