Skip to content

TST test_fit_docstring_attributes include properties #20190

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sklearn/cluster/_bicluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ class SpectralCoclustering(BaseSpectral):
column_labels_ : array-like of shape (n_cols,)
The bicluster label of each column.

biclusters_ : tuple of two ndarrays
The tuple contains the `rows_` and `columns_` arrays.

Examples
--------
>>> from sklearn.cluster import SpectralCoclustering
Expand Down
8 changes: 8 additions & 0 deletions sklearn/model_selection/_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,10 @@ class GridSearchCV(BaseSearchCV):
multimetric_ : bool
Whether or not the scorers compute several metrics.

classes_ : ndarray of shape (n_classes,)
The classes labels. This is present only if ``refit`` is specified and
the underlying estimator is a classifier.

Notes
-----
The parameters selected are those that maximize the score of the left out
Expand Down Expand Up @@ -1499,6 +1503,10 @@ class RandomizedSearchCV(BaseSearchCV):
multimetric_ : bool
Whether or not the scorers compute several metrics.

classes_ : ndarray of shape (n_classes,)
The classes labels. This is present only if ``refit`` is specified and
the underlying estimator is a classifier.

Notes
-----
The parameters selected are those that maximize the score of the held-out
Expand Down
29 changes: 27 additions & 2 deletions sklearn/tests/test_docstring_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def test_fit_docstring_attributes(name, Estimator):
'StackingRegressor', 'TfidfVectorizer', 'VotingClassifier',
'VotingRegressor', 'SequentialFeatureSelector',
'HalvingGridSearchCV', 'HalvingRandomSearchCV'}

if Estimator.__name__ in IGNORED or Estimator.__name__.startswith('_'):
pytest.skip("Estimator cannot be fit easily to test fit attributes")

Expand Down Expand Up @@ -284,10 +285,34 @@ def test_fit_docstring_attributes(name, Estimator):
with ignore_warnings(category=FutureWarning):
assert hasattr(est, attr.name)

fit_attr = [k for k in est.__dict__.keys() if k.endswith('_')
and not k.startswith('_')]
fit_attr = _get_all_fitted_attributes(est)
fit_attr_names = [attr.name for attr in attributes]
undocumented_attrs = set(fit_attr).difference(fit_attr_names)
undocumented_attrs = set(undocumented_attrs).difference(skipped_attributes)
assert not undocumented_attrs,\
"Undocumented attributes: {}".format(undocumented_attrs)


def _get_all_fitted_attributes(estimator):
"Get all the fitted attributes of an estimator including properties"
# attributes
fit_attr = list(estimator.__dict__.keys())

# properties
with warnings.catch_warnings():
warnings.filterwarnings("error", category=FutureWarning)

for name in dir(estimator.__class__):
obj = getattr(estimator.__class__, name)
if not isinstance(obj, property):
continue

# ignore properties that raises an AttributeError and deprecated
# properties
try:
getattr(estimator, name)
except (AttributeError, FutureWarning):
continue
fit_attr.append(name)

return [k for k in fit_attr if k.endswith('_') and not k.startswith('_')]