Skip to content

Instantly share code, notes, and snippets.

@DeflateAwning
Created August 1, 2024 21:17
Show Gist options
  • Save DeflateAwning/918bcdac3c5656d6fd9d1270933cd42f to your computer and use it in GitHub Desktop.
Save DeflateAwning/918bcdac3c5656d6fd9d1270933cd42f to your computer and use it in GitHub Desktop.
Polars Upgrade Regex Magic

Sometimes the Python Polars library upgrades.

The following are some codebase migrations I've used.

Pre-v0.20.x

  1. Find+Replace: pl.Utf8 -> pl.String

v0.20.31 to v1.x

  1. Find+Replace how='outer_coalesce' on joins
Find:
how\s*=\s*['"]outer_coalesce['"]\s*,

Replace:
how='full', coalesce=True,
  1. Locate .replace(..., return_dtype=something)
rg -U -t py '\.replace\([^)]+return_dtype'
  1. Non-breaking change with infer_schema_length (from 0 to False to read all as String):
Find: infer_schema_length\s*=\s*0
Replace: infer_schema_length=False
  1. Find pl.read_csv, and pin engine='xlsx2csv' arg (or migrate manually).
  2. Find and Replace all .frame_equal( to .equals(.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment