Skip to content

BUG: pd.DataFrame.to_csv with escaping produces different output in python 3.10 and 3.11 than 3.8 and 3.9 #51123

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

Open
3 tasks done
LeeMendelowitz opened this issue Feb 2, 2023 · 0 comments

Comments

@LeeMendelowitz
Copy link

LeeMendelowitz commented Feb 2, 2023

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import sys

v = sys.version_info
py_version = f'{v.major}-{v.minor}-{v.micro}'
file_name = f'test.{py_version}.{pd.__version__}.csv'

weird_strings = ['"hi"', 'you,\nthere', 'hi\\there', 'hi\there', 'weird\nstuff\rgoing\\']
df = pd.DataFrame({'d' : weird_strings})
df.to_csv(file_name, index = False, header = False, na_rep = 'NULL', escapechar = "\\", doublequote = False)

Issue Description

The above code produces different CSV files using pandas 1.5.3 in python 3.10 and python 3.11 than it does in python 3.8 and python 3.9.

Could this be related to #47871, which also describes different pandas.DataFrame.to_csv behavior around escaping between python versions?

Expected Behavior

I would expect the CSV files to be identical regardless of the version of Python.

Installed Versions

INSTALLED VERSIONS

commit : 2e218d1
python : 3.10.9.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.3
numpy : 1.24.1
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 65.6.3
pip : 22.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@LeeMendelowitz LeeMendelowitz added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 2, 2023
@DeaMariaLeon DeaMariaLeon added IO CSV read_csv, to_csv Python 3.8 Python 3.10 Python 3.11 and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants