Skip to content

Conversation

@adrinjalali
Copy link
Member

Fixes #30011

This adds tests, and makes it more clear on how to extend tags.

It also does the right check on whether _more_tags is implemented but __sklearn_tags__ is missing.

cc @glemaitre @thomasjpfan

@adrinjalali adrinjalali added No Changelog Needed Developer API Third party developer API related labels Nov 12, 2024
@adrinjalali adrinjalali added this to the 1.6 milestone Nov 12, 2024
@github-actions
Copy link

github-actions bot commented Nov 12, 2024

✔️ Linting Passed

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

Generated for commit: ee76a50. Link to the linter CI: here

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

Comment on lines 535 to 539
tags.input_tags = tags_orig.input_tags
tags.target_tags = tags_orig.target_tags
tags.classifier_tags = tags_orig.classifier_tags
tags.regressor_tags = tags_orig.regressor_tags
tags.transformer_tags = tags_orig.transformer_tags
Copy link
Member

Choose a reason for hiding this comment

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

With MyTags(**asdict(tags_orig)) do we need to set all these afterwards?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, asdict goes recursive, which then makes tags.input_tags a dictionary instead of a InputTags instance.

Copy link
Member

Choose a reason for hiding this comment

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

Can we either do:

tags = MyTags(**tags_org.__dict__)

or: (Copied from the docs of asdict)

tags_org_dict = {field.name: getattr(tags_orig, field.name) for field in fields(tags_orig)}
tags = MyTags(**tags_org_dict)

Copy link
Member Author

Choose a reason for hiding this comment

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

They don't have a __dict__, but the second one works.

@thomasjpfan thomasjpfan merged commit 54810bc into scikit-learn:main Nov 13, 2024
30 checks passed
@adrinjalali adrinjalali deleted the tags/fix branch November 14, 2024 07:26
jeremiedbb pushed a commit to glemaitre/scikit-learn that referenced this pull request Nov 14, 2024
jeremiedbb pushed a commit that referenced this pull request Nov 14, 2024
@larsoner
Copy link
Contributor

This removes the public(ish?) sklearn.utils.estimator_checks.check_estimator_get_tags_default_keys in favor of check_valid_tag_types so now in a CI run that uses nilearn I get an import failure:

...
/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/nilearn/maskers/multi_nifti_masker.py:23: in <module>
    from nilearn._utils.class_inspect import (
/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/nilearn/_utils/class_inspect.py:3: in <module>
    from sklearn.utils.estimator_checks import (
E   ImportError: cannot import name 'check_estimator_get_tags_default_keys' from 'sklearn.utils.estimator_checks' (/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/sklearn/utils/estimator_checks.py)

Would it make sense to add a trivial check_estimator_get_tags_default_keys = check_valid_tag_types backward compat wrapper here or would that be too ugly?

@glemaitre
Copy link
Member

Would it make sense to add a trivial check_estimator_get_tags_default_keys = check_valid_tag_types

It is true that this one kind of public. I would be in favor of introducing an alias. @adrinjalali WDYT?

@adrinjalali
Copy link
Member Author

That test is really for Tags which are introduced in this release. I understand keeping the CI green during this cycle (and probably the upcoming cycle 🙈 ) hasn't been the best experience, but I don't think we should give that alias. Also, the old name really doesn't reflect what the test does, and if devs are doing something using the name, the chances are they might not be doing the same thing with the new test.

@larsoner
Copy link
Contributor

Makes sense to me, thanks -- forgot this was within-cycle!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Extending tags infrastructure is not easy anymore

4 participants