Commit 973bd70
committed
Fix issue DistrictDataLabs#1328: update ContribEstimator wrapper to work 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.1 parent e156692 commit 973bd70
1 file changed
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
123 | 126 | | |
124 | 127 | | |
125 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
126 | 136 | | |
127 | 137 | | |
128 | 138 | | |
| |||
0 commit comments