Skip to content

[sklearn] Make BaseEstimator inherit from _MetadataRequester #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 19, 2025

Conversation

tmke8
Copy link
Contributor

@tmke8 tmke8 commented Jul 18, 2025

@tmke8
Copy link
Contributor Author

tmke8 commented Jul 18, 2025

@tmke8
Copy link
Contributor Author

tmke8 commented Jul 18, 2025

@microsoft-github-policy-service agree

@debonte
Copy link
Contributor

debonte commented Jul 18, 2025

stubs/sklearn/base.pyi:28:1: error: Call to untyped function "init_subclass" in typed context [no-untyped-call]
stubs/sklearn/naive_bayes.pyi:36:1: error: Call to untyped function "init_subclass" in typed context [no-untyped-call]
stubs/sklearn/naive_bayes.pyi:42:1: error: Call to untyped function "init_subclass" in typed context [no-untyped-call]
stubs/sklearn/naive_bayes.pyi:69:1: error: Call to untyped function "init_subclass" in typed context [no-untyped-call]

@Avasam, any idea why mypy is complaining here? I did a spot check and didn't see any explicit __init_subclass__ calls at the reported locations.

@Avasam
Copy link
Contributor

Avasam commented Jul 18, 2025

I'm omw out of city for the weekend. So I can't give you an exact detailed reason atm.
But that one can be triggered w/o an explicit call as mypy understand it is automatically called (I did have it come up in previous PRs).

@tmke8
Copy link
Contributor Author

tmke8 commented Jul 18, 2025

It seems __init_subclass__ on _MetadataRequester creates the set_*_request() methods: https://github.com/scikit-learn/scikit-learn/blob/f462edd741c3cbfccc1c6a2d64a2a66a6599d3f8/sklearn/utils/_metadata_requests.py#L1406

However, the type stubs already have these methods statically on the class:

def set_fit_request(self, **kwargs): ...
def set_partial_fit_request(self, **kwargs): ...
def set_predict_request(self, **kwargs): ...
def set_predict_proba_request(self, **kwargs): ...
def set_predict_log_proba_request(self, **kwargs): ...
def set_decision_function_request(self, **kwargs): ...
def set_score_request(self, **kwargs): ...
def set_split_request(self, **kwargs): ...
def set_transform_request(self, **kwargs): ...
def set_inverse_transform_request(self, **kwargs): ...

So, I think that means __init_subclass__ can be removed from the stubs? I don't think anyone will call it explicitly.

@tmke8
Copy link
Contributor Author

tmke8 commented Jul 18, 2025

(I found another missing thing and added it in a new commit. Hope that's okay; I can remove it if not. It's about the global config: https://scikit-learn.org/stable/modules/generated/sklearn.set_config.html#sklearn.set_config )

@debonte debonte merged commit ee6d039 into microsoft:main Jul 19, 2025
8 checks passed
@debonte
Copy link
Contributor

debonte commented Jul 19, 2025

Thanks for contribution @tmke8!

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.

3 participants