Skip to content

Commit b69af4d

Browse files
committed
Add tests for date parsing when display.date_dayfirst and display.date_yearfirst are set
1 parent bc500f7 commit b69af4d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

pandas/tests/tslibs/test_parsing.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import numpy as np
1111
import pytest
1212

13+
from pandas._config import set_option
14+
1315
from pandas._libs.tslibs import (
1416
parsing,
1517
strptime,
@@ -421,3 +423,39 @@ def test_hypothesis_delimited_date(
421423

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

0 commit comments

Comments
 (0)