Skip to content

Commit 9b1bab5

Browse files
jbrockmendelclaude
andcommitted
TST: cover default dayfirst/yearfirst parse with unit (GH#63472)
Make dayfirst/yearfirst required on _to_datetime_with_unit so a future recursion site that drops them fails loudly, matching objects_to_datetime64. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent aea0c5d commit 9b1bab5

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

pandas/core/tools/datetimes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@ def _to_datetime_with_unit(
527527
name,
528528
utc: bool,
529529
errors: str,
530-
dayfirst=None,
531-
yearfirst=None,
530+
dayfirst,
531+
yearfirst,
532532
) -> Index:
533533
"""
534534
to_datetime specalized to the case where a 'unit' is passed.

pandas/tests/tools/test_to_datetime.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3977,6 +3977,7 @@ def test_empty_string_datetime_coerce__unit():
39773977
@pytest.mark.parametrize(
39783978
"kwargs, expected",
39793979
[
3980+
({}, "2012-10-11"),
39803981
({"dayfirst": True}, "2012-11-10"),
39813982
({"yearfirst": True}, "2010-11-12"),
39823983
({"dayfirst": True, "yearfirst": True}, "2010-12-11"),
@@ -3994,17 +3995,17 @@ def test_to_datetime_unit_dayfirst_yearfirst(kwargs, expected, cache):
39943995

39953996

39963997
@pytest.mark.parametrize(
3997-
"kwargs, expected",
3998+
"kwargs, parsed",
39983999
[
39994000
({"dayfirst": True}, "2012-11-10"),
40004001
({"yearfirst": True}, "2010-11-12"),
40014002
],
40024003
)
4003-
def test_to_datetime_unit_dayfirst_yearfirst_mixed_numeric(kwargs, expected, cache):
4004+
def test_to_datetime_unit_dayfirst_yearfirst_mixed_numeric(kwargs, parsed, cache):
40044005
# GH#63472 the unit still applies to the numeric entries
40054006
result = to_datetime(["10/11/12", 1], unit="s", cache=cache, **kwargs)
40064007

4007-
expected = DatetimeIndex([expected, "1970-01-01 00:00:01"], dtype="datetime64[us]")
4008+
expected = DatetimeIndex([parsed, "1970-01-01 00:00:01"], dtype="datetime64[us]")
40084009
tm.assert_index_equal(result, expected)
40094010

40104011

0 commit comments

Comments
 (0)