-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Don't parse index column as numeric when parse_dates=True #14077
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
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 |
---|---|---|
|
@@ -474,3 +474,35 @@ def test_parse_dates_empty_string(self): | |
result = self.read_csv(StringIO(data), parse_dates=["Date"], | ||
na_filter=False) | ||
self.assertTrue(result['Date'].isnull()[1]) | ||
|
||
def test_parse_dates_noconvert_thousands(self): | ||
# see gh-14066 | ||
data = 'a\n04.15.2016' | ||
|
||
expected = DataFrame([datetime(2016, 4, 15)], columns=['a']) | ||
result = self.read_csv(StringIO(data), parse_dates=['a'], | ||
thousands='.') | ||
tm.assert_frame_equal(result, expected) | ||
|
||
exp_index = DatetimeIndex(['2016-04-15'], name='a') | ||
expected = DataFrame(index=exp_index) | ||
result = self.read_csv(StringIO(data), index_col=0, | ||
parse_dates=True, thousands='.') | ||
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. test 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. Done. |
||
tm.assert_frame_equal(result, expected) | ||
|
||
data = 'a,b\n04.15.2016,09.16.2013' | ||
|
||
expected = DataFrame([[datetime(2016, 4, 15), | ||
datetime(2013, 9, 16)]], | ||
columns=['a', 'b']) | ||
result = self.read_csv(StringIO(data), parse_dates=['a', 'b'], | ||
thousands='.') | ||
tm.assert_frame_equal(result, expected) | ||
|
||
expected = DataFrame([[datetime(2016, 4, 15), | ||
datetime(2013, 9, 16)]], | ||
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 a dict for |
||
columns=['a', 'b']) | ||
expected = expected.set_index(['a', 'b']) | ||
result = self.read_csv(StringIO(data), index_col=[0, 1], | ||
parse_dates=True, thousands='.') | ||
tm.assert_frame_equal(result, expected) |
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.
is_list_like
? (I don't know if its coerced to a list before this), same belowUh oh!
There was an error while loading. Please reload this page.
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.
We expect
parse_dates
to a bebool
,list
, ordict
per the docs. This is explicitly validated as well (see here), sois_list_like
is unnecessary.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.
do you need to handle
dict
at this point? (or is that already transformed)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.
index_col
can never be adict
per the docs.If you're referring to
parse_dates
,parse_dates
being adict
has a completely different meaning that is independent of theindex_col
.