diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 6a0455e0b4cd6..b30dbe32eec4b 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -26,7 +26,6 @@ ) import warnings -from dateutil.parser import ParserError import numpy as np from pandas._libs import ( @@ -1588,19 +1587,10 @@ def maybe_cast_to_datetime( value = to_timedelta(value, errors="raise")._values except OutOfBoundsDatetime: raise - except ParserError: - # Note: ParserError subclasses ValueError - # str that we can't parse to datetime + except ValueError: + # TODO(GH#40048): only catch dateutil's ParserError + # once we can reliably import it in all supported versions pass - except ValueError as err: - if "mixed datetimes and integers in passed array" in str(err): - # array_to_datetime does not allow this; - # when called from _try_cast, this will be followed - # by a call to construct_1d_ndarray_preserving_na - # which will convert these - pass - else: - raise # coerce datetimelike to object elif is_datetime64_dtype( diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index cb83dfba683b7..afc7ccb516c7f 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -89,8 +89,6 @@ def test_array_of_dt64_nat_with_td64dtype_raises(self, frame_or_series): arr = arr.reshape(1, 1) msg = "Could not convert object to NumPy timedelta" - if frame_or_series is Series: - msg = "Invalid type for timedelta scalar: " with pytest.raises(ValueError, match=msg): frame_or_series(arr, dtype="m8[ns]") diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index c952cbcee2dbc..c2d0bf5975059 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1332,7 +1332,7 @@ def test_constructor_dtype_timedelta64(self): td.astype("int32") # this is an invalid casting - msg = "Could not convert 'foo' to NumPy timedelta" + msg = "Could not convert object to NumPy timedelta" with pytest.raises(ValueError, match=msg): Series([timedelta(days=1), "foo"], dtype="m8[ns]")