Skip to content

BUG: revert parts of #40037 #40053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
)
import warnings

from dateutil.parser import ParserError
import numpy as np

from pandas._libs import (
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: <class 'numpy.datetime64'>"
with pytest.raises(ValueError, match=msg):
frame_or_series(arr, dtype="m8[ns]")

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]")

Expand Down