Skip to content

Commit 5e6e590

Browse files
author
y-p
committed
BUG: regression in read_csv parser handling of usecols GH5766
GH4406 fixed one bug and introduced (exposed?) this corner case where the loop over columns continues even after all usecols have been fulfilled, causing an out-of-bound lookup in names.
1 parent 1509a22 commit 5e6e590

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pandas/parser.pyx

+3
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,9 @@ cdef class TextReader:
898898
if i < self.leading_cols:
899899
# Pass through leading columns always
900900
name = i
901+
elif self.usecols and nused == len(self.usecols):
902+
# Once we've gathered all requested columns, stop. GH5766
903+
break
901904
else:
902905
name = self._get_column_name(i, nused)
903906
if self.has_usecols and not (i in self.usecols or

0 commit comments

Comments
 (0)