Skip to content

Commit ecc668d

Browse files
anmyachevvnlitvinov
authored andcommitted
added new '%Y %m %d' format and 2 @pytest.mark.parametrize for test_hypothesis_delimited_date
1 parent 900cea8 commit ecc668d

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

pandas/tests/io/parser/test_parse_dates.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -906,24 +906,25 @@ def test_parse_delimited_date_swap(all_parsers, datestring,
906906
min_value=date(1000, 1, 1),
907907
max_value=date(9999, 12, 31)
908908
)
909-
_DEFAULT_DATETIME = datetime(1, 1, 1).replace(hour=0, minute=0,
910-
second=0, microsecond=0)
909+
_DEFAULT_DATETIME = datetime(1, 1, 1)
911910

912911

913912
@given(gen_random_datetime)
914-
@pytest.mark.parametrize("date_format, delimiters, dayfirst", [
915-
("%m %d %Y", " -./", False),
916-
("%m %d %Y", " -./", True),
917-
("%d %m %Y", " -./", True),
918-
("%d %m %Y", " -./", False),
919-
("%m %Y", " -/", False),
920-
("%m %Y", " -/", True)
913+
@pytest.mark.parametrize("delimiter", list(" -./"))
914+
@pytest.mark.parametrize("dayfirst", [True, False])
915+
@pytest.mark.parametrize("date_format", [
916+
"%m %d %Y",
917+
"%d %m %Y",
918+
"%m %Y",
919+
"%Y %m %d"
921920
])
922-
def test_hypothesis_delimited_date(date_format, delimiters, dayfirst, date):
923-
date_strings = [date.strftime(date_format.replace(' ', delim))
924-
for delim in delimiters]
925-
for date_string in date_strings:
926-
result = parse_datetime_string(date_string, dayfirst=dayfirst)
927-
expected = du_parse(date_string, default=_DEFAULT_DATETIME,
928-
dayfirst=dayfirst, yearfirst=False)
929-
assert result == expected
921+
def test_hypothesis_delimited_date(date_format, dayfirst, delimiter, date):
922+
if date_format == "%m %Y" and delimiter == ".":
923+
# parse_datetime_string cannot reliably tell whether e.g. %m.%Y
924+
# is a float or a date, thus we skip it
925+
pytest.skip()
926+
date_string = date.strftime(date_format.replace(' ', delimiter))
927+
result = parse_datetime_string(date_string, dayfirst=dayfirst)
928+
expected = du_parse(date_string, default=_DEFAULT_DATETIME,
929+
dayfirst=dayfirst, yearfirst=False)
930+
assert result == expected

0 commit comments

Comments
 (0)