Skip to content

Commit f9444ea

Browse files
authored
PERF: read_csv GH#44106 (#44192)
1 parent 1b9be34 commit f9444ea

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

doc/source/whatsnew/v1.3.5.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ including other versions of pandas.
1414

1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
17-
-
17+
- Fixed performance regression in :func:`read_csv` (:issue:`44106`)
1818
-
1919

2020
.. ---------------------------------------------------------------------------

pandas/io/parsers/c_parser_wrapper.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,10 @@ def _set_noconvert_columns(self):
205205
"""
206206
assert self.orig_names is not None
207207
# error: Cannot determine type of 'names'
208-
col_indices = [
209-
self.orig_names.index(x) for x in self.names # type: ignore[has-type]
210-
]
208+
209+
# much faster than using orig_names.index(x) xref GH#44106
210+
names_dict = {x: i for i, x in enumerate(self.orig_names)}
211+
col_indices = [names_dict[x] for x in self.names] # type: ignore[has-type]
211212
# error: Cannot determine type of 'names'
212213
noconvert_columns = self._set_noconvert_dtype_columns(
213214
col_indices,

0 commit comments

Comments
 (0)