Skip to content
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

fix mixin inheritance order, allow overwriting tags #14884

Merged
merged 7 commits into from Sep 5, 2019

Conversation

amueller
Copy link
Member

@amueller amueller commented Sep 4, 2019

Incremental change from #14644, keeping the old logic manually looping over the MRO.
I would really prefer using super but this is a mostly backward-compatible change and seems less controversial.

rth
rth approved these changes Sep 4, 2019
Copy link
Member

@rth rth left a comment

I have not checked that changes include all classes, but the included changes LGTM.

I would really prefer using super but this is a mostly backward-compatible change and seems less controversial.

OK, but I think in either case these changes with mixin reordering would be necessary so it's good to have this no?

cc @NicolasHug in case you have bandwidth for a second quick review :)

@amueller
Copy link
Member Author

@amueller amueller commented Sep 4, 2019

Yes these changes here are are prerequisite so I'm happy to merge them.

@NicolasHug
Copy link
Member

@NicolasHug NicolasHug commented Sep 4, 2019

If we want to simulate super we should go down the MRO, not up.

from sklearn.base import BaseEstimator
class A(BaseEstimator):
    def _more_tags(self):
        return {'allow_nan': True,
                'multioutput': False}

class B(A):
    def _more_tags(self):
        return {'multioutput': True}

class C(B):
    def _more_tags(self):
        return {'allow_nan': False}

class D(C):
    # No _more_tags(), yet self._more_tags() exists and it's C's method
    pass

# "correctly" resolves to C's allow_nan only because C has _more_tags().
print(D()._get_tags()['allow_nan'])  # False, OK

# resolves to A's multioutput instead of B's since C's _more_tags does not
# specifies multioutput, and because we're going up the mro instead of down the
# mro.
print(D()._get_tags()['multioutput'])  # False, KO

@amueller
Copy link
Member Author

@amueller amueller commented Sep 4, 2019

I need to make sure I have the tests from the other PR, will fix this later.


diamond_tag_est = DiamondOverwriteTag()
with pytest.raises(TypeError, match="Inconsistent values for tag"):
diamond_tag_est._get_tags()
assert diamond_tag_est._get_tags()
Copy link
Member Author

@amueller amueller Sep 4, 2019

Choose a reason for hiding this comment

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

lol this is missing an ['allow_nan']

@amueller
Copy link
Member Author

@amueller amueller commented Sep 4, 2019

I'm confused why the current tests pass ...

@amueller
Copy link
Member Author

@amueller amueller commented Sep 4, 2019

tests were passing because the logic was to complicated and only wrong in complex cases.

Copy link
Member

@NicolasHug NicolasHug left a comment

LGTM when all goes green!

@rth rth merged commit 03ea20d into scikit-learn:master Sep 5, 2019
18 checks passed
@rth
Copy link
Member

@rth rth commented Sep 5, 2019

Thanks!

@thomasjpfan
Copy link
Member

@thomasjpfan thomasjpfan commented Sep 5, 2019

In a follow up, we should document how the order of the inheritance matters now when using tags.

ivannz added a commit to ivannz/scikit-learn that referenced this issue Oct 5, 2019
ivannz added a commit to ivannz/scikit-learn that referenced this issue Oct 11, 2019
@jnothman jnothman mentioned this pull request Oct 28, 2019
8 tasks
ivannz added a commit to ivannz/scikit-learn that referenced this issue Nov 1, 2019
artemmavrin added a commit to artemmavrin/logitboost that referenced this issue Dec 7, 2019
ivannz added a commit to ivannz/scikit-learn that referenced this issue Jan 10, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Jan 30, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Jan 30, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Feb 27, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Mar 12, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Apr 17, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue May 3, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue May 30, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Jul 5, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Jul 5, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Aug 5, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Oct 15, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Nov 28, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Dec 12, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this issue Feb 25, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this issue Feb 25, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this issue Mar 27, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this issue Jun 15, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this issue Jul 23, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this issue Nov 10, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this issue May 15, 2022
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.

None yet

4 participants