Skip to content

Commit ab687ae

Browse files
authored
BUG: revert parts of #40037 (#40053)
1 parent 10034a4 commit ab687ae

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

pandas/core/dtypes/cast.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
)
2727
import warnings
2828

29-
from dateutil.parser import ParserError
3029
import numpy as np
3130

3231
from pandas._libs import (
@@ -1588,19 +1587,10 @@ def maybe_cast_to_datetime(
15881587
value = to_timedelta(value, errors="raise")._values
15891588
except OutOfBoundsDatetime:
15901589
raise
1591-
except ParserError:
1592-
# Note: ParserError subclasses ValueError
1593-
# str that we can't parse to datetime
1590+
except ValueError:
1591+
# TODO(GH#40048): only catch dateutil's ParserError
1592+
# once we can reliably import it in all supported versions
15941593
pass
1595-
except ValueError as err:
1596-
if "mixed datetimes and integers in passed array" in str(err):
1597-
# array_to_datetime does not allow this;
1598-
# when called from _try_cast, this will be followed
1599-
# by a call to construct_1d_ndarray_preserving_na
1600-
# which will convert these
1601-
pass
1602-
else:
1603-
raise
16041594

16051595
# coerce datetimelike to object
16061596
elif is_datetime64_dtype(

pandas/tests/frame/test_constructors.py

-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ def test_array_of_dt64_nat_with_td64dtype_raises(self, frame_or_series):
8989
arr = arr.reshape(1, 1)
9090

9191
msg = "Could not convert object to NumPy timedelta"
92-
if frame_or_series is Series:
93-
msg = "Invalid type for timedelta scalar: <class 'numpy.datetime64'>"
9492
with pytest.raises(ValueError, match=msg):
9593
frame_or_series(arr, dtype="m8[ns]")
9694

pandas/tests/series/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ def test_constructor_dtype_timedelta64(self):
13321332
td.astype("int32")
13331333

13341334
# this is an invalid casting
1335-
msg = "Could not convert 'foo' to NumPy timedelta"
1335+
msg = "Could not convert object to NumPy timedelta"
13361336
with pytest.raises(ValueError, match=msg):
13371337
Series([timedelta(days=1), "foo"], dtype="m8[ns]")
13381338

0 commit comments

Comments
 (0)