Skip to content

Commit 831a63b

Browse files
Backport PR #44192: PERF: read_csv GH#44106 (#44197)
Co-authored-by: jbrockmendel <[email protected]>
1 parent b66c366 commit 831a63b

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
@@ -206,9 +206,10 @@ def _set_noconvert_columns(self):
206206
"""
207207
assert self.orig_names is not None
208208
# error: Cannot determine type of 'names'
209-
col_indices = [
210-
self.orig_names.index(x) for x in self.names # type: ignore[has-type]
211-
]
209+
210+
# much faster than using orig_names.index(x) xref GH#44106
211+
names_dict = {x: i for i, x in enumerate(self.orig_names)}
212+
col_indices = [names_dict[x] for x in self.names] # type: ignore[has-type]
212213
# error: Cannot determine type of 'names'
213214
noconvert_columns = self._set_noconvert_dtype_columns(
214215
col_indices,

0 commit comments

Comments
 (0)