Skip to content

Commit 1fa5025

Browse files
authored
CLN: Remove Index.sort (#59283)
1 parent e191a06 commit 1fa5025

File tree

3 files changed

+1
-13
lines changed

3 files changed

+1
-13
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ Other API changes
236236
- All classes inheriting from builtin ``tuple`` (including types created with :func:`collections.namedtuple`) are now hashed and compared as builtin ``tuple`` during indexing operations (:issue:`57922`)
237237
- Made ``dtype`` a required argument in :meth:`ExtensionArray._from_sequence_of_strings` (:issue:`56519`)
238238
- Passing a :class:`Series` input to :func:`json_normalize` will now retain the :class:`Series` :class:`Index`, previously output had a new :class:`RangeIndex` (:issue:`51452`)
239+
- Removed :meth:`Index.sort` which always raised a ``TypeError``. This attribute is not defined and will raise an ``AttributeError`` (:issue:`59283`)
239240
- Updated :meth:`DataFrame.to_excel` so that the output spreadsheet has no styling. Custom styling can still be done using :meth:`Styler.to_excel` (:issue:`54154`)
240241
- pickle and HDF (``.h5``) files created with Python 2 are no longer explicitly supported (:issue:`57387`)
241242
- pickled objects from pandas version less than ``1.0.0`` are no longer supported (:issue:`57155`)

pandas/core/indexes/base.py

-7
Original file line numberDiff line numberDiff line change
@@ -5785,13 +5785,6 @@ def sort_values(
57855785
else:
57865786
return sorted_index
57875787

5788-
@final
5789-
def sort(self, *args, **kwargs):
5790-
"""
5791-
Use sort_values instead.
5792-
"""
5793-
raise TypeError("cannot sort an Index object in-place, use sort_values instead")
5794-
57955788
def shift(self, periods: int = 1, freq=None) -> Self:
57965789
"""
57975790
Shift index by desired number of time frequency increments.

pandas/tests/indexes/test_any_index.py

-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ def test_boolean_context_compat(index):
2222
bool(index)
2323

2424

25-
def test_sort(index):
26-
msg = "cannot sort an Index object in-place, use sort_values instead"
27-
with pytest.raises(TypeError, match=msg):
28-
index.sort()
29-
30-
3125
def test_hash_error(index):
3226
with pytest.raises(TypeError, match=f"unhashable type: '{type(index).__name__}'"):
3327
hash(index)

0 commit comments

Comments
 (0)