Skip to content

Validate all values for csv.QUOTE #991

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 3 commits into from
Sep 7, 2024
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
16 changes: 15 additions & 1 deletion pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from collections.abc import (
)
import datetime
from os import PathLike
import sys
from typing import (
Any,
Literal,
Expand Down Expand Up @@ -738,7 +739,20 @@ JsonSeriesOrient: TypeAlias = Literal["split", "records", "index", "table"]
TimestampConvention: TypeAlias = Literal["start", "end", "s", "e"]

CSVEngine: TypeAlias = Literal["c", "python", "pyarrow", "python-fwf"]
CSVQuoting: TypeAlias = Literal[0, 1, 2, 3]
# [pandas-dev/pandas-stubs/991]
# Ref: https://github.com/python/cpython/blob/5a4fb7ea1c96f67dbb3df5d4ccaf3f66a1e19731/Modules/_csv.c#L88-L91
# QUOTE_MINIMAL = 0
# QUOTE_ALL = 1
# QUOTE_NONNUMERIC = 2
# QUOTE_NONE = 3
# Added in 3.12:
# QUOTE_STRINGS = 4
# QUOTE_NOTNULL = 5
CSVQuotingCompat: TypeAlias = Literal[0, 1, 2, 3]
if sys.version_info < (3, 12):
CSVQuoting: TypeAlias = CSVQuotingCompat
else:
CSVQuoting: TypeAlias = CSVQuotingCompat | Literal[4, 5]

HDFCompLib: TypeAlias = Literal["zlib", "lzo", "bzip2", "blosc"]
ParquetEngine: TypeAlias = Literal["auto", "pyarrow", "fastparquet"]
Expand Down
8 changes: 8 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import itertools
from pathlib import Path
import string
import sys
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -172,6 +173,13 @@ def test_types_to_csv() -> None:
# Testing support for binary file handles, added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
df.to_csv(io.BytesIO(), quoting=csv.QUOTE_ALL, encoding="utf-8", compression="gzip")

if sys.version_info >= (3, 12):
with ensure_clean() as path:
df.to_csv(path, quoting=csv.QUOTE_STRINGS)

with ensure_clean() as path:
df.to_csv(path, quoting=csv.QUOTE_NOTNULL)


def test_types_to_csv_when_path_passed() -> None:
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
Expand Down
Loading