33Tests for Timestamp parsing, aimed at pandas/_libs/tslibs/parsing.pyx
44"""
55from datetime import datetime
6-
76import numpy as np
87import pytest
98from dateutil .parser import parse
10-
9+ from pandas . conftest import is_dateutil_le_261 , is_dateutil_gt_261
1110from pandas import compat
1211from pandas .util import testing as tm
13-
1412from pandas ._libs .tslibs import parsing
1513
1614
@@ -68,7 +66,7 @@ def test_parsers_monthfreq(self):
6866
6967class TestGuessDatetimeFormat (object ):
7068
71- @pytest . mark . xfail ( reason = "GH18141 - dateutil > 2.6.1 broken" )
69+ @is_dateutil_le_261
7270 @pytest .mark .parametrize (
7371 "string, format" ,
7472 [
@@ -86,7 +84,20 @@ def test_guess_datetime_format_with_parseable_formats(
8684 result = parsing ._guess_datetime_format (string )
8785 assert result == format
8886
89- @pytest .mark .xfail (reason = "GH18141 - dateutil > 2.6.1 broken" )
87+ @is_dateutil_gt_261
88+ @pytest .mark .parametrize (
89+ "string" ,
90+ ['20111230' , '2011-12-30' , '30-12-2011' ,
91+ '2011-12-30 00:00:00' , '2011-12-30T00:00:00' ,
92+ '2011-12-30 00:00:00.000000' ])
93+ def test_guess_datetime_format_with_parseable_formats_gt_261 (
94+ self , string ):
95+ tm ._skip_if_not_us_locale ()
96+
97+ result = parsing ._guess_datetime_format (string )
98+ assert result is None
99+
100+ @is_dateutil_le_261
90101 @pytest .mark .parametrize (
91102 "dayfirst, expected" ,
92103 [
@@ -98,7 +109,16 @@ def test_guess_datetime_format_with_dayfirst(self, dayfirst, expected):
98109 ambiguous_string , dayfirst = dayfirst )
99110 assert result == expected
100111
101- @pytest .mark .xfail (reason = "GH18141 - dateutil > 2.6.1 broken" )
112+ @is_dateutil_gt_261
113+ @pytest .mark .parametrize (
114+ "dayfirst" , [True , False ])
115+ def test_guess_datetime_format_with_dayfirst_gt_261 (self , dayfirst ):
116+ ambiguous_string = '01/01/2011'
117+ result = parsing ._guess_datetime_format (
118+ ambiguous_string , dayfirst = dayfirst )
119+ assert result is None
120+
121+ @is_dateutil_le_261
102122 @pytest .mark .parametrize (
103123 "string, format" ,
104124 [
@@ -114,6 +134,22 @@ def test_guess_datetime_format_with_locale_specific_formats(
114134 result = parsing ._guess_datetime_format (string )
115135 assert result == format
116136
137+ @is_dateutil_gt_261
138+ @pytest .mark .parametrize (
139+ "string" ,
140+ [
141+ '30/Dec/2011' ,
142+ '30/December/2011' ,
143+ '30/Dec/2011 00:00:00' ])
144+ def test_guess_datetime_format_with_locale_specific_formats_gt_261 (
145+ self , string ):
146+ # The month names will vary depending on the locale, in which
147+ # case these wont be parsed properly (dateutil can't parse them)
148+ tm ._skip_if_has_locale ()
149+
150+ result = parsing ._guess_datetime_format (string )
151+ assert result is None
152+
117153 def test_guess_datetime_format_invalid_inputs (self ):
118154 # A datetime string must include a year, month and a day for it
119155 # to be guessable, in addition to being a string that looks like
@@ -132,7 +168,7 @@ def test_guess_datetime_format_invalid_inputs(self):
132168 for invalid_dt in invalid_dts :
133169 assert parsing ._guess_datetime_format (invalid_dt ) is None
134170
135- @pytest . mark . xfail ( reason = "GH18141 - dateutil > 2.6.1 broken" )
171+ @is_dateutil_le_261
136172 @pytest .mark .parametrize (
137173 "string, format" ,
138174 [
@@ -147,6 +183,21 @@ def test_guess_datetime_format_nopadding(self, string, format):
147183 result = parsing ._guess_datetime_format (string )
148184 assert result == format
149185
186+ @is_dateutil_gt_261
187+ @pytest .mark .parametrize (
188+ "string" ,
189+ [
190+ '2011-1-1' ,
191+ '30-1-2011' ,
192+ '1/1/2011' ,
193+ '2011-1-1 00:00:00' ,
194+ '2011-1-1 0:0:0' ,
195+ '2011-1-3T00:00:0' ])
196+ def test_guess_datetime_format_nopadding_gt_261 (self , string ):
197+ # GH 11142
198+ result = parsing ._guess_datetime_format (string )
199+ assert result is None
200+
150201
151202class TestArrayToDatetime (object ):
152203 def test_try_parse_dates (self ):
0 commit comments