Skip to content

FIX get_feature_names_out drops reference columns when drop_original=… - #1120

Open
RugvedBane wants to merge 1 commit into
feature-engine:narwhals-migrationfrom
RugvedBane:fix/issue_1103
Open

RugvedBane wants to merge 1 commit into
feature-engine:narwhals-migrationfrom
RugvedBane:fix/issue_1103

Conversation

@RugvedBane

@RugvedBane RugvedBane commented Nov 10, 2026 •

Copy link
Copy Markdown

Fixes #1103

When drop_original=True, transform() drops both variables and reference
columns, but get_feature_names_out() only dropped variables.

Fix: DatetimeSubtraction and RelativeFeatures now override
_add_new_feature_names to drop the same columns as their transform().
The shared mixin is unchanged.

Tests: added a reference-not-in-variables case to the existing
test_get_feature_names_out in both files (pandas and polars via make_df),
plus set_output tests for pandas and polars.

@RugvedBane

Copy link
Copy Markdown
Author

Hi @solegalli, please take a look at this PR when you get a chance. Thanks!

@solegalli

Copy link
Copy Markdown
Collaborator

Hi @RugvedBane, thanks for the PR and for the clear write-up, and apologies for the delayed response.

The fix is in the right place: _add_new_feature_names should drop the same columns that transform() drops, and both DatetimeSubtraction and RelativeFeatures drop the reference columns too. A few things before we can merge:

Target the narwhals-migration branch. The source code and the tests have changed a lot on the narwhals-migration branch, which is where we are doing all development now. Could you rebase your branch onto it and change the base of this PR to narwhals-migration? The mixin looks the same there, so the rebase should mostly affect the tests.

Simplify the mixin change.

  • The if self.drop_original is True and self.variables_ is not None: condition appears twice, one nested inside the other. The inner one can go.
  • The getattr(self, "reference_", None) or getattr(self, "reference", None) chain exists because the two transformers name the attribute differently. Instead of handling that in the shared mixin, I'd rather each of the two transformers override _add_new_feature_names and drop the same set their own transform() drops. OneHotEncoder, Winsorizer, AddMissingIndicator and StringSimilarityEncoder already override it that way, so there is a pattern to follow, and the mixin stays untouched.

Tests. On the migration branch every test in these files runs on both pandas and polars through the make_df parametrization, so the new get_feature_names_out() checks should do the same. Rather than adding new functions, please add a case with a reference column that is not in variables to the existing test_get_feature_names_out in each file; that is exactly the case those tests are missing today. The set_output tests can stay single-backend, but a transform="polars" counterpart would be good to have too.

Thanks again!

@RugvedBane
RugvedBane changed the base branch from main to narwhals-migration November 26, 2026 13:52
@RugvedBane

RugvedBane commented Nov 26, 2026 •

Copy link
Copy Markdown
Author

Hi @solegalli, thanks for the review. I rebased onto narwhals-migration, reverted the mixin change, moved the fix into per transformer overrides of _add_new_feature_names, and extended the existing tests as suggested (including a polars set_output test)

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.

DatetimeSubtraction reports dropped reference columns and breaks pandas output

2 participants