Skip to content

Adapt numerical base transformers to narwhals-returning check_X - #1022

Merged
solegalli merged 1 commit into
narwhals-migrationfrom
narwhals-numerical-base-adapt-check-x
Aug 30, 2026
Merged

Adapt numerical base transformers to narwhals-returning check_X#1022
solegalli merged 1 commit into
narwhals-migrationfrom
narwhals-numerical-base-adapt-check-x

Conversation

@solegalli

@solegalli solegalli commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

update classes to narwhals return from check_x

Since #1019, check_X / check_X_y return a narwhals DataFrame instead of the
native frame. BaseNumericalTransformer._fit_setup /
._check_transform_input_and_state and FitFromDictMixin._fit_from_dict rebind
`X = check_X(X)` and then pass that frame to find_numerical_variables,
check_numerical_variables, _check_contains_na and _check_contains_inf.

Those helpers branch on nwd.is_pandas_dataframe() internally. Handed a
narwhals frame they take the non-pandas path and emit a UserWarning per call
("You passed a narwhals.dataframe.DataFrame to is_pandas_dataframe") - a
single LogTransformer.fit_transform on pandas raised 5 such warnings - while
the pandas fast paths are silently skipped.

check_X is pure validation (no copy, no reshape), so the fix is to stop
rebinding X and keep passing the helpers the native input, exactly as before
#1019.

The transformation classes themselves need no changes (they are already
backend-agnostic: nw.from_native(X) on whatever the base returns). This also
restores the pre-#1019 baseline for the other consumers of these bases:
test_scaling 19/0 (was 14 failing), test_discretisation 5 failing (was 23).
No test changes; mypy and flake8 clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@solegalli
solegalli force-pushed the narwhals-numerical-base-adapt-check-x branch from e8bf2eb to 7beb0a0 Compare August 30, 2026 14:54
@solegalli
solegalli merged commit 0fca9c6 into narwhals-migration Aug 30, 2026
3 of 10 checks passed
@solegalli
solegalli deleted the narwhals-numerical-base-adapt-check-x branch August 30, 2026 14:55
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