-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: read_csv with custom date parser and na_filter=True results in ValueError #39079
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
Conversation
ftrihardjo
commented
Jan 10, 2021
•
edited by jreback
Loading
edited by jreback
- closes BUG: read_csv with custom date parser and na_filter=True results in ValueError #36111
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
Hello @ftrihardjo! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-01-19 21:48:07 UTC |
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.
need to compare the result with an explictly constructed frame, see other tests for examples
pandas/tests/io/test_common.py
Outdated
@@ -139,6 +139,22 @@ def test_iterator(self): | |||
tm.assert_frame_equal(first, expected.iloc[[0]]) | |||
tm.assert_frame_equal(pd.concat(it), expected.iloc[1:]) | |||
|
|||
def test_read_csv_with_custom_date_parser(self): |
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.
can you move to pandas/tests/io/parser//test_parse_dates.py
pandas/tests/io/test_common.py
Outdated
41051.00 -98573.7302 871458.0640 389.0086 | ||
""") | ||
|
||
df = pd.read_csv(testdata, delim_whitespace=True, parse_dates=True, date_parser=__custom_date_parser, index_col='time') |
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 want to test with the fixture all_parsers
pandas/tests/io/test_common.py
Outdated
def test_read_csv_with_custom_date_parser(self): | ||
# GH36111 | ||
def __custom_date_parser(time): | ||
time_temp = time.astype(np.float).astype(np.int) # convert float seconds to int type |
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.
this won't pass linting
@@ -55,6 +55,39 @@ def test_separator_date_conflict(all_parsers): | |||
) | |||
tm.assert_frame_equal(df, expected) | |||
|
|||
def test_read_csv_with_custom_date_parser(self): |
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.
use the allparser fixture (and thus parser.read_csv) see the test above for how
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.
you also have some liniting errors, pls use precommit locally to fix
@@ -55,6 +55,40 @@ def test_separator_date_conflict(all_parsers): | |||
) | |||
tm.assert_frame_equal(df, expected) | |||
|
|||
@pytest.fixtures(all_parsers) |
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.
you don't need this line at all
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.
how to run pre-commit for a single file because running pre-commit run --all-files like in pre-commit website is too slow for my computer