Polars
The Polars pack has 33 rules, and xpd can fix 22 of them.
The Polars pack checks code that imports polars. It reports APIs removed in
Polars 2.0, changes to expressions, and places where a lazy query or a native
expression can replace Python work. Version gates read the project's installed
version when xpd can find it. The rules follow local names to Polars constructors,
annotations and supported method chains. Python API reference
and Polars 2.0 upgrade guide.
The probes used Polars 2.1.0 on CPython 3.14.4 with -W error. Timings are the
median of seven runs after a warm-up with POLARS_MAX_THREADS=1. The two data sizes
were 50,000 and 500,000 rows. Where a rewrite preserves the result, timings compare
equal output values and dtypes using polars.testing.assert_frame_equal for frames.
The compiled checker reported 0 Polars diagnostics across the 219 Python files in
the installed Polars 2.1.0 package. A separate scan of Pandera at 29486d1
covered 66 Python files that import Polars. It reported 61 notes about the
Utf8 alias and one note about collecting in a loop, with zero Polars errors
or warnings.
Measured behavior
Section titled “Measured behavior”| Rule | Severity | Proof | Fix |
|---|---|---|---|
removed-in-polars |
error, info | AttributeRemovedError. AttributeError. TypeError with 0 arguments. TypeError. ModuleNotFoundError. All 11 removed protocol imports raised ImportError. Config.state omitted the variable when it was set to 1. | unsafe, none |
polars-removed-parameter |
error | ArgumentRemovedError. TypeError. ComputeError. | none |
deprecated-in-polars |
warning, info | DeprecationWarning for both methods. DeprecationWarning on concat and union. Identical dtype object. UnstableWarning with warn_unstable=True. | none, safe |
polars-streaming-order |
info | The first two unpivoted rows had labels b and c with streaming and b and b with the in-memory engine. | none |
polars-removed-cast |
error | InvalidOperationError. ComputeError. | none |
polars-selector-coercion |
info | Taking the union of numeric columns and a string column as a value expression raised SchemaError. Two selectors selected 3 columns. | none |
polars-mixed-dtype-arithmetic |
error | InvalidOperationError for two Series. A string Series plus integer scalar raised TypeError. | none |
polars-null-comparison |
warning | UserWarning under -W error | unsafe |
polars-expr-boolean-op |
error | TypeError from ambiguous truth value | none |
polars-expr-mask-precedence |
error | TypeError from chained comparison truth testing | none |
polars-when-without-otherwise |
info | The unhandled row held None. The explicit branch returned 0. | none |
polars-dataframe-orient |
info | Inferred first row (1, 3). Explicit row orientation gave (1, 2). | none |
polars-list-get-oob |
info | Index 1 raised ComputeError for a one-item list. null_on_oob=True returned [None, 3]. | none |
polars-eager-read-before-query |
info | 4.64x and 32.60x with one thread and row group pruning. | none |
polars-collect-then-lazy |
info | The collect call produced a DataFrame and lazy returned a new LazyFrame. | none |
polars-collect-then-write |
info | Eager write and streaming sink produced equal data after reading their files. | none |
polars-collect-in-loop |
info | Three collect calls produced the same three frames as collect_all in the probe. | none |
polars-lazy-schema-property |
warning | PerformanceWarning. The explicit replacement returned the same value and type. | safe |
polars-map-elements-native |
warning | PolarsInefficientMapWarning under -W error | none |
polars-map-without-return-dtype |
info | Inference produced List(Int64) on integer data and raised InvalidOperationError on two Null rows. | none |
polars-row-iteration |
info | 1279.48x and 623.31x with equal sums on integer data. | none |
polars-sequential-with-columns |
info | Independent expressions gave equal frames. | none |
polars-concat-in-loop |
info | 16.23x and 269.11x on 50,000 and 500,000 total rows across 25 batches with rechunk=True. | none |
polars-groupby-join-over |
info | Three rows with non-null keys gave equal frames. | none |
polars-sort-then-head |
info | Top-k was 2.51x and 3.96x faster on shuffled keys, and slower on already sorted keys. | none |
polars-pandas-api-name |
error | Thirteen AttributeError results on DataFrame, LazyFrame, and Series. | none |
polars-pandas-round-trip |
info | The integer-only round trip matched the original frame on 50,000 and 500,000 rows. | none |
polars-builtin-on-expr-or-series |
error | Five TypeError results on Expr. All five builtins worked on Series. | none |
polars-join-without-validate |
info | Two identical keys on each side yielded 4 rows. 1:1 validation raised ComputeError. | none |
polars-join-asof-unsorted |
info | Descending right keys raised InvalidOperationError with the default sortedness check. | none |
polars-categorical-vs-enum |
info | Categorical accepted typo. Enum raised InvalidOperationError for 1 unknown value. | none |
polars-sql-frame-globals |
info | Implicit and explicit binding each returned 3 rows. | none |
polars-assert-frame-equals |
warning | equals returned True. assert_frame_equal raised AssertionError for Int32 against Int64. | none |
Removed and deprecated APIs
Section titled “Removed and deprecated APIs”| Rule | Severity | Fix | What it finds |
|---|---|---|---|
| removed-in-polars | error | unsafe | Polars 2.0 removed methods and attributes that previously worked. |
| polars-removed-parameter | error | unsafe | Polars 2.0 removed several keyword arguments. |
| deprecated-in-polars | warning | safe | Polars 2.1.0 warns about older binning methods and redundant horizontal concatenation arguments. |
Types and query results
Section titled “Types and query results”| Rule | Severity | Fix | What it finds |
|---|---|---|---|
| polars-streaming-order | info | none | Polars 2.0 made streaming the default for lazy queries. |
| polars-removed-cast | error | unsafe | Polars 2.0 removed several casts that need an explicit conversion. |
| polars-selector-coercion | info | unsafe | A selector combined with col by &, | or ^ becomes a value expression in Polars 2.1.0. |
| polars-mixed-dtype-arithmetic | error | none | Polars 2.1.0 rejects string and numeric Series arithmetic. |
| polars-null-comparison | warning | unsafe | Polars 2.1.0 emits UserWarning for comparison to None. |
| polars-expr-boolean-op | error | unsafe | Polars 2.1.0 raises TypeError when a Python boolean operator tests a Polars expression or Series. |
| polars-expr-mask-precedence | error | unsafe | Polars 2.1.0 raises TypeError for this unparenthesized mask. |
| polars-when-without-otherwise | info | unsafe | Polars returns null for unmatched rows when then has no otherwise. |
| polars-dataframe-orient | info | none | Nested list data can fit both DataFrame orientations. |
| polars-list-get-oob | info | unsafe | Polars raises ComputeError for an out-of-bounds list offset by default. |
Lazy execution and file I/O
Section titled “Lazy execution and file I/O”| Rule | Severity | Fix | What it finds |
|---|---|---|---|
| polars-eager-read-before-query | info | unsafe | Start this lazy query with a scan to enable projection and predicate pushdown. |
| polars-collect-then-lazy | info | unsafe | Collect executes this query before lazy starts a new plan. |
| polars-collect-then-write | info | unsafe | Collect builds a DataFrame before writing. |
| polars-collect-in-loop | info | none | Collect inside a loop can execute a separate query on each iteration. |
| polars-lazy-schema-property | warning | safe | Polars 2.1.0 emits PerformanceWarning when code reads LazyFrame.schema. |
Expressions and Python loops
Section titled “Expressions and Python loops”| Rule | Severity | Fix | What it finds |
|---|---|---|---|
| polars-map-elements-native | warning | unsafe | Polars 2.1.0 emits PolarsInefficientMapWarning when map_elements wraps addition in this lambda. |
| polars-map-without-return-dtype | info | none | Polars may fail to infer the result type of a Python function. |
| polars-row-iteration | info | none | Use a Polars expression to compute a reduction over rows. |
| polars-sequential-with-columns | info | unsafe | Chained with_columns calls may split work into separate steps. |
| polars-concat-in-loop | info | none | Concatenating into the same frame on every iteration repeatedly grows the result. |
| polars-groupby-join-over | info | none | A join to an aggregation of the same Polars frame can often be written as a window expression. |
| polars-sort-then-head | info | unsafe | For a small number of rows, top_k or bottom_k can avoid a full sort. |
| polars-pandas-api-name | error | unsafe | Polars frames expose a different API from pandas. |
| polars-pandas-round-trip | info | unsafe | A Polars to pandas to Polars round trip converts the data twice. |
| polars-builtin-on-expr-or-series | error | unsafe | Polars 2.1.0 raises TypeError when this Python builtin tries to size or iterate an Expr. |
Joins, categories, SQL and testing
Section titled “Joins, categories, SQL and testing”| Rule | Severity | Fix | What it finds |
|---|---|---|---|
| polars-join-without-validate | info | none | A Polars join allows duplicate keys on either side by default. |
| polars-join-asof-unsorted | info | unsafe | An as-of join needs ascending join keys. |
| polars-categorical-vs-enum | info | none | Categorical accepts every string label. |
| polars-sql-frame-globals | info | none | Polars sql resolves table names from Python globals. |
| polars-assert-frame-equals | warning | unsafe | Polars DataFrame.equals returned True on equal values with Int32 and Int64 columns. |
What the pack leaves out
Section titled “What the pack leaves out”pl.count("x")still counts non-null values.polars.interchangestill exists and exportsCompatLevel. The rule covers four removed submodules and 11 removed protocol names.pl.Utf8 is pl.Stringis true and emits no warning. Avro read and write emitUnstableWarningonly withwarn_unstable=True. Both are informational.- The streaming and in-memory engines returned the same order on the single-threaded unpivot probe without a limit. A two-row limit exposed different results. The rule is informational because a positional limit can select any rows by design.
- A selector combined with a column can be a valid value operation. The mixed selector rule is informational. The cast and arithmetic rules require written Series values in the types that fail. Inferred column dtypes reach xpd only when the source spells out the evidence its rules use.
- A total sort beat top-k on already sorted data by 5.5 times and 3.4 times at the two sizes. Its rule is informational. The read, row and concat timings depend on file layout, operations and data. Their rules are informational as well.
- Python builtins work on Series, and some return deliberate Python values. The builtin rule reports Expr only. The as-of join rule targets the literal opt-out from sortedness checking. Sortedness can come from the input data.
- The pack leaves optional packages to the chosen I/O backend. Native readers do not require pyarrow, Excel can use another engine, and database reads can use ADBC. The pack has no project-wide package check.
- Dynamic imports, unknown receivers, indirect callbacks and most unpacked arguments can hide details. The pack relies on direct syntax and local value bindings. Other changes outside the listed APIs are covered by the upgrade guide.