Skip to content

Commit 2534260

Browse files
gfyoungmattip
authored andcommitted
MAINT: Drop order and sort from pandas objects (pandas-dev#15735)
Affect classes: 1) Index 2) Series 2) DataFrame xref pandas-devgh-10726
1 parent e8244db commit 2534260

File tree

9 files changed

+4
-191
lines changed

9 files changed

+4
-191
lines changed

Diff for: doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ Removal of prior version deprecations/changes
771771
- The deprecated ``DataFrame.iterkv()`` has been removed in favor of ``DataFrame.iteritems()`` (:issue:`10711`)
772772
- The ``Categorical`` constructor has dropped the ``name`` parameter (:issue:`10632`)
773773
- The ``take_last`` parameter has been dropped from ``duplicated()``, ``drop_duplicates()``, ``nlargest()``, and ``nsmallest()`` methods (:issue:`10236`, :issue:`10792`, :issue:`10920`)
774+
- ``Series``, ``Index``, and ``DataFrame`` have dropped the ``sort`` and ``order`` methods (:issue:`10726`)
774775

775776
.. _whatsnew_0200.performance:
776777

Diff for: pandas/core/frame.py

-50
Original file line numberDiff line numberDiff line change
@@ -3304,56 +3304,6 @@ def trans(v):
33043304
else:
33053305
return self._constructor(new_data).__finalize__(self)
33063306

3307-
def sort(self, columns=None, axis=0, ascending=True, inplace=False,
3308-
kind='quicksort', na_position='last', **kwargs):
3309-
"""
3310-
DEPRECATED: use :meth:`DataFrame.sort_values`
3311-
3312-
Sort DataFrame either by labels (along either axis) or by the values in
3313-
column(s)
3314-
3315-
Parameters
3316-
----------
3317-
columns : object
3318-
Column name(s) in frame. Accepts a column name or a list
3319-
for a nested sort. A tuple will be interpreted as the
3320-
levels of a multi-index.
3321-
ascending : boolean or list, default True
3322-
Sort ascending vs. descending. Specify list for multiple sort
3323-
orders
3324-
axis : {0 or 'index', 1 or 'columns'}, default 0
3325-
Sort index/rows versus columns
3326-
inplace : boolean, default False
3327-
Sort the DataFrame without creating a new instance
3328-
kind : {'quicksort', 'mergesort', 'heapsort'}, optional
3329-
This option is only applied when sorting on a single column or
3330-
label.
3331-
na_position : {'first', 'last'} (optional, default='last')
3332-
'first' puts NaNs at the beginning
3333-
'last' puts NaNs at the end
3334-
3335-
Examples
3336-
--------
3337-
>>> result = df.sort(['A', 'B'], ascending=[1, 0])
3338-
3339-
Returns
3340-
-------
3341-
sorted : DataFrame
3342-
"""
3343-
nv.validate_sort(tuple(), kwargs)
3344-
3345-
if columns is None:
3346-
warnings.warn("sort(....) is deprecated, use sort_index(.....)",
3347-
FutureWarning, stacklevel=2)
3348-
return self.sort_index(axis=axis, ascending=ascending,
3349-
inplace=inplace)
3350-
3351-
warnings.warn("sort(columns=....) is deprecated, use "
3352-
"sort_values(by=.....)", FutureWarning, stacklevel=2)
3353-
return self.sort_values(by=columns, axis=axis, ascending=ascending,
3354-
inplace=inplace, kind=kind,
3355-
na_position=na_position)
3356-
33573307
@Appender(_shared_docs['sort_index'] % _shared_doc_kwargs)
33583308
def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
33593309
kind='quicksort', na_position='last', sort_remaining=True,

Diff for: pandas/core/series.py

-71
Original file line numberDiff line numberDiff line change
@@ -1777,77 +1777,6 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
17771777
else:
17781778
return result.__finalize__(self)
17791779

1780-
def sort(self, axis=0, ascending=True, kind='quicksort',
1781-
na_position='last', inplace=True):
1782-
"""
1783-
DEPRECATED: use :meth:`Series.sort_values(inplace=True)` for INPLACE
1784-
sorting
1785-
1786-
Sort values and index labels by value. This is an inplace sort by
1787-
default. Series.order is the equivalent but returns a new Series.
1788-
1789-
Parameters
1790-
----------
1791-
axis : int (can only be zero)
1792-
ascending : boolean, default True
1793-
Sort ascending. Passing False sorts descending
1794-
kind : {'mergesort', 'quicksort', 'heapsort'}, default 'quicksort'
1795-
Choice of sorting algorithm. See np.sort for more
1796-
information. 'mergesort' is the only stable algorithm
1797-
na_position : {'first', 'last'} (optional, default='last')
1798-
'first' puts NaNs at the beginning
1799-
'last' puts NaNs at the end
1800-
inplace : boolean, default True
1801-
Do operation in place.
1802-
1803-
See Also
1804-
--------
1805-
Series.sort_values
1806-
"""
1807-
warnings.warn("sort is deprecated, use sort_values(inplace=True) for "
1808-
"INPLACE sorting", FutureWarning, stacklevel=2)
1809-
1810-
return self.sort_values(ascending=ascending, kind=kind,
1811-
na_position=na_position, inplace=inplace)
1812-
1813-
def order(self, na_last=None, ascending=True, kind='quicksort',
1814-
na_position='last', inplace=False):
1815-
"""
1816-
DEPRECATED: use :meth:`Series.sort_values`
1817-
1818-
Sorts Series object, by value, maintaining index-value link.
1819-
This will return a new Series by default. Series.sort is the equivalent
1820-
but as an inplace method.
1821-
1822-
Parameters
1823-
----------
1824-
na_last : boolean (optional, default=True)--DEPRECATED; use na_position
1825-
Put NaN's at beginning or end
1826-
ascending : boolean, default True
1827-
Sort ascending. Passing False sorts descending
1828-
kind : {'mergesort', 'quicksort', 'heapsort'}, default 'quicksort'
1829-
Choice of sorting algorithm. See np.sort for more
1830-
information. 'mergesort' is the only stable algorithm
1831-
na_position : {'first', 'last'} (optional, default='last')
1832-
'first' puts NaNs at the beginning
1833-
'last' puts NaNs at the end
1834-
inplace : boolean, default False
1835-
Do operation in place.
1836-
1837-
Returns
1838-
-------
1839-
y : Series
1840-
1841-
See Also
1842-
--------
1843-
Series.sort_values
1844-
"""
1845-
warnings.warn("order is deprecated, use sort_values(...)",
1846-
FutureWarning, stacklevel=2)
1847-
1848-
return self.sort_values(ascending=ascending, kind=kind,
1849-
na_position=na_position, inplace=inplace)
1850-
18511780
def argsort(self, axis=0, kind='quicksort', order=None):
18521781
"""
18531782
Overrides ndarray.argsort. Argsorts the value, omitting NA/null values,

Diff for: pandas/indexes/base.py

-11
Original file line numberDiff line numberDiff line change
@@ -1912,17 +1912,6 @@ def sort_values(self, return_indexer=False, ascending=True):
19121912
else:
19131913
return sorted_index
19141914

1915-
def order(self, return_indexer=False, ascending=True):
1916-
"""
1917-
Return sorted copy of Index
1918-
1919-
DEPRECATED: use :meth:`Index.sort_values`
1920-
"""
1921-
warnings.warn("order is deprecated, use sort_values(...)",
1922-
FutureWarning, stacklevel=2)
1923-
return self.sort_values(return_indexer=return_indexer,
1924-
ascending=ascending)
1925-
19261915
def sort(self, *args, **kwargs):
19271916
raise TypeError("cannot sort an Index object in-place, use "
19281917
"sort_values instead")

Diff for: pandas/tests/frame/test_analytics.py

-20
Original file line numberDiff line numberDiff line change
@@ -660,26 +660,6 @@ def test_sem(self):
660660
self.assertFalse((result < 0).any())
661661
nanops._USE_BOTTLENECK = True
662662

663-
def test_sort_invalid_kwargs(self):
664-
df = DataFrame([1, 2, 3], columns=['a'])
665-
666-
msg = r"sort\(\) got an unexpected keyword argument 'foo'"
667-
tm.assertRaisesRegexp(TypeError, msg, df.sort, foo=2)
668-
669-
# Neither of these should raise an error because they
670-
# are explicit keyword arguments in the signature and
671-
# hence should not be swallowed by the kwargs parameter
672-
with tm.assert_produces_warning(FutureWarning,
673-
check_stacklevel=False):
674-
df.sort(axis=1)
675-
676-
with tm.assert_produces_warning(FutureWarning,
677-
check_stacklevel=False):
678-
df.sort(kind='mergesort')
679-
680-
msg = "the 'order' parameter is not supported"
681-
tm.assertRaisesRegexp(ValueError, msg, df.sort, order=2)
682-
683663
def test_skew(self):
684664
tm._skip_if_no_scipy()
685665
from scipy.stats import skew

Diff for: pandas/tests/frame/test_sorting.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ def test_sort(self):
6262
frame = DataFrame(np.arange(16).reshape(4, 4), index=[1, 2, 3, 4],
6363
columns=['A', 'B', 'C', 'D'])
6464

65-
# 9816 deprecated
66-
with tm.assert_produces_warning(FutureWarning):
67-
frame.sort(columns='A')
68-
with tm.assert_produces_warning(FutureWarning):
69-
frame.sort()
65+
# see gh-9816
7066
with tm.assert_produces_warning(FutureWarning):
7167
frame.sortlevel()
7268

Diff for: pandas/tests/indexes/common.py

-6
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,6 @@ def test_sort(self):
346346
for ind in self.indices.values():
347347
self.assertRaises(TypeError, ind.sort)
348348

349-
def test_order(self):
350-
for ind in self.indices.values():
351-
# 9816 deprecated
352-
with tm.assert_produces_warning(FutureWarning):
353-
ind.order()
354-
355349
def test_mutability(self):
356350
for ind in self.indices.values():
357351
if not len(ind):

Diff for: pandas/tests/indexes/test_base.py

-15
Original file line numberDiff line numberDiff line change
@@ -1808,21 +1808,6 @@ def setUp(self):
18081808
def create_index(self):
18091809
return self.mixedIndex
18101810

1811-
def test_order(self):
1812-
idx = self.create_index()
1813-
# 9816 deprecated
1814-
if PY36:
1815-
with tm.assertRaisesRegexp(TypeError, "'>' not supported"):
1816-
with tm.assert_produces_warning(FutureWarning):
1817-
idx.order()
1818-
elif PY3:
1819-
with tm.assertRaisesRegexp(TypeError, "unorderable types"):
1820-
with tm.assert_produces_warning(FutureWarning):
1821-
idx.order()
1822-
else:
1823-
with tm.assert_produces_warning(FutureWarning):
1824-
idx.order()
1825-
18261811
def test_argsort(self):
18271812
idx = self.create_index()
18281813
if PY36:

Diff for: pandas/tests/series/test_sorting.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,13 @@
1313

1414
class TestSeriesSorting(TestData, tm.TestCase):
1515

16-
def test_sort(self):
17-
16+
def test_sortlevel_deprecated(self):
1817
ts = self.ts.copy()
1918

20-
# 9816 deprecated
21-
with tm.assert_produces_warning(FutureWarning):
22-
ts.sort() # sorts inplace
23-
self.assert_series_equal(ts, self.ts.sort_values())
19+
# see gh-9816
2420
with tm.assert_produces_warning(FutureWarning):
2521
ts.sortlevel()
2622

27-
def test_order(self):
28-
29-
# 9816 deprecated
30-
with tm.assert_produces_warning(FutureWarning):
31-
result = self.ts.order()
32-
self.assert_series_equal(result, self.ts.sort_values())
33-
3423
def test_sort_values(self):
3524

3625
# check indexes are reordered corresponding with the values

0 commit comments

Comments
 (0)