Skip to content

Commit

Permalink
MAINT: Drop order and sort from pandas objects (pandas-dev#15735)
Browse files Browse the repository at this point in the history
Affect classes:

1) Index
2) Series
2) DataFrame

xref pandas-devgh-10726
  • Loading branch information
gfyoung authored and AnkurDedania committed Mar 21, 2017
1 parent 232228d commit c2e5beb
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 191 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ Removal of prior version deprecations/changes
- The deprecated ``DataFrame.iterkv()`` has been removed in favor of ``DataFrame.iteritems()`` (:issue:`10711`)
- The ``Categorical`` constructor has dropped the ``name`` parameter (:issue:`10632`)
- The ``take_last`` parameter has been dropped from ``duplicated()``, ``drop_duplicates()``, ``nlargest()``, and ``nsmallest()`` methods (:issue:`10236`, :issue:`10792`, :issue:`10920`)
- ``Series``, ``Index``, and ``DataFrame`` have dropped the ``sort`` and ``order`` methods (:issue:`10726`)

.. _whatsnew_0200.performance:

Expand Down
50 changes: 0 additions & 50 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3304,56 +3304,6 @@ def trans(v):
else:
return self._constructor(new_data).__finalize__(self)

def sort(self, columns=None, axis=0, ascending=True, inplace=False,
kind='quicksort', na_position='last', **kwargs):
"""
DEPRECATED: use :meth:`DataFrame.sort_values`
Sort DataFrame either by labels (along either axis) or by the values in
column(s)
Parameters
----------
columns : object
Column name(s) in frame. Accepts a column name or a list
for a nested sort. A tuple will be interpreted as the
levels of a multi-index.
ascending : boolean or list, default True
Sort ascending vs. descending. Specify list for multiple sort
orders
axis : {0 or 'index', 1 or 'columns'}, default 0
Sort index/rows versus columns
inplace : boolean, default False
Sort the DataFrame without creating a new instance
kind : {'quicksort', 'mergesort', 'heapsort'}, optional
This option is only applied when sorting on a single column or
label.
na_position : {'first', 'last'} (optional, default='last')
'first' puts NaNs at the beginning
'last' puts NaNs at the end
Examples
--------
>>> result = df.sort(['A', 'B'], ascending=[1, 0])
Returns
-------
sorted : DataFrame
"""
nv.validate_sort(tuple(), kwargs)

if columns is None:
warnings.warn("sort(....) is deprecated, use sort_index(.....)",
FutureWarning, stacklevel=2)
return self.sort_index(axis=axis, ascending=ascending,
inplace=inplace)

warnings.warn("sort(columns=....) is deprecated, use "
"sort_values(by=.....)", FutureWarning, stacklevel=2)
return self.sort_values(by=columns, axis=axis, ascending=ascending,
inplace=inplace, kind=kind,
na_position=na_position)

@Appender(_shared_docs['sort_index'] % _shared_doc_kwargs)
def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
kind='quicksort', na_position='last', sort_remaining=True,
Expand Down
71 changes: 0 additions & 71 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1777,77 +1777,6 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
else:
return result.__finalize__(self)

def sort(self, axis=0, ascending=True, kind='quicksort',
na_position='last', inplace=True):
"""
DEPRECATED: use :meth:`Series.sort_values(inplace=True)` for INPLACE
sorting
Sort values and index labels by value. This is an inplace sort by
default. Series.order is the equivalent but returns a new Series.
Parameters
----------
axis : int (can only be zero)
ascending : boolean, default True
Sort ascending. Passing False sorts descending
kind : {'mergesort', 'quicksort', 'heapsort'}, default 'quicksort'
Choice of sorting algorithm. See np.sort for more
information. 'mergesort' is the only stable algorithm
na_position : {'first', 'last'} (optional, default='last')
'first' puts NaNs at the beginning
'last' puts NaNs at the end
inplace : boolean, default True
Do operation in place.
See Also
--------
Series.sort_values
"""
warnings.warn("sort is deprecated, use sort_values(inplace=True) for "
"INPLACE sorting", FutureWarning, stacklevel=2)

return self.sort_values(ascending=ascending, kind=kind,
na_position=na_position, inplace=inplace)

def order(self, na_last=None, ascending=True, kind='quicksort',
na_position='last', inplace=False):
"""
DEPRECATED: use :meth:`Series.sort_values`
Sorts Series object, by value, maintaining index-value link.
This will return a new Series by default. Series.sort is the equivalent
but as an inplace method.
Parameters
----------
na_last : boolean (optional, default=True)--DEPRECATED; use na_position
Put NaN's at beginning or end
ascending : boolean, default True
Sort ascending. Passing False sorts descending
kind : {'mergesort', 'quicksort', 'heapsort'}, default 'quicksort'
Choice of sorting algorithm. See np.sort for more
information. 'mergesort' is the only stable algorithm
na_position : {'first', 'last'} (optional, default='last')
'first' puts NaNs at the beginning
'last' puts NaNs at the end
inplace : boolean, default False
Do operation in place.
Returns
-------
y : Series
See Also
--------
Series.sort_values
"""
warnings.warn("order is deprecated, use sort_values(...)",
FutureWarning, stacklevel=2)

return self.sort_values(ascending=ascending, kind=kind,
na_position=na_position, inplace=inplace)

def argsort(self, axis=0, kind='quicksort', order=None):
"""
Overrides ndarray.argsort. Argsorts the value, omitting NA/null values,
Expand Down
11 changes: 0 additions & 11 deletions pandas/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1912,17 +1912,6 @@ def sort_values(self, return_indexer=False, ascending=True):
else:
return sorted_index

def order(self, return_indexer=False, ascending=True):
"""
Return sorted copy of Index
DEPRECATED: use :meth:`Index.sort_values`
"""
warnings.warn("order is deprecated, use sort_values(...)",
FutureWarning, stacklevel=2)
return self.sort_values(return_indexer=return_indexer,
ascending=ascending)

def sort(self, *args, **kwargs):
raise TypeError("cannot sort an Index object in-place, use "
"sort_values instead")
Expand Down
20 changes: 0 additions & 20 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,26 +660,6 @@ def test_sem(self):
self.assertFalse((result < 0).any())
nanops._USE_BOTTLENECK = True

def test_sort_invalid_kwargs(self):
df = DataFrame([1, 2, 3], columns=['a'])

msg = r"sort\(\) got an unexpected keyword argument 'foo'"
tm.assertRaisesRegexp(TypeError, msg, df.sort, foo=2)

# Neither of these should raise an error because they
# are explicit keyword arguments in the signature and
# hence should not be swallowed by the kwargs parameter
with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
df.sort(axis=1)

with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
df.sort(kind='mergesort')

msg = "the 'order' parameter is not supported"
tm.assertRaisesRegexp(ValueError, msg, df.sort, order=2)

def test_skew(self):
tm._skip_if_no_scipy()
from scipy.stats import skew
Expand Down
6 changes: 1 addition & 5 deletions pandas/tests/frame/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ def test_sort(self):
frame = DataFrame(np.arange(16).reshape(4, 4), index=[1, 2, 3, 4],
columns=['A', 'B', 'C', 'D'])

# 9816 deprecated
with tm.assert_produces_warning(FutureWarning):
frame.sort(columns='A')
with tm.assert_produces_warning(FutureWarning):
frame.sort()
# see gh-9816
with tm.assert_produces_warning(FutureWarning):
frame.sortlevel()

Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,6 @@ def test_sort(self):
for ind in self.indices.values():
self.assertRaises(TypeError, ind.sort)

def test_order(self):
for ind in self.indices.values():
# 9816 deprecated
with tm.assert_produces_warning(FutureWarning):
ind.order()

def test_mutability(self):
for ind in self.indices.values():
if not len(ind):
Expand Down
15 changes: 0 additions & 15 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1808,21 +1808,6 @@ def setUp(self):
def create_index(self):
return self.mixedIndex

def test_order(self):
idx = self.create_index()
# 9816 deprecated
if PY36:
with tm.assertRaisesRegexp(TypeError, "'>' not supported"):
with tm.assert_produces_warning(FutureWarning):
idx.order()
elif PY3:
with tm.assertRaisesRegexp(TypeError, "unorderable types"):
with tm.assert_produces_warning(FutureWarning):
idx.order()
else:
with tm.assert_produces_warning(FutureWarning):
idx.order()

def test_argsort(self):
idx = self.create_index()
if PY36:
Expand Down
15 changes: 2 additions & 13 deletions pandas/tests/series/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,13 @@

class TestSeriesSorting(TestData, tm.TestCase):

def test_sort(self):

def test_sortlevel_deprecated(self):
ts = self.ts.copy()

# 9816 deprecated
with tm.assert_produces_warning(FutureWarning):
ts.sort() # sorts inplace
self.assert_series_equal(ts, self.ts.sort_values())
# see gh-9816
with tm.assert_produces_warning(FutureWarning):
ts.sortlevel()

def test_order(self):

# 9816 deprecated
with tm.assert_produces_warning(FutureWarning):
result = self.ts.order()
self.assert_series_equal(result, self.ts.sort_values())

def test_sort_values(self):

# check indexes are reordered corresponding with the values
Expand Down

0 comments on commit c2e5beb

Please sign in to comment.