Skip to content

Commit 94cbaa1

Browse files
committed
Do runtime version check
1 parent 88ac71a commit 94cbaa1

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pandas-stubs/_typing.pyi

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ from typing import (
1818
TypeVar,
1919
overload,
2020
)
21+
import sys
2122

2223
import numpy as np
2324
from numpy import typing as npt
@@ -738,7 +739,20 @@ JsonSeriesOrient: TypeAlias = Literal["split", "records", "index", "table"]
738739
TimestampConvention: TypeAlias = Literal["start", "end", "s", "e"]
739740

740741
CSVEngine: TypeAlias = Literal["c", "python", "pyarrow", "python-fwf"]
741-
CSVQuoting: TypeAlias = Literal[0, 1, 2, 3, 4, 5]
742+
# [pandas-dev/pandas-stubs/991]
743+
# Ref: https://github.com/python/cpython/blob/5a4fb7ea1c96f67dbb3df5d4ccaf3f66a1e19731/Modules/_csv.c#L88-L91
744+
# QUOTE_MINIMAL = 0
745+
# QUOTE_ALL = 1
746+
# QUOTE_NONNUMERIC = 2
747+
# QUOTE_NONE = 3
748+
# Added in 3.12:
749+
# QUOTE_STRINGS = 4
750+
# QUOTE_NOTNULL = 5
751+
CSVQuotingCompat: TypeAlias = Literal[0, 1, 2, 3]
752+
if sys.version_info < (3, 12):
753+
CSVQuoting: TypeAlias = CSVQuotingCompat
754+
else:
755+
CSVQuoting: TypeAlias = CSVQuotingCompat | Literal[4, 5]
742756

743757
HDFCompLib: TypeAlias = Literal["zlib", "lzo", "bzip2", "blosc"]
744758
ParquetEngine: TypeAlias = Literal["auto", "pyarrow", "fastparquet"]

tests/test_frame.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
Union,
2626
cast,
2727
)
28+
import sys
2829

2930
import numpy as np
3031
import numpy.typing as npt
@@ -172,8 +173,12 @@ def test_types_to_csv() -> None:
172173
# Testing support for binary file handles, added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
173174
df.to_csv(io.BytesIO(), quoting=csv.QUOTE_ALL, encoding="utf-8", compression="gzip")
174175

175-
with ensure_clean() as path:
176-
df.to_csv(path, quoting=csv.QUOTE_STRINGS)
176+
if sys.version_info >= (3, 12):
177+
with ensure_clean() as path:
178+
df.to_csv(path, quoting=csv.QUOTE_STRINGS)
179+
180+
with ensure_clean() as path:
181+
df.to_csv(path, quoting=csv.QUOTE_NOTNULL)
177182

178183

179184
def test_types_to_csv_when_path_passed() -> None:

0 commit comments

Comments
 (0)