Skip to content

Fix regressor fit crash when sklearn output is globally set to pandas#72

Closed
devYRPauli wants to merge 1 commit into
google-research:mainfrom
devYRPauli:fix/sklearn-pandas-transform-output
Closed

Fix regressor fit crash when sklearn output is globally set to pandas#72
devYRPauli wants to merge 1 commit into
google-research:mainfrom
devYRPauli:fix/sklearn-pandas-transform-output

Conversation

@devYRPauli

Copy link
Copy Markdown
Contributor

Problem

TabFMRegressor.fit scales the regression target with a StandardScaler and then calls .flatten() on the transformed result. When a user has sklearn.set_config(transform_output="pandas") set globally (common in analysis notebooks), fit_transform returns a pandas DataFrame, which has no .flatten() method, so fitting fails with:

AttributeError: 'DataFrame' object has no attribute 'flatten'

This is issue #58 (regression example not working).

Fix

Pin the target scaler to numpy output via set_output(transform="default"), so target scaling is unaffected by the user's global sklearn output configuration.

Note: only this site needs the change. The classifier's CategoricalOrdinalEncoder path is not affected (that encoder is never wrapped to pandas output), and inverse_transform calls are never wrapped either, so no other sites required a fix.

Testing

  • Reproduced the AttributeError on the regressor fit path with transform_output="pandas" before the change, and confirmed fit completes cleanly after it.
  • The non-JAX unit tests in classifier_and_regressor_test pass locally.

TabFMRegressor.fit scales the target with a StandardScaler and calls .flatten() on the result. When the user has set sklearn.set_config(transform_output="pandas") globally, fit_transform returns a DataFrame, which has no .flatten(), raising AttributeError (issue google-research#58).

Pin the target scaler to numpy output with set_output(transform="default") so target scaling is unaffected by the global config.
@fus3r

fus3r commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Hi, I think this may overlap with #59. That PR also includes a regression test for the global pandas output configuration, which may be useful here.

@devYRPauli

Copy link
Copy Markdown
Contributor Author

Thanks for pointing that out, and apologies for the duplicate - I should have checked the open PR list against #58 before sending this.

You are right that #59 covers this: same fix in the same place (pinning the y scaler with set_output(transform="default") before fit_transform().flatten()), and it also carries the regression test under sklearn.config_context(transform_output="pandas"), which mine does not. Yours is both earlier and more complete, so there is nothing here worth a second review.

Closing this in favor of #59.

@devYRPauli devYRPauli closed this Jul 19, 2026
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.

2 participants