Skip to content

MAINT move _estimator_has function to utils #29319

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 36 commits into from
Nov 5, 2024

Conversation

nithish08
Copy link
Contributor

Fixes Issue-29046

Moved _estimator_has function to utils.

Side-comment: _estimator_has function in sklearn/model_selection/_search.py renamed to _search_estimator_has to avoid confusion.

@nithish08 nithish08 changed the title MAINT define a single time _estimator_has MAINT move _estimator_has function to utils Jun 20, 2024
Copy link

github-actions bot commented Jun 20, 2024

✔️ Linting Passed

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

Generated for commit: 17bf5bc. Link to the linter CI: here

@nithish08 nithish08 marked this pull request as draft June 21, 2024 17:54
@nithish08 nithish08 marked this pull request as ready for review June 23, 2024 03:14
@nithish08
Copy link
Contributor Author

@glemaitre Can you please review this?

Copy link
Contributor

@StefanieSenger StefanieSenger left a comment

Choose a reason for hiding this comment

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

Hey @nithish08,
thanks for your PR. I went through it and left you some comments. I'm not a maintainer though.

nithish08 and others added 2 commits June 23, 2024 07:32
Co-authored-by: Stefanie Senger <91849487+StefanieSenger@users.noreply.github.com>
Co-authored-by: Stefanie Senger <91849487+StefanieSenger@users.noreply.github.com>
@nithish08 nithish08 marked this pull request as draft June 24, 2024 19:55
@nithish08 nithish08 requested a review from StefanieSenger June 29, 2024 20:45
@nithish08
Copy link
Contributor Author

Thanks, @StefanieSenger, for the review. I have addressed the comments. Please re-review when you get a chance.

@nithish08 nithish08 marked this pull request as ready for review June 30, 2024 15:25
Copy link
Contributor

@StefanieSenger StefanieSenger left a comment

Choose a reason for hiding this comment

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

Thank you for your update and further work, @nithish08.

The _estimator_has function and the tests for it look pretty good.

I have left you some comments regarding documentation and I suggest using the pytest.mark.parametrize decorator so the tests are more consistent and easier to read.

nithish08 and others added 2 commits July 5, 2024 10:00
Co-authored-by: Stefanie Senger <91849487+StefanieSenger@users.noreply.github.com>
Co-authored-by: Stefanie Senger <91849487+StefanieSenger@users.noreply.github.com>
@nithish08
Copy link
Contributor Author

Thanks, @StefanieSenger; I have addressed the comments.

Copy link
Contributor

@StefanieSenger StefanieSenger left a comment

Choose a reason for hiding this comment

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

Thanks for your work @nithish08, it looks fantastic! 🥇

Pinging @glemaitre to also have a look at it.

@glemaitre
Copy link
Member

Thanks. I'll put in my list for review.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

Here is a first pass of comment. It looks already pretty good but I think that we can make the tool a bit more generic for third-party libraries.

I did not look at the test because I'm proposing some API changes that will impact the test as well.

# In meta estimators with multiple sub estimators,
# only the attribute of the first sub estimator is checked,
# assuming uniformity across all sub estimators.
if delegate == "estimators_":
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this statement here. Basically, we could do the same for estimators as well. But then, we might have third party that have something different and then they cannot use this tool. For instance, in imbalanced-learn, we would use this pattern with samplers_ and samplers for instance.

So I would be a bit more lenient here and only check if the attribute can be iterated:

if hasattr(self, delegate):
    delagator = getattr(self, delegate)
    if isinstance(delegator, Sequence):
        return getattr(delegator[0], attr)
    else:
        return getattr(delegator, attr)

where Sequence can be imported from collections.abc

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should care much about third parties since this is very private, but I like your diff anyway.

@glemaitre
Copy link
Member

ping @adrinjalali to take over this PR.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @adrinjalali to take over this PR.

# In meta estimators with multiple sub estimators,
# only the attribute of the first sub estimator is checked,
# assuming uniformity across all sub estimators.
if delegate == "estimators_":
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should care much about third parties since this is very private, but I like your diff anyway.

@adrinjalali adrinjalali enabled auto-merge (squash) November 5, 2024 19:43
@adrinjalali adrinjalali merged commit 8f620fd into scikit-learn:main Nov 5, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MAINT define a single time _estimator_has and refactor code
4 participants