@@ -49,8 +49,7 @@ def test_numpy_ufuncs_basic(index, func):
49
49
# https://numpy.org/doc/stable/reference/ufuncs.html
50
50
51
51
if isinstance (index , DatetimeIndexOpsMixin ):
52
- # raise TypeError or ValueError (PeriodIndex)
53
- with pytest .raises (Exception ):
52
+ with tm .external_error_raised ((TypeError , AttributeError )):
54
53
with np .errstate (all = "ignore" ):
55
54
func (index )
56
55
elif isinstance (index , (Float64Index , Int64Index , UInt64Index )):
@@ -66,7 +65,7 @@ def test_numpy_ufuncs_basic(index, func):
66
65
if len (index ) == 0 :
67
66
pass
68
67
else :
69
- with pytest . raises ( Exception ):
68
+ with tm . external_error_raised (( TypeError , AttributeError ) ):
70
69
with np .errstate (all = "ignore" ):
71
70
func (index )
72
71
@@ -77,7 +76,6 @@ def test_numpy_ufuncs_basic(index, func):
77
76
def test_numpy_ufuncs_other (index , func , request ):
78
77
# test ufuncs of numpy, see:
79
78
# https://numpy.org/doc/stable/reference/ufuncs.html
80
-
81
79
if isinstance (index , (DatetimeIndex , TimedeltaIndex )):
82
80
if isinstance (index , DatetimeIndex ) and index .tz is not None :
83
81
if func in [np .isfinite , np .isnan , np .isinf ]:
@@ -96,13 +94,11 @@ def test_numpy_ufuncs_other(index, func, request):
96
94
result = func (index )
97
95
assert isinstance (result , np .ndarray )
98
96
else :
99
- # raise TypeError or ValueError (PeriodIndex)
100
- with pytest .raises (Exception ):
97
+ with tm .external_error_raised (TypeError ):
101
98
func (index )
102
99
103
100
elif isinstance (index , PeriodIndex ):
104
- # raise TypeError or ValueError (PeriodIndex)
105
- with pytest .raises (Exception ):
101
+ with tm .external_error_raised (TypeError ):
106
102
func (index )
107
103
108
104
elif isinstance (index , (Float64Index , Int64Index , UInt64Index )):
@@ -114,5 +110,5 @@ def test_numpy_ufuncs_other(index, func, request):
114
110
if len (index ) == 0 :
115
111
pass
116
112
else :
117
- with pytest . raises ( Exception ):
113
+ with tm . external_error_raised ( TypeError ):
118
114
func (index )
0 commit comments