Skip to content

COMPAT: dateutil 2.5.0 bug fix #12613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/install_travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ else
echo "pip installs"
REQ="ci/requirements-${TRAVIS_PYTHON_VERSION}${JOB_TAG}.pip"
if [ -e ${REQ} ]; then
pip install -r $REQ
pip install --upgrade -r $REQ
fi

# remove any installed pandas package
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-2.7.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dateutil=2.1
python-dateutil=2.4.1
pytz=2013b
numpy=1.9.3
cython=0.19.1
6 changes: 3 additions & 3 deletions ci/requirements-2.7.pip
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
blosc
httplib2
google-api-python-client == 1.2
python-gflags == 2.0
oauth2client == 1.5.0
google-api-python-client==1.2
python-gflags==2.0
oauth2client==1.5.0
pathlib
py
2 changes: 1 addition & 1 deletion ci/requirements-2.7.run
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dateutil=2.1
python-dateutil=2.4.1
pytz=2013b
numpy=1.9.3
xlwt=0.7.5
Expand Down
2 changes: 0 additions & 2 deletions ci/requirements-3.5_OSX.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
python-dateutil
pytz
numpy
cython
1 change: 1 addition & 0 deletions ci/requirements-3.5_OSX.pip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-dateutil>=2.5.0
1 change: 0 additions & 1 deletion ci/requirements-3.5_OSX.run
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
python-dateutil
pytz
numpy
openpyxl
Expand Down
4 changes: 4 additions & 0 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ def raise_with_traceback(exc, traceback=Ellipsis):
def parse_date(timestr, *args, **kwargs):
timestr = bytes(timestr)
return _date_parser.parse(timestr, *args, **kwargs)
elif PY2 and LooseVersion(dateutil.__version__) == '2.0':
# dateutil brokenness
raise Exception('dateutil 2.0 incompatible with Python 2.x, you must '
'install version 1.5 or 2.1+!')
else:
parse_date = _date_parser.parse

Expand Down
11 changes: 10 additions & 1 deletion pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import nose
import platform
from distutils.version import LooseVersion

from multiprocessing.pool import ThreadPool

Expand Down Expand Up @@ -1048,12 +1049,20 @@ def test_parse_dates_string(self):
'C': [2, 4, 5]}, idx)
tm.assert_frame_equal(rs, xp)

def test_yy_format(self):
def test_yy_format_with_yearfirst(self):
data = """date,time,B,C
090131,0010,1,2
090228,1020,3,4
090331,0830,5,6
"""

# https://github.com/dateutil/dateutil/issues/217
import dateutil
if dateutil.__version__ >= LooseVersion('2.5.0'):
raise nose.SkipTest("testing yearfirst=True not-support"
"on datetutil < 2.5.0 this works but"
"is wrong")

rs = self.read_csv(StringIO(data), index_col=0,
parse_dates=[['date', 'time']])
idx = DatetimeIndex([datetime(2009, 1, 31, 0, 10, 0),
Expand Down
29 changes: 20 additions & 9 deletions pandas/tseries/tests/test_tslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ def test_does_not_convert_mixed_integer(self):
good_date_string))

def test_parsers(self):

# https://github.com/dateutil/dateutil/issues/217
import dateutil
yearfirst = dateutil.__version__ >= LooseVersion('2.5.0')

cases = {'2011-01-01': datetime.datetime(2011, 1, 1),
'2Q2005': datetime.datetime(2005, 4, 1),
'2Q05': datetime.datetime(2005, 4, 1),
Expand Down Expand Up @@ -527,20 +532,26 @@ def test_parsers(self):
}

for date_str, expected in compat.iteritems(cases):
result1, _, _ = tools.parse_time_string(date_str)
result2 = to_datetime(date_str)
result3 = to_datetime([date_str])
result4 = to_datetime(np.array([date_str], dtype=object))
result5 = Timestamp(date_str)
result6 = DatetimeIndex([date_str])[0]
result7 = date_range(date_str, freq='S', periods=1)
result1, _, _ = tools.parse_time_string(date_str,
yearfirst=yearfirst)
result2 = to_datetime(date_str, yearfirst=yearfirst)
result3 = to_datetime([date_str], yearfirst=yearfirst)
result4 = to_datetime(np.array([date_str], dtype=object),
yearfirst=yearfirst)
result6 = DatetimeIndex([date_str], yearfirst=yearfirst)[0]
self.assertEqual(result1, expected)
self.assertEqual(result2, expected)
self.assertEqual(result3, expected)
self.assertEqual(result4, expected)
self.assertEqual(result5, expected)
self.assertEqual(result6, expected)
self.assertEqual(result7, expected)

# these really need to have yearfist, but we don't support
if not yearfirst:
result5 = Timestamp(date_str)
self.assertEqual(result5, expected)
result7 = date_range(date_str, freq='S', periods=1,
yearfirst=yearfirst)
self.assertEqual(result7, expected)

# NaT
result1, _, _ = tools.parse_time_string('NaT')
Expand Down
13 changes: 0 additions & 13 deletions pandas/tseries/tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from datetime import datetime, timedelta, time
import sys

import numpy as np

import pandas.lib as lib
Expand All @@ -10,17 +8,6 @@
import pandas.compat as compat
from pandas.util.decorators import deprecate_kwarg

try:
import dateutil
# raise exception if dateutil 2.0 install on 2.x platform
if (sys.version_info[0] == 2 and
dateutil.__version__ == '2.0'): # pragma: no cover
raise Exception('dateutil 2.0 incompatible with Python 2.x, you must '
'install version 1.5 or 2.1+!')
except ImportError: # pragma: no cover
print('Please install python-dateutil via easy_install or some method!')
raise # otherwise a 2nd import won't show the message

_DATEUTIL_LEXER_SPLIT = None
try:
# Since these are private methods from dateutil, it is safely imported
Expand Down