3
3
Tests for Timestamp parsing, aimed at pandas/_libs/tslibs/parsing.pyx
4
4
"""
5
5
from datetime import datetime
6
-
7
6
import numpy as np
8
7
import pytest
9
8
from dateutil .parser import parse
10
-
9
+ from pandas . conftest import is_dateutil_le_261 , is_dateutil_gt_261
11
10
from pandas import compat
12
11
from pandas .util import testing as tm
13
-
14
12
from pandas ._libs .tslibs import parsing
15
13
16
14
@@ -68,7 +66,7 @@ def test_parsers_monthfreq(self):
68
66
69
67
class TestGuessDatetimeFormat (object ):
70
68
71
- @pytest . mark . xfail ( reason = "GH18141 - dateutil > 2.6.1 broken" )
69
+ @is_dateutil_le_261
72
70
@pytest .mark .parametrize (
73
71
"string, format" ,
74
72
[
@@ -86,7 +84,20 @@ def test_guess_datetime_format_with_parseable_formats(
86
84
result = parsing ._guess_datetime_format (string )
87
85
assert result == format
88
86
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
90
101
@pytest .mark .parametrize (
91
102
"dayfirst, expected" ,
92
103
[
@@ -98,7 +109,16 @@ def test_guess_datetime_format_with_dayfirst(self, dayfirst, expected):
98
109
ambiguous_string , dayfirst = dayfirst )
99
110
assert result == expected
100
111
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
102
122
@pytest .mark .parametrize (
103
123
"string, format" ,
104
124
[
@@ -114,6 +134,22 @@ def test_guess_datetime_format_with_locale_specific_formats(
114
134
result = parsing ._guess_datetime_format (string )
115
135
assert result == format
116
136
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
+
117
153
def test_guess_datetime_format_invalid_inputs (self ):
118
154
# A datetime string must include a year, month and a day for it
119
155
# to be guessable, in addition to being a string that looks like
@@ -132,7 +168,7 @@ def test_guess_datetime_format_invalid_inputs(self):
132
168
for invalid_dt in invalid_dts :
133
169
assert parsing ._guess_datetime_format (invalid_dt ) is None
134
170
135
- @pytest . mark . xfail ( reason = "GH18141 - dateutil > 2.6.1 broken" )
171
+ @is_dateutil_le_261
136
172
@pytest .mark .parametrize (
137
173
"string, format" ,
138
174
[
@@ -147,6 +183,21 @@ def test_guess_datetime_format_nopadding(self, string, format):
147
183
result = parsing ._guess_datetime_format (string )
148
184
assert result == format
149
185
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
+
150
201
151
202
class TestArrayToDatetime (object ):
152
203
def test_try_parse_dates (self ):
0 commit comments