Skip to content

Commit d83871a

Browse files
authored
CI: update exception catching for np1.21 (#40697)
1 parent caa5649 commit d83871a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

pandas/core/dtypes/cast.py

+2
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,8 @@ def maybe_cast_to_datetime(
17331733
except ValueError:
17341734
# TODO(GH#40048): only catch dateutil's ParserError
17351735
# once we can reliably import it in all supported versions
1736+
if is_timedelta64:
1737+
raise
17361738
pass
17371739

17381740
# coerce datetimelike to object

pandas/tests/frame/test_constructors.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ def test_array_of_dt64_nat_with_td64dtype_raises(self, frame_or_series):
8989
if frame_or_series is DataFrame:
9090
arr = arr.reshape(1, 1)
9191

92-
msg = "Could not convert object to NumPy timedelta"
92+
msg = "|".join(
93+
[
94+
"Could not convert object to NumPy timedelta",
95+
"Invalid type for timedelta scalar: <class 'numpy.datetime64'>",
96+
]
97+
)
9398
with pytest.raises(ValueError, match=msg):
9499
frame_or_series(arr, dtype="m8[ns]")
95100

pandas/tests/series/test_constructors.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,12 @@ def test_constructor_dtype_timedelta64(self):
13511351
td.astype("int32")
13521352

13531353
# this is an invalid casting
1354-
msg = "Could not convert object to NumPy timedelta"
1354+
msg = "|".join(
1355+
[
1356+
"Could not convert object to NumPy timedelta",
1357+
"Could not convert 'foo' to NumPy timedelta",
1358+
]
1359+
)
13551360
with pytest.raises(ValueError, match=msg):
13561361
Series([timedelta(days=1), "foo"], dtype="m8[ns]")
13571362

0 commit comments

Comments
 (0)