Skip to content

Commit 4dd7e3c

Browse files
author
Jean-Mathieu Deschenes
committed
Changes requested by @jreback
1 parent eaebb7b commit 4dd7e3c

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

doc/source/whatsnew/v0.21.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ Bug Fixes
144144
~~~~~~~~~
145145

146146
- Fixes regression in 0.20, :func:`Series.aggregate` and :func:`DataFrame.aggregate` allow dictionaries as return values again (:issue:`16741`)
147-
- Fixes regression when sorting by multiple columns on a datetime array with NaT values (:issue:`16836`)
148147

149148
Conversion
150149
^^^^^^^^^^
@@ -184,6 +183,7 @@ Sparse
184183
Reshaping
185184
^^^^^^^^^
186185

186+
- Fixes regression when sorting by multiple columns on a ``datetime64`` dtype ``Series`` with ``NaT`` values (:issue:`16836`)
187187

188188

189189
Numeric

pandas/tests/frame/test_sorting.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,6 @@ def test_sort_values(self):
8989
with tm.assert_raises_regex(ValueError, msg):
9090
frame.sort_values(by=['A', 'B'], axis=0, ascending=[True] * 5)
9191

92-
# GH 16836
93-
94-
d1 = [Timestamp(x) for x in ['2016-01-01', '2015-01-01',
95-
np.nan, '2016-01-01']]
96-
d2 = [Timestamp(x) for x in ['2017-01-01', '2014-01-01',
97-
'2016-01-01', '2015-01-01']]
98-
df = pd.DataFrame({'a': d1, 'b': d2}, index=[0, 1, 2, 3])
99-
100-
d3 = [Timestamp(x) for x in ['2015-01-01', '2016-01-01',
101-
'2016-01-01', np.nan]]
102-
d4 = [Timestamp(x) for x in ['2014-01-01', '2015-01-01',
103-
'2017-01-01', '2016-01-01']]
104-
expected = pd.DataFrame({'a': d3, 'b': d4}, index=[1, 3, 0, 2])
105-
sorted_df = df.sort_values(by=['a', 'b'], )
106-
tm.assert_frame_equal(sorted_df, expected)
107-
10892
def test_sort_values_inplace(self):
10993
frame = DataFrame(np.random.randn(4, 4), index=[1, 2, 3, 4],
11094
columns=['A', 'B', 'C', 'D'])
@@ -348,6 +332,22 @@ def test_sort_nat_values_in_int_column(self):
348332
df_sorted = df.sort_values(["datetime", "float"], ascending=False)
349333
assert_frame_equal(df_sorted, df)
350334

335+
# GH 16836
336+
337+
d1 = [Timestamp(x) for x in ['2016-01-01', '2015-01-01',
338+
np.nan, '2016-01-01']]
339+
d2 = [Timestamp(x) for x in ['2017-01-01', '2014-01-01',
340+
'2016-01-01', '2015-01-01']]
341+
df = pd.DataFrame({'a': d1, 'b': d2}, index=[0, 1, 2, 3])
342+
343+
d3 = [Timestamp(x) for x in ['2015-01-01', '2016-01-01',
344+
'2016-01-01', np.nan]]
345+
d4 = [Timestamp(x) for x in ['2014-01-01', '2015-01-01',
346+
'2017-01-01', '2016-01-01']]
347+
expected = pd.DataFrame({'a': d3, 'b': d4}, index=[1, 3, 0, 2])
348+
sorted_df = df.sort_values(by=['a', 'b'], )
349+
tm.assert_frame_equal(sorted_df, expected)
350+
351351

352352
class TestDataFrameSortIndexKinds(TestData):
353353

0 commit comments

Comments
 (0)