Skip to content

Commit 7347c78

Browse files
BUG: Split up tests pandas-dev#46071
1 parent 8867090 commit 7347c78

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

pandas/tests/arrays/test_datetimes.py

+27-21
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ def test_tz_localize_t2d(self):
646646
"error",
647647
["coerce", "raise"],
648648
)
649-
def test_coerce_fallback(self, error):
649+
def test_fallback_different_formats(self, error):
650650
# GH#46071
651651
# 2 valid dates with different formats
652652
# Should parse with no errors
@@ -657,25 +657,31 @@ def test_coerce_fallback(self, error):
657657
result = pd.to_datetime(s, errors=error, infer_datetime_format=True)
658658
tm.assert_series_equal(expected, result)
659659

660+
@pytest.mark.parametrize(
661+
"dateseries",
662+
[
663+
pd.Series(["1/1/2000", "7/12/1200"]),
664+
pd.Series(["1/1/2000", "Invalid input"]),
665+
],
666+
)
667+
def test_fallback_with_errors_coerce(self, dateseries):
668+
# GH#46071
660669
# Invalid inputs
661-
# Errors should be raised for the second element
662-
expected2 = pd.Series([pd.Timestamp("2000-01-01 00:00:00"), pd.NaT])
663-
# Out of bounds date
664-
es1 = pd.Series(["1/1/2000", "7/12/1200"])
665-
# Invalid input string
666-
es2 = pd.Series(["1/1/2000", "Invalid input"])
667-
if error == "coerce":
668-
eres1 = pd.to_datetime(es1, errors=error, infer_datetime_format=True)
669-
tm.assert_series_equal(expected2, eres1)
670-
eres2 = pd.to_datetime(es2, errors=error, infer_datetime_format=True)
671-
tm.assert_series_equal(expected2, eres2)
672-
else:
673-
with pytest.raises(
674-
OutOfBoundsDatetime, match="Out of bounds nanosecond timestamp"
675-
):
676-
pd.to_datetime(es1, errors=error, infer_datetime_format=True)
670+
# Parsing should fail for the second element
671+
expected = pd.Series([pd.Timestamp("2000-01-01 00:00:00"), pd.NaT])
672+
result = pd.to_datetime(dateseries, errors="coerce", infer_datetime_format=True)
673+
tm.assert_series_equal(expected, result)
677674

678-
with pytest.raises(
679-
ParserError, match="Unknown string format: Invalid input"
680-
):
681-
pd.to_datetime(es2, errors=error, infer_datetime_format=True)
675+
def test_fallback_with_errors_raise(self):
676+
# GH#46071
677+
# Invalid inputs
678+
# Parsing should fail for the second element
679+
dates1 = pd.Series(["1/1/2000", "7/12/1200"])
680+
with pytest.raises(
681+
OutOfBoundsDatetime, match="Out of bounds nanosecond timestamp"
682+
):
683+
pd.to_datetime(dates1, errors="raise", infer_datetime_format=True)
684+
685+
dates2 = pd.Series(["1/1/2000", "Invalid input"])
686+
with pytest.raises(ParserError, match="Unknown string format: Invalid input"):
687+
pd.to_datetime(dates2, errors="raise", infer_datetime_format=True)

0 commit comments

Comments
 (0)