-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Datetime resolution coercion #10249
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
Datetime resolution coercion #10249
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2057,18 +2057,20 @@ def converter(*date_cols): | |
infer_datetime_format=infer_datetime_format | ||
) | ||
except: | ||
return lib.try_parse_dates(strs, dayfirst=dayfirst) | ||
return tools.to_datetime( | ||
lib.try_parse_dates(strs, dayfirst=dayfirst)) | ||
else: | ||
try: | ||
result = date_parser(*date_cols) | ||
result = tools.to_datetime(date_parser(*date_cols)) | ||
if isinstance(result, datetime.datetime): | ||
raise Exception('scalar parser') | ||
return result | ||
except Exception: | ||
try: | ||
return lib.try_parse_dates(_concat_date_cols(date_cols), | ||
parser=date_parser, | ||
dayfirst=dayfirst) | ||
return tools.to_datetime( | ||
lib.try_parse_dates(_concat_date_cols(date_cols), | ||
parser=date_parser, | ||
dayfirst=dayfirst)) | ||
except Exception: | ||
return generic_parser(date_parser, *date_cols) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. techincally we should put the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure? It fails if I do so:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I guess that is some old behavior. |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
import numpy as np | ||
from numpy.testing.decorators import slow | ||
|
||
from pandas import DataFrame, Series, Index, isnull | ||
from pandas import DataFrame, Series, Index, MultiIndex, isnull | ||
import pandas.io.parsers as parsers | ||
from pandas.io.parsers import (read_csv, read_table, read_fwf, | ||
TextParser) | ||
|
@@ -119,6 +119,31 @@ def test_generic(self): | |
self.assertIn('ym', df) | ||
self.assertEqual(df.ym.ix[0], date(2001, 1, 1)) | ||
|
||
def test_dateparser_resolution_if_not_ns(self): | ||
# issue 10245 | ||
data = """\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add the issue number here |
||
date,time,prn,rxstatus | ||
2013-11-03,19:00:00,126,00E80000 | ||
2013-11-03,19:00:00,23,00E80000 | ||
2013-11-03,19:00:00,13,00E80000 | ||
""" | ||
|
||
def date_parser(date, time): | ||
datetime = np.array(date + 'T' + time + 'Z', dtype='datetime64[s]') | ||
return datetime | ||
|
||
df = read_csv(StringIO(data), date_parser=date_parser, | ||
parse_dates={'datetime': ['date', 'time']}, | ||
index_col=['datetime', 'prn']) | ||
|
||
datetimes = np.array(['2013-11-03T19:00:00Z']*3, dtype='datetime64[s]') | ||
df_correct = DataFrame(data={'rxstatus': ['00E80000']*3}, | ||
index=MultiIndex.from_tuples( | ||
[(datetimes[0], 126), | ||
(datetimes[1], 23), | ||
(datetimes[2], 13)], | ||
names=['datetime', 'prn'])) | ||
assert_frame_equal(df, df_correct) | ||
|
||
if __name__ == '__main__': | ||
import nose | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the issue number at the end