Skip to content

DOC: delim_whitespace deprecation warning advocates code that generates a warning in Python 3.12 #58487

Closed
@edbennett

Description

@edbennett

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

pandas.read_csv and https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html

Documentation problem

The deprecation warning for the delim_whitespace option suggests using sep="\s+" instead. Since \s is not a valid escape sequence, in Python 3.11 and earlier this is equivalent to sep=r"\s+".

However, in Python 3.12, invalid escape sequences now generate SyntaxWarnings. I would suggest that Pandas should avoid advising users to add code that will generate warnings (in particular when doing so via a warning—if the suggestion is implemented, then the number of warnings would remain constant rather than decreasing)

Suggested fix for documentation

Replace all instances of sep="\s+" with either sep=r"\s+" or sep="\\s+".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions