Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,17 @@ def _isna(obj, inf_as_na: bool = False):
return False
elif isinstance(obj, (np.ndarray, ABCExtensionArray)):
return _isna_array(obj, inf_as_na=inf_as_na)
elif isinstance(obj, (ABCSeries, ABCIndex)):
elif isinstance(obj, ABCIndex):
# Try to use cached isna, which also short-circuits for integer dtypes
# and avoids materializing RangeIndex._values
if not obj._can_hold_na:
return obj.isna()
return _isna_array(obj._values, inf_as_na=inf_as_na)

elif isinstance(obj, ABCSeries):
result = _isna_array(obj._values, inf_as_na=inf_as_na)
# box
if isinstance(obj, ABCSeries):
result = obj._constructor(
result, index=obj.index, name=obj.name, copy=False
)
result = obj._constructor(result, index=obj.index, name=obj.name, copy=False)
return result
elif isinstance(obj, ABCDataFrame):
return obj.isna()
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ def argsort(self, *args, **kwargs) -> npt.NDArray[np.intp]:
numpy.ndarray.argsort
"""
ascending = kwargs.pop("ascending", True) # EA compat
kwargs.pop("kind", None) # e.g. "mergesort" is irrelevant
nv.validate_argsort(args, kwargs)

if self._range.step > 0:
Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,9 @@ def test_numpy_argsort(self, index):
expected = index.argsort()
tm.assert_numpy_array_equal(result, expected)

if not isinstance(index, RangeIndex):
# TODO: add compatibility to RangeIndex?
result = np.argsort(index, kind="mergesort")
expected = index.argsort(kind="mergesort")
tm.assert_numpy_array_equal(result, expected)
result = np.argsort(index, kind="mergesort")
expected = index.argsort(kind="mergesort")
tm.assert_numpy_array_equal(result, expected)

# these are the only two types that perform
# pandas compatibility input validation - the
Expand Down