10
10
isna ,
11
11
)
12
12
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
+ )
15
17
from pandas .core .arrays import BooleanArray
16
18
from pandas .core .indexes .datetimelike import DatetimeIndexOpsMixin
17
19
@@ -66,11 +68,8 @@ def test_numpy_ufuncs_basic(index, func):
66
68
with tm .external_error_raised ((TypeError , AttributeError )):
67
69
with np .errstate (all = "ignore" ):
68
70
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 ]
74
73
):
75
74
# coerces to float (e.g. np.sin)
76
75
with np .errstate (all = "ignore" ):
@@ -81,10 +80,9 @@ def test_numpy_ufuncs_basic(index, func):
81
80
exp = Index (arr_result , name = index .name )
82
81
83
82
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 ):
86
84
if is_complex_dtype (index ):
87
- assert result .dtype == "complex64"
85
+ assert result .dtype == index . dtype
88
86
elif index .dtype in ["bool" , "int8" , "uint8" ]:
89
87
assert result .dtype in ["float16" , "float32" ]
90
88
elif index .dtype in ["int16" , "uint16" , "float32" ]:
@@ -128,11 +126,8 @@ def test_numpy_ufuncs_other(index, func):
128
126
with tm .external_error_raised (TypeError ):
129
127
func (index )
130
128
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
136
131
):
137
132
# Results in bool array
138
133
result = func (index )
0 commit comments