8000 TST test_fit_docstring_attributes include properties (#20190) · scikit-learn/scikit-learn@b15e312 · GitHub
[go: up one dir, main page]

Skip to content

Commit b15e312

Browse files
authored
TST test_fit_docstring_attributes include properties (#20190)
1 parent 673625b commit b15e312

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

sklearn/cluster/_bicluster.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ class SpectralCoclustering(BaseSpectral):
255255
column_labels_ : array-like of shape (n_cols,)
256256
The bicluster label of each column.
257257
258+
biclusters_ : tuple of two ndarrays
259+
The tuple contains the `rows_` and `columns_` arrays.
260+
258261
Examples
259262
--------
260263
>>> from sklearn.cluster import SpectralCoclustering

sklearn/model_selection/_search.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,10 @@ class GridSearchCV(BaseSearchCV):
11771177
multimetric_ : bool
11781178
Whether or not the scorers compute several metrics.
11791179
1180+
classes_ : ndarray of shape (n_classes,)
1181+
The classes labels. This is present only if ``refit`` is specified and
1182+
the underlying estimator is a classifier.
1183+
11801184
Notes
11811185
-----
11821186
The parameters selected are those that maximize the score of the left out
@@ -1499,6 +1503,10 @@ class RandomizedSearchCV(BaseSearchCV):
14991503
multimetric_ : bool
15001504
Whether or not the scorers compute several metrics.
15011505
1506+
classes_ : ndarray of shape (n_classes,)
1507+
The classes labels. This is present only if ``refit`` is specified and
1508+
the underlying estimator is a classifier.
1509+
15021510
Notes
15031511
-----
15041512
The parameters selected are those that maximize the score of the held-out

sklearn/tests/test_docstring_parameters.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def test_fit_docstring_attributes(name, Estimator):
224224
'StackingRegressor', 'TfidfVectorizer', 'VotingClassifier',
225225
'VotingRegressor', 'SequentialFeatureSelector',
226226
'HalvingGridSearchCV', 'HalvingRandomSearchCV'}
227+
8000
227228
if Estimator.__name__ in IGNORED or Estimator.__name__.startswith('_'):
228229
pytest.skip("Estimator cannot be fit easily to test fit attributes")
229230

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

287-
fit_attr = [k for k in est.__dict__.keys() if k.endswith('_')
288-
and not k.startswith('_')]
288+
fit_attr = _get_all_fitted_attributes(est)
289289
fit_attr_names = [attr.name for attr in attributes]
290290
undocumented_attrs = set(fit_attr).difference(fit_attr_names)
291291
undocumented_attrs = set(undocumented_attrs).difference(skipped_attributes)
292292
assert not undocumented_attrs,\
293293
"Undocumented attributes: {}".format(undocumented_attrs)
294+
295+
296+
def _get_all_fitted_attributes(estimator):
297+
"Get all the fitted attributes of an estimator including properties"
298+
# attributes
299+
fit_attr = list(estimator.__dict__.keys())
300+
301+
# properties
302+
with warnings.catch_warnings():
303+
warnings.filterwarnings("error", category=FutureWarning)
304+
305+
for name in dir(estimator.__class__):
306+
obj = getattr(estimator.__class__, name)
307+
if not isinstance(obj, property):
308+
continue
309+
310+
# ignore properties that raises an AttributeError and deprecated
311+
# properties
312+
try:
313+
getattr(estimator, name)
314+
except (AttributeError, FutureWarning):
315+
continue
316+
fit_attr.append(name)
317+
318+
return [k for k in fit_attr if k.endswith('_') and not k.startswith('_')]

0 commit comments

Comments
 (0)
0