Fix regressor fit crash when sklearn transform_output is "pandas"#59
Open
fus3r wants to merge 1 commit into
Open
Fix regressor fit crash when sklearn transform_output is "pandas"#59fus3r wants to merge 1 commit into
fus3r wants to merge 1 commit into
Conversation
If a user sets sklearn's global output config to pandas, the regressor's internal StandardScaler returns a DataFrame from fit_transform, and the next line calls .flatten() on it, which only ndarrays have. That raised AttributeError: 'DataFrame' object has no attribute 'flatten' (issue google-research#58). Pin the target scaler to ndarray output with set_output(transform= "default") so it ignores the user's global config. The classifier and predict are unaffected. Adds a regression test.
fus3r
requested review from
abhidas,
erzel,
rajatsen91,
siriuz42,
tamannarayan and
weihaokong
as code owners
July 7, 2026 19:18
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.
Why
TabFMRegressor.fitcrashes for any user whose sklearn output config is set topandas globally:
The target
StandardScaleris an internal transformer. Undertransform_output="pandas"itsfit_transformreturns a DataFrame, and thenext line calls
.flatten()on it, which only exists on ndarrays. That isissue #58 (the reporter's traceback shows the matching FunctionTransformer
"pandas" warning, so the config was active in their environment).
The classifier is not affected (it does not scale the target).
predictis notaffected either:
inverse_transformoutput is not controlled by that config.What
Pin the internal target scaler to ndarray output with
set_output(transform="default"), so the regressor ignores the user's globalconfig for its own internal transformer. This is the standard way for a library
to keep ndarray output when it consumes transformer results directly.
Added a regression test that fits the regressor inside a
transform_output="pandas"context and checks it does not crash.