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 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.

amueller added 2 commits Sep 4, 2019
@rth
rth approved these changes Sep 4, 2019
Copy link
Member

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

This comment has been minimized.

Copy link
Member Author

amueller commented Sep 4, 2019

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

@NicolasHug

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Member Author

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()

This comment has been minimized.

Copy link
@amueller

amueller Sep 4, 2019

Author Member

lol this is missing an ['allow_nan']

@amueller

This comment has been minimized.

Copy link
Member Author

amueller commented Sep 4, 2019

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

amueller added 2 commits Sep 4, 2019
@amueller

This comment has been minimized.

Copy link
Member Author

amueller commented Sep 4, 2019

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

Copy link
Contributor

NicolasHug left a comment

LGTM when all goes green!

@rth rth merged commit 03ea20d into scikit-learn:master Sep 5, 2019
18 checks passed
18 checks passed
LGTM analysis: C/C++ No code changes detected
Details
LGTM analysis: JavaScript No code changes detected
Details
LGTM analysis: Python 14 new alerts
Details
ci/circleci: deploy Your tests passed on CircleCI!
Details
ci/circleci: doc Your tests passed on CircleCI!
Details
ci/circleci: doc artifact Link to 0/doc/_changed.html
Details
ci/circleci: doc-min-dependencies Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
codecov/patch 100% of diff hit (target 96.92%)
Details
codecov/project Absolute coverage decreased by -<.01% but relative coverage increased by +3.07% compared to ae5f558
Details
scikit-learn.scikit-learn Build #20190904.40 succeeded
Details
scikit-learn.scikit-learn (Linux py35_conda_openblas) Linux py35_conda_openblas succeeded
Details
scikit-learn.scikit-learn (Linux py35_ubuntu_atlas) Linux py35_ubuntu_atlas succeeded
Details
scikit-learn.scikit-learn (Linux pylatest_conda_mkl_pandas) Linux pylatest_conda_mkl_pandas succeeded
Details
scikit-learn.scikit-learn (Linux32 py35_ubuntu_atlas_32bit) Linux32 py35_ubuntu_atlas_32bit succeeded
Details
scikit-learn.scikit-learn (Windows py35_pip_openblas_32bit) Windows py35_pip_openblas_32bit succeeded
Details
scikit-learn.scikit-learn (Windows py37_conda_mkl) Windows py37_conda_mkl succeeded
Details
scikit-learn.scikit-learn (macOS pylatest_conda_mkl) macOS pylatest_conda_mkl succeeded
Details
@rth

This comment has been minimized.

Copy link
Member

rth commented Sep 5, 2019

Thanks!

@thomasjpfan

This comment has been minimized.

Copy link
Member

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 pull request Oct 5, 2019
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Oct 11, 2019
@jnothman jnothman mentioned this pull request Oct 28, 2019
0 of 8 tasks complete
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Nov 1, 2019
artemmavrin added a commit to artemmavrin/logitboost that referenced this pull request Dec 7, 2019
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.