Skip to content

BUG: convert_objects with convert_dates=coerce was parsing a into a date #3671

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

Merged
merged 1 commit into from
May 21, 2013
Merged
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: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ pandas 0.11.1
- Fix running of bs4 tests when it is not installed (GH3605_)
- Fix parsing of html table (GH3606_)
- ``read_html()`` now only allows a single backend: ``html5lib`` (GH3616_)
- ``convert_objects`` with ``convert_dates='coerce'`` was parsing some single-letter strings
into today's date

.. _GH3164: https://github.com/pydata/pandas/issues/3164
.. _GH2786: https://github.com/pydata/pandas/issues/2786
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3509,6 +3509,15 @@ def test_convert_objects(self):
#result = r.convert_objects(convert_dates=True,convert_numeric=False)
#self.assert_(result.dtype == 'M8[ns]')

# dateutil parses some single letters into today's value as a date
for x in 'abcdefghijklmnopqrstuvwxyz':
s = Series([x])
result = s.convert_objects(convert_dates='coerce')
assert_series_equal(result,s)
s = Series([x.upper()])
result = s.convert_objects(convert_dates='coerce')
assert_series_equal(result,s)

def test_apply_args(self):
s = Series(['foo,bar'])

Expand Down
9 changes: 9 additions & 0 deletions pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ class Timestamp(_Timestamp):


_nat_strings = set(['NaT','nat','NAT','nan','NaN','NAN'])
_not_datelike_strings = set(['a','A','m','M','p','P','t','T'])
class NaTType(_NaT):
"""(N)ot-(A)-(T)ime, the time equivalent of NaN"""

Expand Down Expand Up @@ -876,6 +877,14 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
&dts)
_check_dts_bounds(iresult[i], &dts)
except ValueError:

# for some reason, dateutil parses some single letter len-1 strings into today's date
if len(val) == 1 and val in _not_datelike_strings:
if coerce:
iresult[i] = iNaT
continue
elif raise_:
raise
try:
result[i] = parse(val, dayfirst=dayfirst)
except Exception:
Expand Down