Skip to content

Conversation

@adrinjalali
Copy link
Member

Fixes #30237

This adds an explicit error when tags are missing which would result in failure of collecting tests. This gives an explicit error on why the collection fails.

@adrinjalali adrinjalali added the Developer API Third party developer API related label Nov 8, 2024
@adrinjalali adrinjalali added this to the 1.6 milestone Nov 8, 2024
@github-actions
Copy link

github-actions bot commented Nov 8, 2024

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 8caca2f. Link to the linter CI: here



def _yield_api_checks(estimator):
if not isinstance(estimator, BaseEstimator):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we made the decision to only really support estimators that inherit from BaseEstimator? If so, is it documented somewhere so third-party estimator developers can know.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, documented:

Out of all the methods that an estimator implements, ``fit`` is usually the one you
want to implement yourself. Other methods such as ``set_params``, ``get_params``, etc.
are implemented in :class:`~sklearn.base.BaseEstimator`, which you should inherit from.
You might need to inherit from more mixins, which we will explain later.

And the example:

>>> import numpy as np
>>> from sklearn.base import BaseEstimator, ClassifierMixin
>>> from sklearn.utils.validation import validate_data, check_is_fitted
>>> from sklearn.utils.multiclass import unique_labels
>>> from sklearn.metrics import euclidean_distances
>>> class TemplateClassifier(ClassifierMixin, BaseEstimator):
...
... def __init__(self, demo_param='demo'):
... self.demo_param = demo_param
...
... def fit(self, X, y):
...
... # Check that X and y have correct shape, set n_features_in_, etc.
... X, y = validate_data(self, X, y)
... # Store the classes seen during fit
... self.classes_ = unique_labels(y)
...
... self.X_ = X
... self.y_ = y
... # Return the classifier
... return self
...
... def predict(self, X):
...
... # Check if fit has been called
... check_is_fitted(self)
...
... # Input validation
... X = validate_data(self, X, reset=False)
...
... closest = np.argmin(euclidean_distances(X, self.X_), axis=1)
... return self.y_[closest]

yield sparse_format + "_64", X


@ignore_warnings(category=FutureWarning)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other reviewers, this is just shifting the original test down.

@glemaitre glemaitre merged commit 3ec4457 into scikit-learn:main Nov 12, 2024
33 of 34 checks passed
@adrinjalali adrinjalali deleted the tests/tags branch November 12, 2024 16:24
jeremiedbb pushed a commit to glemaitre/scikit-learn that referenced this pull request Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

BUG: Test collection for Transformer fails

3 participants