diff --git a/pandas/tests/indexes/test_numpy_compat.py b/pandas/tests/indexes/test_numpy_compat.py index cdc5446bfeba3..2a29e57678df9 100644 --- a/pandas/tests/indexes/test_numpy_compat.py +++ b/pandas/tests/indexes/test_numpy_compat.py @@ -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 @@ -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"): @@ -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"]: @@ -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)