pandas icon indicating copy to clipboard operation
pandas copied to clipboard

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

Open edbennett opened this issue 1 year ago • 2 comments

Pandas version checks

  • [X] 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+".

edbennett avatar Apr 30 '24 08:04 edbennett

Similar to what I said in #58488, not sure if this is worth fixing considering there's already a PR working on removing this parameter in #58280 We could fix this and backport it to the current docs, but I'm not sure if that's really necessary

Aloqeely avatar Apr 30 '24 11:04 Aloqeely

Ah, I hadn't realised that removing the parameter entirely was so imminent. I agree that it's probably not worth backporting documentation changes for this.

edbennett avatar Apr 30 '24 11:04 edbennett