Skip to content

Commit

Permalink
DOC: Add the description for fix unexpected sort in groupby in whatsn…
Browse files Browse the repository at this point in the history
…ew note
  • Loading branch information
Licht-T committed Sep 29, 2017
1 parent 7b23e65 commit 9b6a3da
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ Groupby/Resample/Rolling
- Bug in ``.rolling(...).apply(...)`` with a ``DataFrame`` with a ``DatetimeIndex``, a ``window`` of a timedelta-convertible and ``min_periods >= 1` (:issue:`15305`)
- 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`)
- Bug in ``groupby.nunique()`` with ``TimeGrouper`` which cannot handle ``NaT`` correctly (:issue:`17575`)
- Bug in ``DataFrame.groupby`` where a single level selection from a ``MultiIndex`` unexpectedly sorts (:issue:`17537`)

Sparse
^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,7 @@ def aggfun(ser):

@pytest.mark.parametrize('sort', [True, False])
def test_groupby_level(self, sort):
# GH 17537
frame = self.mframe
deleveled = frame.reset_index()

Expand Down Expand Up @@ -1838,6 +1839,7 @@ def test_groupby_level_index_names(self):

@pytest.mark.parametrize('sort', [True, False])
def test_groupby_level_with_nas(self, sort):
# GH 17537
index = MultiIndex(levels=[[1, 0], [0, 1, 2, 3]],
labels=[[1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 2, 3, 0, 1,
2, 3]])
Expand Down Expand Up @@ -1943,6 +1945,7 @@ def test_groupby_complex(self):
[False, [0, 0, 0, 1, 1, 2, 2, 3, 3, 3]]
])
def test_level_preserve_order(self, sort, labels):
# GH 17537
grouped = self.mframe.groupby(level=0, sort=sort)
exp_labels = np.array(labels, np.intp)
assert_almost_equal(grouped.grouper.labels[0], exp_labels)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/groupby/test_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def test_regression_whitelist_methods(
raw_frame, op, level,
axis, skipna, sort):
# GH6944
# GH 17537
# explicity test the whitelest methods

if axis == 0:
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,7 @@ def test_count(self):

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

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

Expand Down

0 comments on commit 9b6a3da

Please sign in to comment.