fix: DatetimeFeaturesAdder one-hot columns unstable and inconsistent with features_added()#980
Merged
egordm merged 6 commits intoJun 25, 2026
Conversation
… features_added() With onehot_encode=True, transform() built month/quarter dummies only for the values present in the data, so the column set was data-dependent (training and inference could differ). features_added() also returned the non-one-hot names (month_of_year/quarter_of_year), which the one-hot branch never produces, while omitting the actual month_N/quarter_N columns. Build the dummies from a fixed category set (all 12 months, 4 quarters) so the one-hot columns are stable, and branch features_added() on onehot_encode so it reports exactly the columns transform() adds. Add regression tests for both branches. Signed-off-by: RAJVEER42 <irajveer.bishnoi2310@gmail.com>
lschilders
requested changes
Jun 22, 2026
lschilders
left a comment
Collaborator
There was a problem hiding this comment.
The comments in the method and the docstring in the test are way too verbose. Only add such comments when absolutely necessary. Fix and logic look good.
Address @lschilders review on OpenSTEF#980. Signed-off-by: RAJVEER42 <irajveer.bishnoi2310@gmail.com>
Contributor
Author
|
Done, trimmed the comment in the one-hot branch and the test docstring. Thanks for the review! |
Contributor
Author
|
@lschilders, any suggestion on the changes? |
egordm
approved these changes
Jun 25, 2026
egordm
left a comment
Collaborator
There was a problem hiding this comment.
Looks great! Good fix. We indeed want the full category values not just the ones available in data.
Thanks for your contribution!
lschilders
approved these changes
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
With
onehot_encode=True,DatetimeFeaturesAdderhad two related problems:transform()built the month/quarter dummies withpd.get_dummies(data.index.month, ...), which only emits columns for the values present in the data. So the column set was data-dependent: training spanning Jan-Mar producedmonth_1..3, while inference in Apr producedmonth_4. Training and inference could therefore yield different feature columns.features_added()always returned the non-one-hot names (month_of_year,quarter_of_year), which the one-hot branch never produces, while omitting the actualmonth_N/quarter_Ncolumns.Fix
pd.Categorical(..., categories=1..12 / 1..4)) so the one-hot columns are always the full, stable set regardless of the data span.features_added()ononehot_encodeso it reports exactly the columnstransform()adds.Tests
Added regression tests asserting
set(features_added()) == set(added columns)for both branches, and that the one-hot columns are the full stable set even when the data spans only two months (the one-hot test fails on the previous code, passes with the fix). The existing one-hot test still passes.ty check,ruff check,ruff format --check, the module doctest, and the fullopenstef-modelssuite all pass.Note
This makes one-hot output always span all 12 months / 4 quarters. I believe that's the desired behaviour (a stable feature space across train/inference), but flagging it in case you'd prefer to keep it data-dependent.