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

Invalid typing for df.to_csv #962

Open
JensHeinrich opened this issue Jul 19, 2024 · 1 comment
Open

Invalid typing for df.to_csv #962

JensHeinrich opened this issue Jul 19, 2024 · 1 comment

Comments

@JensHeinrich
Copy link

There probably should be a switch like

if sys.version_info >= (3, 12):
    CSVQuoting: TypeAlias = Literal[0, 1, 2, 3, 4,5]
else:
    CSVQuoting: TypeAlias = Literal[0, 1, 2, 3]

at

CSVQuoting: TypeAlias = Literal[0, 1, 2, 3]

as QUOTE_STRINGS and QUOTE_NOTNULL options have been added in python 3.12

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jul 19, 2024

Sounds reasonable. Interestingly, typeshed for csv.writer() has this declaration for the quoting argument: quoting: _QuotingType. Then when defining QuotingType, there is this:

UOTE_ALL: Literal[1]
QUOTE_MINIMAL: Literal[0]
QUOTE_NONE: Literal[3]
QUOTE_NONNUMERIC: Literal[2]
if sys.version_info >= (3, 12):
    QUOTE_STRINGS: Literal[4]
    QUOTE_NOTNULL: Literal[5]

# Ideally this would be `QUOTE_ALL | QUOTE_MINIMAL | QUOTE_NONE | QUOTE_NONNUMERIC`
# However, using literals in situations like these can cause false-positives (see #7258)
_QuotingType: TypeAlias = int

That links to this issue: python/typeshed#7258

Nevertheless, I'm open to a PR with your suggested changes, although we may want to consider referring to the constants in the csv package rather than the explicit numbers 0, 1, 2, 3, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants