Skip to content

Commit 6f6f39f

Browse files
phoflluckyvs1
authored andcommitted
BUG: read_csv raising TypeError for engine=c with names and parse_dates (pandas-dev#38431)
1 parent d23ab4a commit 6f6f39f

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/whatsnew/v1.3.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ MultiIndex
148148
I/O
149149
^^^
150150

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

154154
Period

pandas/io/parsers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ def _should_parse_dates(self, i):
14311431
name = self.index_names[i]
14321432
else:
14331433
name = None
1434-
j = self.index_col[i]
1434+
j = i if self.index_col is None else self.index_col[i]
14351435

14361436
if is_scalar(self.parse_dates):
14371437
return (j == self.parse_dates) or (

pandas/tests/io/parser/test_parse_dates.py

+9
Original file line numberDiff line numberDiff line change
@@ -1595,3 +1595,12 @@ def test_missing_parse_dates_column_raises(
15951595
parser.read_csv(
15961596
content, sep=",", names=names, usecols=usecols, parse_dates=parse_dates
15971597
)
1598+
1599+
1600+
def test_date_parser_and_names(all_parsers):
1601+
# GH#33699
1602+
parser = all_parsers
1603+
data = StringIO("""x,y\n1,2""")
1604+
result = parser.read_csv(data, parse_dates=["B"], names=["B"])
1605+
expected = DataFrame({"B": ["y", "2"]}, index=["x", "1"])
1606+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)