File tree 2 files changed +7
-4
lines changed
2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -1300,10 +1300,12 @@ def _ensure_numeric(x):
1300
1300
elif not (is_float (x ) or is_integer (x ) or is_complex (x )):
1301
1301
try :
1302
1302
x = float (x )
1303
- except Exception :
1303
+ except ValueError :
1304
+ # e.g. "1+1j" or "foo"
1304
1305
try :
1305
1306
x = complex (x )
1306
- except Exception :
1307
+ except ValueError :
1308
+ # e.g. "foo"
1307
1309
raise TypeError (
1308
1310
"Could not convert {value!s} to numeric" .format (value = x )
1309
1311
)
Original file line number Diff line number Diff line change @@ -911,10 +911,11 @@ def test_non_convertable_values(self):
911
911
msg = "Could not convert foo to numeric"
912
912
with pytest .raises (TypeError , match = msg ):
913
913
nanops ._ensure_numeric ("foo" )
914
- msg = "Could not convert {} to numeric"
914
+
915
+ # with the wrong type, python raises TypeError for us
916
+ msg = "argument must be a string or a number"
915
917
with pytest .raises (TypeError , match = msg ):
916
918
nanops ._ensure_numeric ({})
917
- msg = r"Could not convert \[\] to numeric"
918
919
with pytest .raises (TypeError , match = msg ):
919
920
nanops ._ensure_numeric ([])
920
921
You can’t perform that action at this time.
0 commit comments