Skip to content

datetime: propagate NaN for week and days_in_month with missing_values=ignore - #1017

Open
AlejandroCoronadoN wants to merge 1 commit into
feature-engine:mainfrom
AlejandroCoronadoN:fix-datetime-ignore-nan-week-days
Open

datetime: propagate NaN for week and days_in_month with missing_values=ignore#1017
AlejandroCoronadoN wants to merge 1 commit into
feature-engine:mainfrom
AlejandroCoronadoN:fix-datetime-ignore-nan-week-days

Conversation

@AlejandroCoronadoN

Copy link
Copy Markdown

When missing_values="ignore", DatetimeFeatures.transform() raises for the week and days_in_month features if the input has a missing date. Both cast to np.int64, which fails on the NaT-derived NA:

IntCastingNaNError: Cannot convert non-finite values (NA or inf) to integer

The other datetime features (month, year, day_of_month, ...) do not force an int cast and correctly return NaN for the missing row, so only these two were affected.

Repro:

import pandas as pd
from feature_engine.datetime import DatetimeFeatures

X = pd.DataFrame({"date": pd.to_datetime(["2022-01-01", None, "2022-03-01"])})
DatetimeFeatures(features_to_extract=["days_in_month"],
                 missing_values="ignore").fit(X).transform(X)

This casts both to float64 instead, so the missing row becomes NaN like the other features. Added a test covering week and days_in_month with missing_values="ignore".

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