Skip to content

Commit d4306ba

Browse files
authored
DOC Improve docstring around set_output (#24672)
* DOC Improve docstring around set_output * DOC Improve docs around set_output * DOC Address comments * DOC Better grammar * DOC Improve wording * DOC Improves docstring in set_config
1 parent 98a3fdf commit d4306ba

File tree

7 files changed

+43
-16
lines changed

7 files changed

+43
-16
lines changed

doc/developers/develop.rst

+3
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,9 @@ setting `auto_wrap_output_keys=None` when defining a custom subclass::
659659
def get_feature_names_out(self, input_features=None):
660660
...
661661

662+
The default value for `auto_wrap_output_keys` is `("transform",)`, which automatically
663+
wraps `fit_transform` and `transform`.
664+
662665
For transformers that return multiple arrays in `transform`, auto wrapping will
663666
only wrap the first array and not alter the other arrays.
664667

sklearn/_config.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ def set_config(
123123
.. versionadded:: 1.2
124124
125125
transform_output : str, default=None
126-
Configure the output container for transform.
126+
Configure output of `transform` and `fit_transform`.
127+
128+
See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py`
129+
for an example on how to use the API.
130+
131+
- `"default"`: Default output format of a transformer
132+
- `"pandas"`: DataFrame output
133+
- `None`: Transform configuration is unchanged
127134
128135
.. versionadded:: 1.2
129136
@@ -231,7 +238,14 @@ def config_context(
231238
.. versionadded:: 1.2
232239
233240
transform_output : str, default=None
234-
Configure the output container for transform.
241+
Configure output of `transform` and `fit_transform`.
242+
243+
See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py`
244+
for an example on how to use the API.
245+
246+
- `"default"`: Default output format of a transformer
247+
- `"pandas"`: DataFrame output
248+
- `None`: Transform configuration is unchanged
235249
236250
.. versionadded:: 1.2
237251

sklearn/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,9 @@ def get_submatrix(self, i, data):
808808
class TransformerMixin(_SetOutputMixin):
809809
"""Mixin class for all transformers in scikit-learn.
810810
811-
If :term:`get_feature_names_out` is defined and `auto_wrap_output` is True,
812-
then `BaseEstimator` will automatically wrap `transform` and `fit_transform` to
813-
follow the `set_output` API. See the :ref:`developer_api_set_output` for details.
811+
If :term:`get_feature_names_out` is defined, then `BaseEstimator` will
812+
automatically wrap `transform` and `fit_transform` to follow the `set_output`
813+
API. See the :ref:`developer_api_set_output` for details.
814814
"""
815815

816816
def fit_transform(self, X, y=None, **fit_params):

sklearn/compose/_column_transformer.py

+4
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ def set_output(self, transform=None):
265265
transform : {"default", "pandas"}, default=None
266266
Configure output of `transform` and `fit_transform`.
267267
268+
- `"default"`: Default output format of a transformer
269+
- `"pandas"`: DataFrame output
270+
- `None`: Transform configuration is unchanged
271+
268272
Returns
269273
-------
270274
self : estimator instance

sklearn/pipeline.py

+8
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ def set_output(self, transform=None):
158158
transform : {"default", "pandas"}, default=None
159159
Configure output of `transform` and `fit_transform`.
160160
161+
- `"default"`: Default output format of a transformer
162+
- `"pandas"`: DataFrame output
163+
- `None`: Transform configuration is unchanged
164+
161165
Returns
162166
-------
163167
self : estimator instance
@@ -999,6 +1003,10 @@ def set_output(self, transform=None):
9991003
transform : {"default", "pandas"}, default=None
10001004
Configure output of `transform` and `fit_transform`.
10011005
1006+
- `"default"`: Default output format of a transformer
1007+
- `"pandas"`: DataFrame output
1008+
- `None`: Transform configuration is unchanged
1009+
10021010
Returns
10031011
-------
10041012
self : estimator instance

sklearn/preprocessing/_function_transformer.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,11 @@ def set_output(self, *, transform=None):
316316
Parameters
317317
----------
318318
transform : {"default", "pandas"}, default=None
319-
Configure output of the following estimator's methods:
319+
Configure output of `transform` and `fit_transform`.
320320
321-
- `"transform"`
322-
- `"fit_transform"`
323-
324-
If `None`, this operation is a no-op.
321+
- `"default"`: Default output format of a transformer
322+
- `"pandas"`: DataFrame output
323+
- `None`: Transform configuration is unchanged
325324
326325
Returns
327326
-------

sklearn/utils/_set_output.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class _SetOutputMixin:
167167
it based on `set_output` of the global configuration.
168168
169169
`set_output` is only defined if `get_feature_names_out` is defined and
170-
`auto_wrap_output` is True.
170+
`auto_wrap_output_keys` is the default value.
171171
"""
172172

173173
def __init_subclass__(cls, auto_wrap_output_keys=("transform",), **kwargs):
@@ -206,12 +206,11 @@ def set_output(self, *, transform=None):
206206
Parameters
207207
----------
208208
transform : {"default", "pandas"}, default=None
209-
Configure output of the following estimator's methods:
209+
Configure output of `transform` and `fit_transform`.
210210
211-
- `"transform"`
212-
- `"fit_transform"`
213-
214-
If `None`, this operation is a no-op.
211+
- `"default"`: Default output format of a transformer
212+
- `"pandas"`: DataFrame output
213+
- `None`: Transform configuration is unchanged
215214
216215
Returns
217216
-------

0 commit comments

Comments
 (0)