Skip to content

BUGFIX: escape quotechar when escapechar is not None (even if quoting=csv.QUOTE_NONE) #61514

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

Conversation

KevsterAmp
Copy link
Contributor

@KevsterAmp KevsterAmp commented May 29, 2025


Found the issue on CSVFormatter._initialize_quotechar, wherein it only returns quotechar when self.quoting is not csvlib.QUOTE_NONE:

if self.quoting != csvlib.QUOTE_NONE:
    # prevents crash in _csv
    return quotechar
return None

to follow the same behavior of csv.writer (escape when escapechar is not None), I improved the if function to return quotechar when self.escapechar is not None

in the CSVFormatter.__init__, moved the initialization of self.escapechar higher than self.quotechar since the initial solution was returning errors from calling self.escapechar before its initialization

initially marked as draft to let the CIs run & check if there are tests affected by this change

@KevsterAmp KevsterAmp marked this pull request as draft May 29, 2025 11:53
@KevsterAmp KevsterAmp changed the title initialize quotechar when self.escapechar is not None even if self.qu… BUG initialize quotechar when self.escapechar is not None even if self.qu… May 29, 2025
@KevsterAmp KevsterAmp changed the title BUG initialize quotechar when self.escapechar is not None even if self.qu… BUGFIX: fix quotechar when escapechar is not None even if self.qu… May 29, 2025
@KevsterAmp KevsterAmp changed the title BUGFIX: fix quotechar when escapechar is not None even if self.qu… BUGFIX: escape quotechar when escapechar is not None (even if quoting=csv.QUOTE_NONE) May 29, 2025
@KevsterAmp
Copy link
Contributor Author

CI errors looks unrelated

@KevsterAmp KevsterAmp marked this pull request as ready for review May 29, 2025 14:07
- Bug in :meth:`to_excel` where :class:`MultiIndex` columns would be merged to a single row when ``merge_cells=False`` is passed (:issue:`60274`)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/home/runner/work/pandas/pandas/doc/source/whatsnew/v3.0.0.rst:809: WARNING: Bullet list ends without a blank line; unexpected unindent. [docutils]

@KevsterAmp KevsterAmp requested a review from mroeschke May 30, 2025 01:35
@mroeschke mroeschke added the IO CSV read_csv, to_csv label May 30, 2025
@mroeschke mroeschke added this to the 3.0 milestone May 30, 2025
@mroeschke mroeschke merged commit f31a4b1 into pandas-dev:main May 30, 2025
47 of 48 checks passed
@mroeschke
Copy link
Member

Thanks @KevsterAmp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: to_csv() quotechar/escapechar behavior differs from csv module
2 participants