Skip to content

Commit 4ae2bdd

Browse files
CLN: updated types to pass mypy tests without type: ignore
1 parent d396eff commit 4ae2bdd

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
@@ -1601,6 +1601,9 @@ def sort_values(self, inplace=False, ascending=True, na_position="last", key=Non
16011601
na_position : {'first', 'last'} (optional, default='last')
16021602
'first' puts NaNs at the beginning
16031603
'last' puts NaNs at the end
1604+
key : Callable, default None
1605+
If not None, apply the key function to every value before
1606+
sorting. Identical to key argument in built-in sorted function.
16041607
16051608
Returns
16061609
-------

pandas/core/frame.py

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

47064706
# ----------------------------------------------------------------------
47074707
# Sorting
4708-
47094708
@Substitution(**_shared_doc_kwargs)
47104709
@Appender(NDFrame.sort_values.__doc__)
4711-
def sort_values( # type: ignore
4710+
def sort_values(
47124711
self,
47134712
by,
47144713
axis=0,
47154714
ascending=True,
47164715
inplace=False,
47174716
kind="quicksort",
47184717
na_position="last",
4719-
key: Optional[Callable] = None,
4718+
key=None,
47204719
):
47214720
inplace = validate_bool_kwarg(inplace, "inplace")
47224721
axis = self._get_axis_number(axis)
@@ -4759,7 +4758,7 @@ def sort_values( # type: ignore
47594758

47604759
@Substitution(**_shared_doc_kwargs)
47614760
@Appender(NDFrame.sort_index.__doc__)
4762-
def sort_index( # type: ignore
4761+
def sort_index(
47634762
self,
47644763
axis=0,
47654764
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
@@ -2828,14 +2828,14 @@ def update(self, other):
28282828
# ----------------------------------------------------------------------
28292829
# Reindexing, sorting
28302830

2831-
def sort_values( # type: ignore
2831+
def sort_values(
28322832
self,
28332833
axis=0,
28342834
ascending=True,
28352835
inplace=False,
28362836
kind="quicksort",
28372837
na_position="last",
2838-
key: Optional[Callable] = None,
2838+
key=None,
28392839
):
28402840
"""
28412841
Sort by the values.
@@ -3026,7 +3026,7 @@ def _try_kind_sort(arr):
30263026
else:
30273027
return result.__finalize__(self)
30283028

3029-
def sort_index( # type: ignore
3029+
def sort_index(
30303030
self,
30313031
axis=0,
30323032
level=None,

0 commit comments

Comments
 (0)