From c22cb16129c57c63bbe21a7b0e65a14c36f0139a Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 30 Mar 2021 14:20:18 -0700 Subject: [PATCH 1/2] CI: update exception catching for np1.21 --- pandas/core/dtypes/cast.py | 2 ++ pandas/tests/frame/test_constructors.py | 7 ++++++- pandas/tests/series/test_constructors.py | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 7a2175a364a8a..a46e74ae15a06 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -1733,6 +1733,8 @@ def maybe_cast_to_datetime( except ValueError: # TODO(GH#40048): only catch dateutil's ParserError # once we can reliably import it in all supported versions + if is_timedelta64: + raise pass # coerce datetimelike to object diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index b76a44b3c86be..5edeb72725d2f 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -89,7 +89,12 @@ def test_array_of_dt64_nat_with_td64dtype_raises(self, frame_or_series): if frame_or_series is DataFrame: arr = arr.reshape(1, 1) - msg = "Could not convert object to NumPy timedelta" + msg = "|".join( + [ + "Could not convert object to NumPy timedelta", + "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 ab484e7ae9d8a..613eae7b2e8c1 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1351,7 +1351,12 @@ def test_constructor_dtype_timedelta64(self): td.astype("int32") # this is an invalid casting - msg = "Could not convert object to NumPy timedelta" + msg = "|".join( + [ + "Could not convert object to NumPy timedelta", + "Invalid type for timedelta scalar: ", + ] + ) with pytest.raises(ValueError, match=msg): Series([timedelta(days=1), "foo"], dtype="m8[ns]") From c3b65c0b56176e1f2138d1e60c49397ea033c1fe Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 30 Mar 2021 15:02:06 -0700 Subject: [PATCH 2/2] fix caught message --- pandas/tests/series/test_constructors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 613eae7b2e8c1..75474a29169a7 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1354,7 +1354,7 @@ def test_constructor_dtype_timedelta64(self): msg = "|".join( [ "Could not convert object to NumPy timedelta", - "Invalid type for timedelta scalar: ", + "Could not convert 'foo' to NumPy timedelta", ] ) with pytest.raises(ValueError, match=msg):