Skip to content

Commit b65551c

Browse files
authored
DEPR: Remove NumericIndex from tests/indexes/test_numpy_compat.py (#51132)
1 parent fa7639e commit b65551c

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

pandas/tests/indexes/test_numpy_compat.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
isna,
1111
)
1212
import pandas._testing as tm
13-
from pandas.api.types import is_complex_dtype
14-
from pandas.core.api import NumericIndex
13+
from pandas.api.types import (
14+
is_complex_dtype,
15+
is_numeric_dtype,
16+
)
1517
from pandas.core.arrays import BooleanArray
1618
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
1719

@@ -66,11 +68,8 @@ def test_numpy_ufuncs_basic(index, func):
6668
with tm.external_error_raised((TypeError, AttributeError)):
6769
with np.errstate(all="ignore"):
6870
func(index)
69-
elif (
70-
isinstance(index, NumericIndex)
71-
or (not isinstance(index.dtype, np.dtype) and index.dtype._is_numeric)
72-
or (index.dtype.kind == "c" and func not in [np.deg2rad, np.rad2deg])
73-
or index.dtype == bool
71+
elif is_numeric_dtype(index) and not (
72+
is_complex_dtype(index) and func in [np.deg2rad, np.rad2deg]
7473
):
7574
# coerces to float (e.g. np.sin)
7675
with np.errstate(all="ignore"):
@@ -81,10 +80,9 @@ def test_numpy_ufuncs_basic(index, func):
8180
exp = Index(arr_result, name=index.name)
8281

8382
tm.assert_index_equal(result, exp)
84-
if type(index) is not Index or index.dtype == bool:
85-
assert type(result) is NumericIndex
83+
if isinstance(index.dtype, np.dtype) and is_numeric_dtype(index):
8684
if is_complex_dtype(index):
87-
assert result.dtype == "complex64"
85+
assert result.dtype == index.dtype
8886
elif index.dtype in ["bool", "int8", "uint8"]:
8987
assert result.dtype in ["float16", "float32"]
9088
elif index.dtype in ["int16", "uint16", "float32"]:
@@ -128,11 +126,8 @@ def test_numpy_ufuncs_other(index, func):
128126
with tm.external_error_raised(TypeError):
129127
func(index)
130128

131-
elif (
132-
isinstance(index, NumericIndex)
133-
or (not isinstance(index.dtype, np.dtype) and index.dtype._is_numeric)
134-
or (index.dtype.kind == "c" and func is not np.signbit)
135-
or index.dtype == bool
129+
elif is_numeric_dtype(index) and not (
130+
is_complex_dtype(index) and func is np.signbit
136131
):
137132
# Results in bool array
138133
result = func(index)

0 commit comments

Comments
 (0)