diff --git a/doc/developers/develop.rst b/doc/developers/develop.rst index 05f6ea26ac80e..ef55be3cdffca 100644 --- a/doc/developers/develop.rst +++ b/doc/developers/develop.rst @@ -659,6 +659,9 @@ setting `auto_wrap_output_keys=None` when defining a custom subclass:: def get_feature_names_out(self, input_features=None): ... +The default value for `auto_wrap_output_keys` is `("transform",)`, which automatically +wraps `fit_transform` and `transform`. + For transformers that return multiple arrays in `transform`, auto wrapping will only wrap the first array and not alter the other arrays. diff --git a/sklearn/_config.py b/sklearn/_config.py index ea5c47499b5b4..e4c398c9c5444 100644 --- a/sklearn/_config.py +++ b/sklearn/_config.py @@ -123,7 +123,14 @@ def set_config( .. versionadded:: 1.2 transform_output : str, default=None - Configure the output container for transform. + Configure output of `transform` and `fit_transform`. + + See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py` + for an example on how to use the API. + + - `"default"`: Default output format of a transformer + - `"pandas"`: DataFrame output + - `None`: Transform configuration is unchanged .. versionadded:: 1.2 @@ -231,7 +238,14 @@ def config_context( .. versionadded:: 1.2 transform_output : str, default=None - Configure the output container for transform. + Configure output of `transform` and `fit_transform`. + + See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py` + for an example on how to use the API. + + - `"default"`: Default output format of a transformer + - `"pandas"`: DataFrame output + - `None`: Transform configuration is unchanged .. versionadded:: 1.2 diff --git a/sklearn/base.py b/sklearn/base.py index 3ef2a908cdadf..d7d5d8f6644b5 100644 --- a/sklearn/base.py +++ b/sklearn/base.py @@ -808,9 +808,9 @@ def get_submatrix(self, i, data): class TransformerMixin(_SetOutputMixin): """Mixin class for all transformers in scikit-learn. - If :term:`get_feature_names_out` is defined and `auto_wrap_output` is True, - then `BaseEstimator` will automatically wrap `transform` and `fit_transform` to - follow the `set_output` API. See the :ref:`developer_api_set_output` for details. + If :term:`get_feature_names_out` is defined, then `BaseEstimator` will + automatically wrap `transform` and `fit_transform` to follow the `set_output` + API. See the :ref:`developer_api_set_output` for details. """ def fit_transform(self, X, y=None, **fit_params): diff --git a/sklearn/compose/_column_transformer.py b/sklearn/compose/_column_transformer.py index db7a7016c83ab..1fb81e69647c7 100644 --- a/sklearn/compose/_column_transformer.py +++ b/sklearn/compose/_column_transformer.py @@ -265,6 +265,10 @@ def set_output(self, transform=None): transform : {"default", "pandas"}, default=None Configure output of `transform` and `fit_transform`. + - `"default"`: Default output format of a transformer + - `"pandas"`: DataFrame output + - `None`: Transform configuration is unchanged + Returns ------- self : estimator instance diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py index 3f74acda1fc29..dff4d4c1cd147 100644 --- a/sklearn/pipeline.py +++ b/sklearn/pipeline.py @@ -158,6 +158,10 @@ def set_output(self, transform=None): transform : {"default", "pandas"}, default=None Configure output of `transform` and `fit_transform`. + - `"default"`: Default output format of a transformer + - `"pandas"`: DataFrame output + - `None`: Transform configuration is unchanged + Returns ------- self : estimator instance @@ -999,6 +1003,10 @@ def set_output(self, transform=None): transform : {"default", "pandas"}, default=None Configure output of `transform` and `fit_transform`. + - `"default"`: Default output format of a transformer + - `"pandas"`: DataFrame output + - `None`: Transform configuration is unchanged + Returns ------- self : estimator instance diff --git a/sklearn/preprocessing/_function_transformer.py b/sklearn/preprocessing/_function_transformer.py index 228304bb70091..d4c2cf6de7af2 100644 --- a/sklearn/preprocessing/_function_transformer.py +++ b/sklearn/preprocessing/_function_transformer.py @@ -316,12 +316,11 @@ def set_output(self, *, transform=None): Parameters ---------- transform : {"default", "pandas"}, default=None - Configure output of the following estimator's methods: + Configure output of `transform` and `fit_transform`. - - `"transform"` - - `"fit_transform"` - - If `None`, this operation is a no-op. + - `"default"`: Default output format of a transformer + - `"pandas"`: DataFrame output + - `None`: Transform configuration is unchanged Returns ------- diff --git a/sklearn/utils/_set_output.py b/sklearn/utils/_set_output.py index 525c6e0fe0118..5de296dc62d9b 100644 --- a/sklearn/utils/_set_output.py +++ b/sklearn/utils/_set_output.py @@ -167,7 +167,7 @@ class _SetOutputMixin: it based on `set_output` of the global configuration. `set_output` is only defined if `get_feature_names_out` is defined and - `auto_wrap_output` is True. + `auto_wrap_output_keys` is the default value. """ def __init_subclass__(cls, auto_wrap_output_keys=("transform",), **kwargs): @@ -206,12 +206,11 @@ def set_output(self, *, transform=None): Parameters ---------- transform : {"default", "pandas"}, default=None - Configure output of the following estimator's methods: + Configure output of `transform` and `fit_transform`. - - `"transform"` - - `"fit_transform"` - - If `None`, this operation is a no-op. + - `"default"`: Default output format of a transformer + - `"pandas"`: DataFrame output + - `None`: Transform configuration is unchanged Returns -------