Skip to content

PERF: read_csv macro updates #52632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Other enhancements
- Improve error message when setting :class:`DataFrame` with wrong number of columns through :meth:`DataFrame.isetitem` (:issue:`51701`)
- Improved error message when creating a DataFrame with empty data (0 rows), no index and an incorrect number of columns. (:issue:`52084`)
- Let :meth:`DataFrame.to_feather` accept a non-default :class:`Index` and non-string column names (:issue:`51787`)
- Performance improvement in :func:`read_csv` (:issue:`52632`) with ``engine="c"``
-

.. ---------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions pandas/_libs/src/parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,7 @@ static int parser_buffer_bytes(parser_t *self, size_t nbytes,
((!self->delim_whitespace && c == ' ' && self->skipinitialspace))

// applied when in a field
#define IS_DELIMITER(c) \
((!self->delim_whitespace && c == self->delimiter) || \
(self->delim_whitespace && isblank(c)))
#define IS_DELIMITER(c) ((c == delimiter) || (delim_whitespace && isblank(c)))

#define _TOKEN_CLEANUP() \
self->stream_len = slen; \
Expand Down Expand Up @@ -721,6 +719,9 @@ int tokenize_bytes(parser_t *self,
const char lineterminator = (self->lineterminator == '\0') ?
'\n' : self->lineterminator;

const int delim_whitespace = self->delim_whitespace;
const char delimiter = self->delimiter;

// 1000 is something that couldn't fit in "char"
// thus comparing a char to it would always be "false"
const int carriage_symbol = (self->lineterminator == '\0') ? '\r' : 1000;
Expand Down