Skip to content

Fix #1328: Update ContribEstimator wrapper to work with sklearn 1.6+ tags API#1333

Open
edschofield wants to merge 2 commits intoDistrictDataLabs:developfrom
PythonCharmers:fix-1328
Open

Fix #1328: Update ContribEstimator wrapper to work with sklearn 1.6+ tags API#1333
edschofield wants to merge 2 commits intoDistrictDataLabs:developfrom
PythonCharmers:fix-1328

Conversation

@edschofield
Copy link
Copy Markdown

@edschofield edschofield commented Mar 7, 2026

Starting in scikit-learn 1.6, the type-checking functions is_classifier(), is_regressor(),etc. were changed to use a new tags-based mechanism. Yellowbrick's ContribEstimator did not implement __sklearn_tags__(),so when sklearn called it, the call fell through to ContribEstimator.getattr(). Since third-party estimators (the whole reason ContribEstimator exists) typically don't implement sklearn_tags() either, this raised an AttributeError, causing all four type checks to fail.

This fix adds a __sklearn_tags__() method to ContribEstimator that builds a default Tags object (via BaseEstimator) and replaces the estimator_type field with the value from self._estimator_type when set. This preserves the existing behavior where wrap(est, "classifier") makes the estimator pass is_classifier() checks, while remaining forward-compatible with sklearn's tags infrastructure.

After applying this fix, the tests that @jakevdp reported in #1328 to be failing now pass.

$ pytest . -k test_wrapper --tb=short

...
tests/test_contrib/test_wrapper.py::Third party ContribEstimator wrapper::Check that the contrib wrapper passes through correctly PASSED [  5%]
tests/test_contrib/test_wrapper.py::Third party ContribEstimator wrapper::Assert a correct exception is raised on failed access PASSED [ 10%]
...
tests/test_utils/test_wrapper.py::Test the object Wrapper mixin utility::Ensure wrapper recursion isn't possible PASSED [ 94%]
tests/test_utils/test_wrapper.py::Test the object Wrapper mixin utility::Attribute errors should return a YellowbrickAttributeError PASSED [100%]

…gressor(), is_clusterer() do not work with sklearn 1.8
…ork with sklearn 1.6+ tags API

Starting in scikit-learn 1.6, the type-checking functions is_classifier(),
is_regressor(), is_clusterer(), and is_outlier_detector() were changed to
use a new tags-based mechanism. Instead of inspecting the _estimator_type
attribute directly, they now call get_tags(estimator), which in turn
invokes estimator.__sklearn_tags__() and checks the estimator_type field
on the returned Tags dataclass.

ContribEstimator did not implement __sklearn_tags__(), so when sklearn
called it, the call fell through to ContribEstimator.__getattr__(), which
proxied it to the wrapped third-party estimator. Since third-party
estimators (the whole reason ContribEstimator exists) typically don't
implement __sklearn_tags__() either, this raised an AttributeError,
causing all four type checks to fail.

The fix adds a __sklearn_tags__() method to ContribEstimator that builds
a default Tags object (via BaseEstimator) and replaces the estimator_type
field with the value from self._estimator_type when set. This preserves
the existing behavior where wrap(est, "classifier") makes the estimator
pass is_classifier() checks, while remaining forward-compatible with
sklearn's tags infrastructure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant