Skip to content

Commit b678d80

Browse files
jrebackNo-Stream
authored andcommitted
TST: conform tests for datetutil > 2.6.1 (pandas-dev#18253)
1 parent b98eea1 commit b678d80

File tree

3 files changed

+91
-8
lines changed

3 files changed

+91
-8
lines changed

pandas/conftest.py

+10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import pytest
22

3+
from distutils.version import LooseVersion
34
import numpy
45
import pandas
56
import pandas.util.testing as tm
7+
import dateutil
68

79

810
def pytest_addoption(parser):
@@ -65,3 +67,11 @@ def ip():
6567
pytest.importorskip('IPython', minversion="6.0.0")
6668
from IPython.core.interactiveshell import InteractiveShell
6769
return InteractiveShell()
70+
71+
72+
is_dateutil_le_261 = pytest.mark.skipif(
73+
LooseVersion(dateutil.__version__) > '2.6.1',
74+
reason="dateutil api change version")
75+
is_dateutil_gt_261 = pytest.mark.skipif(
76+
LooseVersion(dateutil.__version__) <= '2.6.1',
77+
reason="dateutil stable version")

pandas/tests/indexes/datetimes/test_tools.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from distutils.version import LooseVersion
1313

1414
import pandas as pd
15+
from pandas.conftest import is_dateutil_le_261, is_dateutil_gt_261
1516
from pandas._libs import tslib
1617
from pandas._libs.tslibs import parsing
1718
from pandas.core.tools import datetimes as tools
@@ -996,7 +997,7 @@ def test_dayfirst(self, cache):
996997

997998
class TestGuessDatetimeFormat(object):
998999

999-
@pytest.mark.xfail(reason="GH18141 - dateutil > 2.6.1 broken")
1000+
@is_dateutil_le_261
10001001
def test_guess_datetime_format_for_array(self):
10011002
tm._skip_if_not_us_locale()
10021003
expected_format = '%Y-%m-%d %H:%M:%S.%f'
@@ -1017,6 +1018,27 @@ def test_guess_datetime_format_for_array(self):
10171018
[np.nan, np.nan, np.nan], dtype='O'))
10181019
assert format_for_string_of_nans is None
10191020

1021+
@is_dateutil_gt_261
1022+
def test_guess_datetime_format_for_array_gt_261(self):
1023+
tm._skip_if_not_us_locale()
1024+
expected_format = '%Y-%m-%d %H:%M:%S.%f'
1025+
dt_string = datetime(2011, 12, 30, 0, 0, 0).strftime(expected_format)
1026+
1027+
test_arrays = [
1028+
np.array([dt_string, dt_string, dt_string], dtype='O'),
1029+
np.array([np.nan, np.nan, dt_string], dtype='O'),
1030+
np.array([dt_string, 'random_string'], dtype='O'),
1031+
]
1032+
1033+
for test_array in test_arrays:
1034+
assert tools._guess_datetime_format_for_array(
1035+
test_array) is None
1036+
1037+
format_for_string_of_nans = tools._guess_datetime_format_for_array(
1038+
np.array(
1039+
[np.nan, np.nan, np.nan], dtype='O'))
1040+
assert format_for_string_of_nans is None
1041+
10201042

10211043
class TestToDatetimeInferFormat(object):
10221044

pandas/tests/scalar/test_parsing.py

+58-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
Tests for Timestamp parsing, aimed at pandas/_libs/tslibs/parsing.pyx
44
"""
55
from datetime import datetime
6-
76
import numpy as np
87
import pytest
98
from dateutil.parser import parse
10-
9+
from pandas.conftest import is_dateutil_le_261, is_dateutil_gt_261
1110
from pandas import compat
1211
from pandas.util import testing as tm
13-
1412
from pandas._libs.tslibs import parsing
1513

1614

@@ -68,7 +66,7 @@ def test_parsers_monthfreq(self):
6866

6967
class 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

151202
class TestArrayToDatetime(object):
152203
def test_try_parse_dates(self):

0 commit comments

Comments
 (0)