Skip to content

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

Closed
wants to merge 16 commits into from
16 changes: 16 additions & 0 deletions pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Contributor

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

# GH36111
def __custom_date_parser(time):
time_temp = time.astype(np.float).astype(np.int) # convert float seconds to int type
Copy link
Contributor

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

return pd.to_timedelta(time_temp, unit='s')

testdata = StringIO("""time e n h
41047.00 -98573.7297 871458.0640 389.0089
41048.00 -98573.7299 871458.0640 389.0089
41049.00 -98573.7300 871458.0642 389.0088
41050.00 -98573.7299 871458.0643 389.0088
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')
Copy link
Contributor

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


@pytest.mark.parametrize(
"reader, module, error_class, fn_ext",
[
Expand Down