DatetimeSubtraction reports dropped reference columns and breaks pandas output
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- Mezza giornata
- Idoneità per principianti
- 22/100
Direzione di ricerca
Start with transform in feature_engine/datetime/datetime_subtraction.py, which drops the union of variables_ and reference_, and with _add_new_feature_names in feature_engine/base_transformers/mixins.py, which filters only variables. Reproduce with the snippet in the issue, then check that get_feature_names_out() matches the transform output. Done means both return only end_sub_start and set_output(transform="pandas") works. Tests live in tests/test_datetime/test_datetime_subtraction.py. Open PR #1120 already targets this, so review it before starting.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
With drop_original=True, DatetimeSubtraction correctly removes both operands from the transformed dataframe, but get_feature_names_out() still includes reference columns that are not also in variables. Consequently, the supported set_output(transform="pandas") path raises a column-length mismatch instead of returning the elapsed-time features.
To reproduce
Run against current main, commit d866312874a66364c6dee3c247e69476b478395c:
import pandas as pd
from feature_engine.datetime import DatetimeSubtraction
X = pd.DataFrame({"end": ["2026-01-02"], "start": ["2026-01-01"]})
transformer = DatetimeSubtraction(
variables=["end"], reference=["start"], drop_original=True
)
result = transformer.fit_transform(X)
print("columns:", result.columns.tolist())
print("names:", transformer.get_feature_names_out())
print("values:", result.to_numpy().tolist())
transformer.set_output(transform="pandas").transform(X)
Output:
columns: ['end_sub_start']
names: ['start', 'end_sub_start']
values: [[1.0]]
The final line raises:
ValueError: Length mismatch: Expected axis has 1 elements, new values have 2 elements
Expected behavior
Both the output columns and get_feature_names_out() should be ['end_sub_start']. Enabling pandas output should return the same one-column dataframe containing 1.0.
Environment
macOS, Python 3.13.16, pandas 3.0.6, NumPy 2.5.3, SciPy 1.18.1 and scikit-learn 1.9.1; Feature-engine imported from the unchanged commit above. This investigation and report were prepared autonomously with AI assistance; no independent human review is claimed.
Additional context
DatetimeSubtraction.transform drops the union of variables_ and reference_. The inherited _add_new_feature_names filters only variables_.
All 83 existing tests in tests/test_datetime/test_datetime_subtraction.py pass. A separate 40-case regression matrix gives 12 failures: six feature-name mismatches and six pandas-output exceptions. These cover distinct/partly overlapping single or multiple references and default/custom output names. The 28 controls pass, including drop_original=False, references contained in variables, and automatic selection. The checks also compare values, nondefault indices, unrelated columns and input preservation.
The active narwhals migration was inspected, not executed: its mixin still filters only variables_; the open column-order fix #1068 does not change this dropped-reference behavior. No library code was changed, and no full-suite, Polars or other-platform validation is claimed.
- Lingua principale
- Python
- Stelle
- 2.3k
- Fork
- 391
- Merge medio
- 11h 34m
- PR unite (30g)
- 11
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di feature-engine/feature_engine
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
feature-engine/feature_engine#1141 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
feature-engine/feature_engine#393 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
feature-engine/feature_engine#1140 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
CategoricalImputer fails when fill_value is already a categoryForse già presa @AryanRG l’ha presa 13 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 18/100
feature-engine/feature_engine#1113 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
OneHotEncoder loses a dummy name when it matches an encoded input columnForse già presa @Aadrit555 l’ha presa 7 giorni fa. Aperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 25/100
feature-engine/feature_engine#1106 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di feature-engine/feature_engine
Issue simili
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount dueForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 79/100
developmentseed/titiler-covjson#164 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
awslabs/visual-asset-management-system#2164 ·
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
MakazhanAlpamys/Soup#3589 ·
I maintainer di solito rispondono entro 1 giorno
-
channels status reports the wrong Enabled value for Feishu instances and default-enabled WebSocketAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno