Skip to content

Commit 21f2ebe

Browse files
harinikhknvdn
andauthored
Add tests for date parsing when display.date_dayfirst and display.date_yearfirst are set (#62511)
Co-authored-by: Harini Krishnamurthy <[email protected]>
1 parent 7be1d10 commit 21f2ebe

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

pandas/tests/tslibs/test_parsing.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
# Usually we wouldn't want this import in this test file (which is targeted at
2626
# tslibs.parsing), but it is convenient to test the Timestamp constructor at
2727
# the same time as the other parsing functions.
28-
from pandas import Timestamp
28+
from pandas import (
29+
Timestamp,
30+
option_context,
31+
)
2932
import pandas._testing as tm
3033
from pandas._testing._hypothesis import DATETIME_NO_TZ
3134

@@ -422,3 +425,40 @@ def test_hypothesis_delimited_date(
422425

423426
assert except_out_dateutil == except_in_dateutil
424427
assert result == expected
428+
429+
430+
@pytest.mark.parametrize("input", ["21-01-01", "01-01-21"])
431+
@pytest.mark.parametrize("dayfirst", [True, False])
432+
def test_parse_datetime_string_with_reso_dayfirst(dayfirst, input):
433+
with option_context("display.date_dayfirst", dayfirst):
434+
except_out_dateutil, result = _helper_hypothesis_delimited_date(
435+
parsing.parse_datetime_string_with_reso, input
436+
)
437+
438+
except_in_dateutil, expected = _helper_hypothesis_delimited_date(
439+
du_parse,
440+
input,
441+
default=datetime(1, 1, 1),
442+
dayfirst=dayfirst,
443+
yearfirst=False,
444+
)
445+
assert except_out_dateutil == except_in_dateutil
446+
assert result[0] == expected
447+
448+
449+
@pytest.mark.parametrize("input", ["21-01-01", "01-01-21"])
450+
@pytest.mark.parametrize("yearfirst", [True, False])
451+
def test_parse_datetime_string_with_reso_yearfirst(yearfirst, input):
452+
with option_context("display.date_yearfirst", yearfirst):
453+
except_out_dateutil, result = _helper_hypothesis_delimited_date(
454+
parsing.parse_datetime_string_with_reso, input
455+
)
456+
except_in_dateutil, expected = _helper_hypothesis_delimited_date(
457+
du_parse,
458+
input,
459+
default=datetime(1, 1, 1),
460+
dayfirst=False,
461+
yearfirst=yearfirst,
462+
)
463+
assert except_out_dateutil == except_in_dateutil
464+
assert result[0] == expected

0 commit comments

Comments
 (0)