Skip to content

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:`set_option` where setting the pandas option ``display.html.use_mathjax`` to ``False`` has no effect (:issue:`59884`)
- Bug in :meth:`to_csv` where ``quotechar``` is not escaped when ``escapechar`` is not None (:issue:`61407`)
- 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