[BUG] Fix ColumnwiseTransformer to work with sklearn transformers using TabularToSeriesAdaptor #9132
+23
−4
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.
Reference Issues/PRs
Fixes #9122 - ColumnwiseTransformer failed with sklearn transformers due to incompatible interfaces.
This PR implements the TabularToSeriesAdaptor pattern as suggested by mentor to seamlessly support both sklearn and sktime transformers.
What does this implement/fix? Explain your changes.
This PR fixes a bug where
ColumnwiseTransformercould not be instantiated with sklearn transformers likePowerTransformer.###📌Problem:
ColumnwiseTransformer failed when used with sklearn transformers like PowerTransformer:
Root Causes:
✨Solution (Mentor-Recommended Approach):
Implemented the TabularToSeriesAdaptor pattern with the following key changes:
1. Centralized sklearn/sktime handling in init:_
Changes:
ColumnwiseTransformer.__init__to check forget_tagmethod before cloning tags📌 I'm using self.transformer here because:
- clone_tags() expects a sktime transformer with get_tag() method
- self._transformer is guaranteed to have this method
- self.transformer might be sklearn (no get_tag() method)_
Summary
2. Use internal transformer throughout:
Files Changed:
sktime/transformations/compose/_column.py
- Added TabularToSeriesAdaptor import
- Modified init with conditional wrapping
- Updated methods to use self._transformer
- Enhanced get_test_params() with sklearn case
- Removed manual data conversion logic_
Mentor Feedback Implementation:
This PR implements the @fkiraly mentor's suggested approach:
✨Fixes -
Does your contribution introduce a new dependency? If yes, which one?
No. This fix uses existing functionality and doesn't introduce any new dependencies.
What should a reviewer concentrate their feedback on?
hasattr(transformer, 'get_tag')check is the appropriate way to distinguish transformer typesPowerTransformerDid you add any tests for the change?
No new tests were added. The fix is minimal and preserves existing behavior. The issue can be verified by running:
Any other comments?
This is a minimal, targeted fix that addresses the root cause while maintaining backward compatibility. The solution follows sktime's pattern of checking for interface compatibility before using sktime-specific functionality.
PR checklist
For all contributions
How to: add yourself to the all-contributors file in the
sktimeroot directory (not theCONTRIBUTORS.md). Common badges:code- fixing a bug, or adding code logic.doc- writing or improving documentation or docstrings.bug- reporting or diagnosing a bug (get this pluscodeif you also fixed the bug in the PR).maintenance- CI, test framework, release.See here for full badge reference
maintainerstag - do this if you want to become the owner or maintainer of an estimator you added.See here for further details on the algorithm maintainer role.
For new estimators
docs/source/api_reference/taskname.rst, follow the pattern.Examplessection.python_dependenciestag and ensureddependency isolation, see the estimator dependencies guide.