Skip to content

use a raw string for the whitespace separator regex - #4

Open
cboettig wants to merge 1 commit into
mainfrom
fix-regex-escape
Open

cboettig wants to merge 1 commit into
mainfrom
fix-regex-escape

Conversation

@cboettig

Copy link
Copy Markdown
Member

One character. sep = '\s+' → sep = r'\s+' in climate.ipynb.

\s is not a recognised Python escape. Python currently falls back to treating such sequences literally, so the regex works and the tests pass — but on the image's Python 3.14 it emits:

SyntaxWarning: "\s" is an invalid escape sequence.
Such sequences will not work in the future. Did you mean "\\s"? A raw string is also an option.

"Will not work in the future" is the operative part: this is slated to become a hard error. It sits in the notebook every student copies, so it would break the whole cohort at once whenever that lands.

How this came up

Chasing a delim_whitespace failure in a student repo. Worth recording what that turned up, since it is not what it looked like:

  • delim_whitespace appears nowhere in any of the four templates, nor in espm-157/website. The template has always used the correct sep. That student introduced it themselves — it is a pandas 1.x idiom removed in pandas 3.0, which the image ships.
  • Same for the other two pilot failures: the template reads the NOAA URL, so FileNotFoundError: 'co2_mm_mlo.csv' is a student switching to an uncommitted local file; and the template's kernelspec is python3, so NoSuchKernel: climate is a student's locally-created venv kernel saved into notebook metadata.

So the course materials were not the source of any of those. This escape sequence is the one real latent issue in them, found by compiling every code cell of all four template notebooks under 3.14 — it was the only hit.

sep = "\s+" relies on Python treating an unrecognised escape literally. On the
image Python (3.14) that emits

  SyntaxWarning: "\s" is an invalid escape sequence.
  Such sequences will not work in the future.

It still works today, so nothing fails yet, but it is in the notebook every
student copies. r"\s+" is the form that keeps working.
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

Successfully merging this pull request may close these issues.

1 participant