Skip to content

DOC Ensures that ColumnTransformer passes numpydoc validation #20836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 change: 0 additions & 1 deletion maint_tools/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"Birch",
"CalibratedClassifierCV",
"ClassifierChain",
"ColumnTransformer",
"DecisionTreeRegressor",
"DictVectorizer",
"DictionaryLearning",
Expand Down
47 changes: 22 additions & 25 deletions sklearn/compose/_column_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ class ColumnTransformer(TransformerMixin, _BaseComposition):

.. versionadded:: 0.24

See Also
--------
make_column_transformer : Convenience function for
combining the outputs of multiple transformer objects applied to
column subsets of the original feature space.
make_column_selector : Convenience function for selecting
columns based on datatype or the columns name with a regex pattern.

Notes
-----
The order of the columns in the transformed feature matrix follows the
Expand All @@ -156,14 +164,6 @@ class ColumnTransformer(TransformerMixin, _BaseComposition):
in the `passthrough` keyword. Those columns specified with `passthrough`
are added at the right to the output of the transformers.

See Also
--------
make_column_transformer : Convenience function for
combining the outputs of multiple transformer objects applied to
column subsets of the original feature space.
make_column_selector : Convenience function for selecting
columns based on datatype or the columns name with a regex pattern.

Examples
--------
>>> import numpy as np
Expand All @@ -180,7 +180,6 @@ class ColumnTransformer(TransformerMixin, _BaseComposition):
>>> ct.fit_transform(X)
array([[0. , 1. , 0.5, 0.5],
[0.5, 0.5, 0. , 1. ]])

"""

_required_parameters = ["transformers"]
Expand Down Expand Up @@ -242,13 +241,17 @@ def get_params(self, deep=True):
def set_params(self, **kwargs):
"""Set the parameters of this estimator.

Valid parameter keys can be listed with ``get_params()``. Note that you
can directly set the parameters of the estimators contained in
`transformers` of `ColumnTransformer`.
Parameters
----------
**kwargs : dict
Valid parameter keys can be listed with ``get_params()``. Note that you
can directly set the parameters of the estimators contained in
`transformers` of `ColumnTransformer`.

Returns
-------
self
self : object
ColumnTransformer class instance.
"""
self._set_params("_transformers", **kwargs)
return self
Expand Down Expand Up @@ -364,7 +367,6 @@ def named_transformers_(self):
Read-only attribute to access any transformer by given name.
Keys are transformer names and values are the fitted transformer
objects.

"""
# Use Bunch object to improve autocomplete
return Bunch(**{name: trans for name, trans, _ in self.transformers_})
Expand Down Expand Up @@ -512,9 +514,8 @@ def fit(self, X, y=None):

Returns
-------
self : ColumnTransformer
This estimator

self : object
ColumnTransformer class instance.
"""
# we use fit_transform to make sure to set sparse_output_ (for which we
# need the transformed data) to have consistent output type in predict
Expand All @@ -535,13 +536,11 @@ def fit_transform(self, X, y=None):

Returns
-------
X_t : {array-like, sparse matrix} of \
shape (n_samples, sum_n_components)
hstack of results of transformers. sum_n_components is the
X_t : {array-like, sparse matrix} of shape (n_samples, sum_n_components)
The "_hstack" of results of transformers. The "sum_n_components" is the
sum of n_components (output dimension) over transformers. If
any result is a sparse matrix, everything will be converted to
sparse matrices.

"""
self._check_feature_names(X, reset=True)

Expand Down Expand Up @@ -588,13 +587,11 @@ def transform(self, X):

Returns
-------
X_t : {array-like, sparse matrix} of \
shape (n_samples, sum_n_components)
hstack of results of transformers. sum_n_components is the
X_t : {array-like, sparse matrix} of shape (n_samples, sum_n_components)
The _"hstack" of results of transformers. The "sum_n_components" is the
sum of n_components (output dimension) over transformers. If
any result is a sparse matrix, everything will be converted to
sparse matrices.

"""
check_is_fitted(self)
X = _check_X(X)
Expand Down