From 79e1b6d6197111c617adb416b35d959cce0c885b Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Sun, 12 Nov 2017 09:34:57 -0500 Subject: [PATCH] TST: xfail dateutil > 2.6.1 tests xref #18141 --- pandas/tests/indexes/datetimes/test_tools.py | 2 + pandas/tests/scalar/test_parsing.py | 88 ++++++++++++-------- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index 307184cb34e27..f53688fd5c84a 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -995,6 +995,8 @@ def test_dayfirst(self, cache): class TestGuessDatetimeFormat(object): + + @pytest.mark.xfail(reason="GH18141 - dateutil > 2.6.1 broken") def test_guess_datetime_format_for_array(self): tm._skip_if_not_us_locale() expected_format = '%Y-%m-%d %H:%M:%S.%f' diff --git a/pandas/tests/scalar/test_parsing.py b/pandas/tests/scalar/test_parsing.py index 6908fecbd4e05..54ae84b678a94 100644 --- a/pandas/tests/scalar/test_parsing.py +++ b/pandas/tests/scalar/test_parsing.py @@ -67,37 +67,52 @@ def test_parsers_monthfreq(self): class TestGuessDatetimeFormat(object): - def test_guess_datetime_format_with_parseable_formats(self): + + @pytest.mark.xfail(reason="GH18141 - dateutil > 2.6.1 broken") + @pytest.mark.parametrize( + "string, format", + [ + ('20111230', '%Y%m%d'), + ('2011-12-30', '%Y-%m-%d'), + ('30-12-2011', '%d-%m-%Y'), + ('2011-12-30 00:00:00', '%Y-%m-%d %H:%M:%S'), + ('2011-12-30T00:00:00', '%Y-%m-%dT%H:%M:%S'), + ('2011-12-30 00:00:00.000000', + '%Y-%m-%d %H:%M:%S.%f')]) + def test_guess_datetime_format_with_parseable_formats( + self, string, format): tm._skip_if_not_us_locale() - dt_string_to_format = (('20111230', '%Y%m%d'), - ('2011-12-30', '%Y-%m-%d'), - ('30-12-2011', '%d-%m-%Y'), - ('2011-12-30 00:00:00', '%Y-%m-%d %H:%M:%S'), - ('2011-12-30T00:00:00', '%Y-%m-%dT%H:%M:%S'), - ('2011-12-30 00:00:00.000000', - '%Y-%m-%d %H:%M:%S.%f'), ) - - for dt_string, dt_format in dt_string_to_format: - assert parsing._guess_datetime_format(dt_string) == dt_format - - def test_guess_datetime_format_with_dayfirst(self): - ambiguous_string = '01/01/2011' - assert parsing._guess_datetime_format( - ambiguous_string, dayfirst=True) == '%d/%m/%Y' - assert parsing._guess_datetime_format( - ambiguous_string, dayfirst=False) == '%m/%d/%Y' - def test_guess_datetime_format_with_locale_specific_formats(self): + result = parsing._guess_datetime_format(string) + assert result == format + + @pytest.mark.xfail(reason="GH18141 - dateutil > 2.6.1 broken") + @pytest.mark.parametrize( + "dayfirst, expected", + [ + (True, "%d/%m/%Y"), + (False, "%m/%d/%Y")]) + def test_guess_datetime_format_with_dayfirst(self, dayfirst, expected): + ambiguous_string = '01/01/2011' + result = parsing._guess_datetime_format( + ambiguous_string, dayfirst=dayfirst) + assert result == expected + + @pytest.mark.xfail(reason="GH18141 - dateutil > 2.6.1 broken") + @pytest.mark.parametrize( + "string, format", + [ + ('30/Dec/2011', '%d/%b/%Y'), + ('30/December/2011', '%d/%B/%Y'), + ('30/Dec/2011 00:00:00', '%d/%b/%Y %H:%M:%S')]) + def test_guess_datetime_format_with_locale_specific_formats( + self, string, format): # The month names will vary depending on the locale, in which # case these wont be parsed properly (dateutil can't parse them) tm._skip_if_has_locale() - dt_string_to_format = (('30/Dec/2011', '%d/%b/%Y'), - ('30/December/2011', '%d/%B/%Y'), - ('30/Dec/2011 00:00:00', '%d/%b/%Y %H:%M:%S'), ) - - for dt_string, dt_format in dt_string_to_format: - assert parsing._guess_datetime_format(dt_string) == dt_format + result = parsing._guess_datetime_format(string) + assert result == format def test_guess_datetime_format_invalid_inputs(self): # A datetime string must include a year, month and a day for it @@ -117,17 +132,20 @@ def test_guess_datetime_format_invalid_inputs(self): for invalid_dt in invalid_dts: assert parsing._guess_datetime_format(invalid_dt) is None - def test_guess_datetime_format_nopadding(self): + @pytest.mark.xfail(reason="GH18141 - dateutil > 2.6.1 broken") + @pytest.mark.parametrize( + "string, format", + [ + ('2011-1-1', '%Y-%m-%d'), + ('30-1-2011', '%d-%m-%Y'), + ('1/1/2011', '%m/%d/%Y'), + ('2011-1-1 00:00:00', '%Y-%m-%d %H:%M:%S'), + ('2011-1-1 0:0:0', '%Y-%m-%d %H:%M:%S'), + ('2011-1-3T00:00:0', '%Y-%m-%dT%H:%M:%S')]) + def test_guess_datetime_format_nopadding(self, string, format): # GH 11142 - dt_string_to_format = (('2011-1-1', '%Y-%m-%d'), - ('30-1-2011', '%d-%m-%Y'), - ('1/1/2011', '%m/%d/%Y'), - ('2011-1-1 00:00:00', '%Y-%m-%d %H:%M:%S'), - ('2011-1-1 0:0:0', '%Y-%m-%d %H:%M:%S'), - ('2011-1-3T00:00:0', '%Y-%m-%dT%H:%M:%S')) - - for dt_string, dt_format in dt_string_to_format: - assert parsing._guess_datetime_format(dt_string) == dt_format + result = parsing._guess_datetime_format(string) + assert result == format class TestArrayToDatetime(object):