Skip to content

fix(polars): plan missing-value actions only where pandas does - #542

Merged
JohnnyWilson16 merged 1 commit into
mainfrom
fix/polars-int-dtype-jwd
Nov 28, 2026
Merged

JohnnyWilson16 merged 1 commit into
mainfrom
fix/polars-int-dtype-jwd

Conversation

@JohnnyWilson16

Copy link
Copy Markdown
Contributor

Cause

The Polars planner planned impute_median for every numeric column, also for columns with no nulls. apply_plan fills with expr.median(), which is Float64. So an Int64 column with no nulls came back as Float64. pandas plans no fill for that column, so it stays int64. The README quickstart showed the symptom: [missing] invoice_total: impute_median {} for a column with no nulls.

This is launch gate G6 in the adoption audit (Phase 3 parity difference P1).

Change

PolarsBackend.suggest_plan adds one boolean "keep" flag per missing-value action to its one planning query. After the query, it drops the actions that change no cell. The rules match stage_missing in pandas:

  • impute_median, impute_mean, impute_mode: the column has some nulls, but not only nulls.
  • impute_ffill: forward fill fills at least one cell.
  • drop_nulls: the column has nulls, or the frame is empty.

The planner still runs one query. apply_plan still runs no query.

Check

New tests in tests/test_backend_honesty.py:

  • test_polars_plans_missing_actions_only_where_pandas_does (5 strategies, DataFrame and LazyFrame)
  • test_polars_keeps_int_dtype_when_no_value_is_missing

Before (main c386c8d):

E           AssertionError: assert {('age', 'imp...impute_mode')} == {('age', 'impute_mode')}
E             Extra items in the left set:
E             ('qty', 'impute_mode')
E             ('gone', 'impute_mode')
E             Extra items in the left set:
E             ('qty', 'drop_nulls')
E       assert Float64 == Int64
6 failed, 20 deselected in 0.66s

After:

6 passed, 20 deselected in 0.54s

Full suite: 107 passed, coverage 96.18%. ruff check . and mypy are clean. The README blocks run with exit 0.

Public behavior change

Polars plans have fewer actions. Columns with no nulls (or only nulls) get no missing-value action, and Int64 columns stay Int64 after apply_plan. pandas plans do not change. CHANGELOG.md records this under [3.0.0] / Fixed, because 3.0.0 is not on PyPI yet.

Not changed: after a drop_nulls, pandas counts rows_affected on the rows that are left, and Polars counts on the input. The new test compares actions, not those counts.

The Polars planner added impute_median for every numeric column, also
for columns with no nulls. The fill used a Float64 median, so applying
the plan turned Int64 columns into Float64. pandas skips those columns.

The planner now gets one keep flag per missing-value action from its
one planning query and drops the actions that change no cell: a fill
needs some nulls but not only nulls, drop_nulls needs nulls (or an
empty frame), ffill needs one filled cell. The rules match
stage_missing in pandas. Int columns with no nulls stay Int64.

The README output loses the no-op "invoice_total: impute_median" line.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ca7401ff-9b2f-4591-bd7e-1dc68359c898
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@JohnnyWilson16
JohnnyWilson16 merged commit 8cf7e20 into main Nov 28, 2026
15 checks passed
@JohnnyWilson16
JohnnyWilson16 deleted the fix/polars-int-dtype-jwd branch November 28, 2026 16:42
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