Skip to content

DEPR: Remove NumericIndex from tests/indexes/test_numpy_compat.py #51132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
25 changes: 10 additions & 15 deletions pandas/tests/indexes/test_numpy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
isna,
)
import pandas._testing as tm
from pandas.api.types import is_complex_dtype
from pandas.core.api import NumericIndex
from pandas.api.types import (
is_complex_dtype,
is_numeric_dtype,
)
from pandas.core.arrays import BooleanArray
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin

Expand Down Expand Up @@ -66,11 +68,8 @@ def test_numpy_ufuncs_basic(index, func):
with tm.external_error_raised((TypeError, AttributeError)):
with np.errstate(all="ignore"):
func(index)
elif (
isinstance(index, NumericIndex)
or (not isinstance(index.dtype, np.dtype) and index.dtype._is_numeric)
or (index.dtype.kind == "c" and func not in [np.deg2rad, np.rad2deg])
or index.dtype == bool
elif is_numeric_dtype(index) and not (
is_complex_dtype(index) and func in [np.deg2rad, np.rad2deg]
):
# coerces to float (e.g. np.sin)
with np.errstate(all="ignore"):
Expand All @@ -81,10 +80,9 @@ def test_numpy_ufuncs_basic(index, func):
exp = Index(arr_result, name=index.name)

tm.assert_index_equal(result, exp)
if type(index) is not Index or index.dtype == bool:
assert type(result) is NumericIndex
if isinstance(index.dtype, np.dtype) and is_numeric_dtype(index):
if is_complex_dtype(index):
assert result.dtype == "complex64"
assert result.dtype == index.dtype
elif index.dtype in ["bool", "int8", "uint8"]:
assert result.dtype in ["float16", "float32"]
elif index.dtype in ["int16", "uint16", "float32"]:
Expand Down Expand Up @@ -128,11 +126,8 @@ def test_numpy_ufuncs_other(index, func):
with tm.external_error_raised(TypeError):
func(index)

elif (
isinstance(index, NumericIndex)
or (not isinstance(index.dtype, np.dtype) and index.dtype._is_numeric)
or (index.dtype.kind == "c" and func is not np.signbit)
or index.dtype == bool
elif is_numeric_dtype(index) and not (
is_complex_dtype(index) and func is np.signbit
):
# Results in bool array
result = func(index)
Expand Down