fix(temporal): emit feature names in the order transform produces - #27
Open
ChrisW09 wants to merge 1 commit into
Open
fix(temporal): emit feature names in the order transform produces#27ChrisW09 wants to merge 1 commit into
ChrisW09 wants to merge 1 commit into
Conversation
All three temporal transformers hstack one ``(n_rows, n_features)`` block per
lag / statistic / component, so their columns are block-major. They inherited
``BasePreTabTransformer.get_feature_names_out``, which walks
``zip(input_features, self._output_sizes())`` and therefore emits feature-major
names. For any input with more than one column the two disagreed:
Lag names : ['A_lag0', 'A_lag1', 'B_lag0', 'B_lag1']
Lag row 0 : [1., 100., 0., 0.] # col 1 is B's lag-1, labelled A_lag1
Override ``get_feature_names_out`` in each class to iterate blocks outermost.
The existing ``lag{j}`` / ``roll{j}`` / ``cyclic{j}`` suffix scheme is kept
deliberately, so single-feature output is byte-identical and no existing test
changes. The issue also suggested naming the columns after the statistic and
after sin/cos, which is more informative but changes public output names for
users whose labels are correct today; that is left as a separate change.
Closes #15
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Fixes #15.
Problem
LagFeatureTransformer,RollingStatsTransformerandCyclicalTimeTransformerall buildtheir output by hstacking one
(n_rows, n_features)block per lag / statistic / component,so the columns are block-major. But they inherit
BasePreTabTransformer.get_feature_names_out, which walkszip(input_features, self._output_sizes())and emits feature-major names.For any input with more than one column, the labels are simply wrong:
Single-column input happens to be correct, which is why the existing tests pass.
Fix
Override
get_feature_names_outin each of the three classes to iterate blocks outermost,matching the actual column layout.
Scope note
I kept the existing
lag{j}/roll{j}/cyclic{j}suffix scheme rather than renaming to_mean/_sin/_cos. The issue suggested that rename as a bonus and it is genuinelymore informative — but it changes public output names for single-feature users whose labels
are correct today, which is a different kind of change from fixing a mislabelling. Keeping
the suffixes means:
['t_lag0', 't_lag1']before and after);that encode the current scheme — a good signal it belongs in its own PR.
Happy to follow up with the rename if you want it.
Result
Tests
Five added to
tests/test_temporal.py, using a two-column fixture whereB = 100 * Asoevery column is identifiable from its value alone:
None) names still work for single-feature inputlen(get_feature_names_out()) == transform(X).shape[1]Full suite: 487 passed, 9 xfailed, no existing test modified.
ruff checkclean on changedfiles; pyright unchanged at its pre-existing 71 errors.
🤖 Generated with Claude Code