Skip to content
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

BUG: csv.QUOTE_NOTNULL doesn't seem to be supported by DataFrame.to_csv(), but there's no error and it's not documented #60423

Open
3 tasks done
wjandrea opened this issue Nov 26, 2024 · 1 comment
Labels
Bug IO CSV read_csv, to_csv Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@wjandrea
Copy link
Contributor

wjandrea commented Nov 26, 2024

Pandas version checks

  • I have checked that this issue has not already been reported.
    • No issues mention QUOTE_NOTNULL
  • 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 csv
import pandas as pd

df = pd.DataFrame(
    [[0, None, np.nan, pd.NA]],
    columns=['a', 'b', 'c', 'd'])

print(df.to_csv(quoting=csv.QUOTE_NOTNULL, index=False))

Issue Description

All fields are quoted, even nulls.

"a","b","c","d"
"0","","",""

Expected Behavior

All nulls should be unquoted.

"a","b","c","d"
"0",,,

Another possibility I might have expected is only unquoting None, as described in the csv docs, but this doesn't make sense for Pandas IMHO since Pandas has multiple "NULL"s.

"a","b","c","d"
"0",,"",""

Installed Versions

INSTALLED VERSIONS
------------------
commit                : b1c2ba793bb1f3d7001de41ca4c73377006b9e4d
python                : 3.12.7
python-bits           : 64
OS                    : Linux
OS-release            : 5.4.0-200-generic
Version               : #220-Ubuntu SMP Fri Sep 27 13:19:16 UTC 2024
machine               : x86_64
processor             : x86_64
byteorder             : little
LC_ALL                : None
LANG                  : fr_CA.UTF-8
LOCALE                : fr_CA.UTF-8

pandas                : 3.0.0.dev0+1729.gb1c2ba793b
numpy                 : 2.1.0.dev0+git20240403.e59c074
dateutil              : 2.9.0.post0
pip                   : 24.2
Cython                : None
sphinx                : None
IPython               : 8.22.2
adbc-driver-postgresql: None
adbc-driver-sqlite    : None
bs4                   : None
blosc                 : None
bottleneck            : None
fastparquet           : None
fsspec                : None
html5lib              : None
hypothesis            : None
gcsfs                 : None
jinja2                : None
lxml.etree            : None
matplotlib            : None
numba                 : None
numexpr               : None
odfpy                 : None
openpyxl              : None
psycopg2              : None
pymysql               : None
pyarrow               : None
pyreadstat            : None
pytest                : None
python-calamine       : None
pytz                  : 2024.1
pyxlsb                : None
s3fs                  : None
scipy                 : None
sqlalchemy            : None
tables                : None
tabulate              : None
xarray                : None
xlrd                  : None
xlsxwriter            : None
zstandard             : None
tzdata                : 2024.1
qtpy                  : None
pyqt5                 : None
@wjandrea wjandrea added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 26, 2024
@asishm
Copy link
Contributor

asishm commented Nov 26, 2024

Thanks, looks like csv.QUOTE_NOTNULL was added in python 3.12 along with csv.QUOTE_STRINGS. The user guide at https://pandas.pydata.org/docs/user_guide/io.html#quoting-compression-and-file-format also only mentions 0,1,2,3

quotingint or csv.QUOTE_* instance, default 0
Control field quoting behavior per csv.QUOTE_* constants. Use one of QUOTE_MINIMAL (0), QUOTE_ALL (1), QUOTE_NONNUMERIC (2) or QUOTE_NONE (3).

@asishm asishm added the IO CSV read_csv, to_csv label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants