You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PERF: Optimize CSV categorical parsing when categories are known
When read_csv receives a CategoricalDtype with pre-specified categories,
map parsed values directly to category codes in a single pass using a
pre-built hash table, avoiding the factorize-then-recode steps.
For non-string category types (datetime, float edge cases, bool), the
optimization is attempted first and falls back to the existing path if
str() representations don't match the raw CSV tokens.
closespandas-dev#17743
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: doc/source/whatsnew/v3.1.0.rst
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,6 +132,7 @@ Performance improvements
132
132
- Performance improvement in :func:`merge` with ``how="cross"`` (:issue:`38082`)
133
133
- Performance improvement in :func:`merge` with ``how="left"`` (:issue:`64370`)
134
134
- Performance improvement in :func:`merge` with ``sort=False`` for single-key ``how="left"``/``how="right"`` joins when the opposite join key is sorted, unique, and range-like (:issue:`64146`)
135
+
- Performance improvement in :func:`read_csv` with ``engine="c"`` when parsing columns as :class:`CategoricalDtype` with known categories, by mapping parsed values directly to category codes in a single pass instead of factorizing and then recoding (:issue:`17743`)
135
136
- Performance improvement in :func:`read_csv` with ``engine="c"`` when reading from binary file-like objects (e.g. PyArrow S3 file handles) by avoiding unnecessary ``TextIOWrapper`` wrapping (:issue:`46823`)
136
137
- Performance improvement in :func:`read_html` and the Python CSV parser when ``thousands`` is set, fixing catastrophic regex backtracking on cells with many comma-separated digit groups followed by non-numeric text (:issue:`52619`)
137
138
- Performance improvement in :func:`read_sas` by reading page header fields directly in Cython instead of falling back to Python (:issue:`47339`)
0 commit comments