Skip to content

Commit f4c085e

Browse files
committed
MAINT: Drop order and sort from pandas objects
Affect classes: 1) Index 2) Series 2) DataFrame xref pandas-devgh-10726
1 parent 59b88ab commit f4c085e

File tree

6 files changed

+3
-116
lines changed

6 files changed

+3
-116
lines changed

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

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,

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")

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):

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:

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)