Skip to content

Fix regressor fit crash when sklearn transform_output is "pandas"#59

Open
fus3r wants to merge 1 commit into
google-research:mainfrom
fus3r:fix-regressor-pandas-output
Open

Fix regressor fit crash when sklearn transform_output is "pandas"#59
fus3r wants to merge 1 commit into
google-research:mainfrom
fus3r:fix-regressor-pandas-output

Conversation

@fus3r

@fus3r fus3r commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Why

TabFMRegressor.fit crashes for any user whose sklearn output config is set to
pandas globally:

import sklearn
sklearn.set_config(transform_output="pandas")
reg.fit(X_train, y_train)
# AttributeError: 'DataFrame' object has no attribute 'flatten'

The target StandardScaler is an internal transformer. Under
transform_output="pandas" its fit_transform returns a DataFrame, and the
next line calls .flatten() on it, which only exists on ndarrays. That is
issue #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). predict is not
affected either: inverse_transform output 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 global
config 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.

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.
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