Skip to content

Commit 4b51227

Browse files
CLN: updated types to pass mypy tests without type: ignore
1 parent 917d6c8 commit 4b51227

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

pandas/core/arrays/categorical.py

+3
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,9 @@ def sort_values(self, inplace=False, ascending=True, na_position="last", key=Non
16141614
na_position : {'first', 'last'} (optional, default='last')
16151615
'first' puts NaNs at the beginning
16161616
'last' puts NaNs at the end
1617+
key : Callable, default None
1618+
If not None, apply the key function to every value before
1619+
sorting. Identical to key argument in built-in sorted function.
16171620
16181621
Returns
16191622
-------

pandas/core/frame.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -4712,18 +4712,17 @@ def f(vals):
47124712

47134713
# ----------------------------------------------------------------------
47144714
# Sorting
4715-
47164715
@Substitution(**_shared_doc_kwargs)
47174716
@Appender(NDFrame.sort_values.__doc__)
4718-
def sort_values( # type: ignore
4717+
def sort_values(
47194718
self,
47204719
by,
47214720
axis=0,
47224721
ascending=True,
47234722
inplace=False,
47244723
kind="quicksort",
47254724
na_position="last",
4726-
key: Optional[Callable] = None,
4725+
key=None,
47274726
):
47284727
inplace = validate_bool_kwarg(inplace, "inplace")
47294728
axis = self._get_axis_number(axis)
@@ -4766,7 +4765,7 @@ def sort_values( # type: ignore
47664765

47674766
@Substitution(**_shared_doc_kwargs)
47684767
@Appender(NDFrame.sort_index.__doc__)
4769-
def sort_index( # type: ignore
4768+
def sort_index(
47704769
self,
47714770
axis=0,
47724771
level=None,

pandas/core/indexes/datetimelike.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ def sort_values(
279279
"""
280280
Return sorted copy of Index.
281281
"""
282+
if not isinstance(self, Index):
283+
raise TypeError("sort_values must be called on an Index object")
284+
282285
if key:
283286
idx = self.map(key, na_action="ignore")
284287
else:
@@ -308,7 +311,7 @@ def sort_values(
308311
if not ascending:
309312
sorted_values = sorted_values[::-1]
310313

311-
return self._simple_new(sorted_values, **attribs) # type: ignore
314+
return self._simple_new(sorted_values, **attribs)
312315

313316
@Appender(_index_shared_docs["take"] % _index_doc_kwargs)
314317
def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):

pandas/core/series.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2831,14 +2831,14 @@ def update(self, other):
28312831
# ----------------------------------------------------------------------
28322832
# Reindexing, sorting
28332833

2834-
def sort_values( # type: ignore
2834+
def sort_values(
28352835
self,
28362836
axis=0,
28372837
ascending=True,
28382838
inplace=False,
28392839
kind="quicksort",
28402840
na_position="last",
2841-
key: Optional[Callable] = None,
2841+
key=None,
28422842
):
28432843
"""
28442844
Sort by the values.
@@ -3029,7 +3029,7 @@ def _try_kind_sort(arr):
30293029
else:
30303030
return result.__finalize__(self)
30313031

3032-
def sort_index( # type: ignore
3032+
def sort_index(
30333033
self,
30343034
axis=0,
30353035
level=None,

0 commit comments

Comments
 (0)