Skip to content

Commit ef1f736

Browse files
BUG: Edited test structure pandas-dev#46071
1 parent 78e6bc7 commit ef1f736

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pandas/tests/arrays/test_datetimes.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -648,33 +648,34 @@ def test_tz_localize_t2d(self):
648648
)
649649
def test_coerce_fallback(self, error):
650650
# GH#46071
651+
# 2 valid dates with different formats
652+
# Should parse with no errors
651653
s = pd.Series(["6/30/2025", "1 27 2024"])
652654
expected = pd.Series(
653655
[pd.Timestamp("2025-06-30 00:00:00"), pd.Timestamp("2024-01-27 00:00:00")]
654656
)
655-
656657
result = pd.to_datetime(s, errors=error, infer_datetime_format=True)
657-
658-
if error == "coerce":
659-
assert result[1] is not pd.NaT
660-
661658
tm.assert_series_equal(expected, result)
662659

660+
# Invalid inputs
661+
# Errors should be raised for the second element
663662
expected2 = pd.Series([pd.Timestamp("2000-01-01 00:00:00"), pd.NaT])
664-
663+
# Out of bounds date
665664
es1 = pd.Series(["1/1/2000", "7/12/1200"])
666-
es2 = pd.Series(["1/1/2000", "Hello"])
667-
665+
# Invalid input string
666+
es2 = pd.Series(["1/1/2000", "Invalid input"])
668667
if error == "coerce":
669668
eres1 = pd.to_datetime(es1, errors=error, infer_datetime_format=True)
670-
eres2 = pd.to_datetime(es2, errors=error, infer_datetime_format=True)
671669
tm.assert_series_equal(expected2, eres1)
670+
eres2 = pd.to_datetime(es2, errors=error, infer_datetime_format=True)
672671
tm.assert_series_equal(expected2, eres2)
673672
else:
674673
with pytest.raises(
675674
OutOfBoundsDatetime, match="Out of bounds nanosecond timestamp"
676675
):
677676
pd.to_datetime(es1, errors=error, infer_datetime_format=True)
678677

679-
with pytest.raises(ParserError, match="Unknown string format: Hello"):
678+
with pytest.raises(
679+
ParserError, match="Unknown string format: Invalid input"
680+
):
680681
pd.to_datetime(es2, errors=error, infer_datetime_format=True)

0 commit comments

Comments
 (0)