Skip to content

BUG: read_csv raising TypeError for engine=c with names and parse_dates #38431

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
Dec 12, 2020
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: 1 addition & 1 deletion doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ MultiIndex
I/O
^^^

-
- Bug in :func:`read_csv` raising ``TypeError`` when ``names`` and ``parse_dates`` is specified for ``engine="c"`` (:issue:`33699`)
-

Period
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ def _should_parse_dates(self, i):
name = self.index_names[i]
else:
name = None
j = self.index_col[i]
j = i if self.index_col is None else self.index_col[i]

if is_scalar(self.parse_dates):
return (j == self.parse_dates) or (
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/io/parser/test_parse_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1595,3 +1595,12 @@ def test_missing_parse_dates_column_raises(
parser.read_csv(
content, sep=",", names=names, usecols=usecols, parse_dates=parse_dates
)


def test_date_parser_and_names(all_parsers):
# GH#33699
parser = all_parsers
data = StringIO("""x,y\n1,2""")
result = parser.read_csv(data, parse_dates=["B"], names=["B"])
expected = DataFrame({"B": ["y", "2"]}, index=["x", "1"])
tm.assert_frame_equal(result, expected)