Repository navigation
sklearn: Add HDBSCAN, Tree node-array properties, and precision_recall_curve drop_intermediate/y_score - #404
Open
John Clow (Gamrix) wants to merge 1 commit into
Open
John Clow (Gamrix) wants to merge 1 commit into
John Clow (Gamrix) wants to merge 1 commit into
Conversation
…l_curve drop_intermediate/y_score Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
@microsoft-github-policy-service agree company="Safetykit" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These are three gaps in
stubs/sklearnthat produce false type errors on current scikit-learn code. They affect Pylance users and also Pyrefly users, because Pyrefly bundles these stubs. I found them by running Pyrefly against a codebase on scikit-learn 1.9.0. Each signature below was checked against both 1.9.0 and the 1.6.1 runtime that CI's stubtest installs (scikit-learn <1.7.0).1.
sklearn.cluster.HDBSCANis missing (added in 1.3)from sklearn.cluster import HDBSCANfails because the stub doesn't export it.cluster/_hdbscan/__init__.pyiandcluster/_hdbscan/hdbscan.pyi, written in the style of_dbscan.pyiand_optics.pyi: constructor parameters,fit,fit_predict,dbscan_clustering, and the fitted attributeslabels_,probabilities_,centroids_,medoids_,n_features_in_andfeature_names_in_.HDBSCANfromcluster/__init__.pyi, including__all__.sklearn/cluster/_hdbscan/hdbscan.py#L423and__init__at L665.copyis typedbool = False. In 1.9 the runtime default is a hidden"warn"sentinel (Hidden(StrOptions({"warn"}))) that behaves likeFalseand raises a FutureWarning. In 1.6 the default is plainFalse, which stubtest checks.2.
sklearn.tree._tree.Treelacks its public node-array propertiesestimator.tree_.children_left,.feature,.thresholdand the other node arrays are the documented way to inspect a fitted tree, but none of them are in the stub.children_left,children_right,feature,threshold,impurity,n_node_samples,weighted_n_node_samples,missing_go_to_left(allndarray) andn_leaves(int, which matchesBaseDecisionTree.get_n_leaves() -> int). Source:sklearn/tree/_tree.pyx#L721-L761.max_dept: inttomax_depth: int(cdef public intp_t max_depth,_tree.pxd#L50).n_classesfromintto anndarrayproperty. At runtime it is a property that returns an array with one entry per output (_tree.pyx#L721-L723).3.
precision_recall_curvelacksdrop_intermediateandy_scoredrop_intermediate: bool = Falsewas added in 1.3.probas_predtoy_scorein 1.5, withprobas_preddeprecated and removed in 1.7. The 1.9 signature is(y_true, y_score, *, pos_label=None, sample_weight=None, drop_intermediate=False)(sklearn/metrics/_ranking.py#L1059).squareddeprecation pattern inmetrics/_regression.pyi. The main overload takesy_score. A second overload, marked@deprecated, accepts the keywordprobas_pred=that 1.5 and 1.6 still allow. Positional callsprecision_recall_curve(y, scores)are unaffected.stubtest_allowlist.txtsklearn.cluster.HDBSCAN,sklearn.cluster.__all__,sklearn.cluster._hdbscan.hdbscan, the tensklearn.tree._tree.Tree.*properties andmax_depth, and bothprecision_recall_curveentries.HDBSCAN.__sklearn_tags__(both paths),hdbscan.FAST_METRICSandhdbscan.remap_single_linkage_tree.Validation (local, Python 3.13,
--group tests)python tests/run_stubtest.py sklearnreports exactly the same set of errors before and after this change, so the PR adds no new stubtest errors and leaves no unused allowlist entries. Two caveats:numpy<2.3locally. With numpy 2.5 the run stops with an unrelated build error:sklearn/utils/validation.pyi: Module "numpy.core.numeric" has no attribute "ComplexWarning".mainthat this PR doesn't touch (_seq_datasetdisjoint-base errors and others), so a CI run may still fail on those.python -m mypy .: no issues.pyright stubs/sklearn tests: 0 errors. A probe file checkingHDBSCAN(...).fit(X).labels_,tree_.children_left,tree_.n_leavesandprecision_recall_curve(..., drop_intermediate=True)also checks cleanly.ruff check stubs/sklearnandruff format --check stubs/sklearnpass. Repo-wideruff checkreports one existingRUF100instubs/matplotlib/pyplot.pyi, which this PR doesn't touch.🤖 Generated with Claude Code