You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For my downstream project, I'm testing my classifier with check_estimator, and would like to see which of its individual tests failed.
Doing so under nose works by using for check in _yield_all_checks(name, estimator): yield check, name, my_estimator (and a separate call to the class-level checks), but py.test won't support yield-tests, and using _yield_all_checks to parameterize a test doesn't work because the function requires the estimator instance.
Therefore the request is to provide all checks from check_estimator as a (non-private) iterable, so they can be used separately.
We could for instance add a parameter evaluate=True to check_estimator that would make it yield check, name, estimator. In which case, downstream projects would be able use it, for instance with pytest as follows,
the name of the estimator is passed as parametrization parameter. For a single one, it's a bit useless, but this would make it easier to test multiples estimators in the downstream project at once by using e.g.,
the repr of the estimator instance is a bit verbose and subopimal in the list of pytest generated test names. But this can be fixed by customizing pytest options.
Another way to potentially handle this is to provide, as an alternative to
check_estimator, a pytest fixture that generates the various checks, or
something similar... I've not thought this out in detail.
Another way to potentially handle this is to provide, as an alternative to
check_estimator, a pytest fixture that generates the various checks, or
something similar... I've not thought this out in detail.
Interesting idea. The problem is that checks are generated based on the estimator, so the fixture would need to know which third party estimators to test which might be difficult.
The problem is that checks are generated based on the estimator
what about separating this decision (does check apply to this estimator) from enumerating all checks? simplest way would be to move it into the check, but maybe there's an even better idea?
what about separating this decision (does check apply to this estimator) from enumerating all checks? simplest way would be to move it into the check, but maybe there's an even better idea?
Generally some of this was discussed in #6715 but it would require some significant refactoring of the way estimator checks works. Estimator tags (#8022) could also be part of the solution in the long term.
We can't just move the checks inside of the corresponding check_* functions (and skip if the estimator should not be run) because then we get an overly verbose list of tests that are harder to follow. E.g. if estimator check_classification_* is skipped for some estimator, currently it would typically mean that there is some issue why it was not supported as skipped as a workaround. If the estimator is not a classifier in the first place, the check will not be run. With the proposed change it would be run for all estimators, which would be confusing IMO.
I thought I had commented on this. I'm not sure I'm convinced it's good to enable running individual tests because that will encourage not running all tests.
If your motivation is debugging, then really we should provide a better error message.
I thought I had commented on this. I'm not sure I'm convinced it's good to enable running individual tests because that will encourage not running all tests.
Thanks for the feedback. Still suppose one has a a single check that doesn't pass in check_estimator in a sklearn-contrib project. With an iterative setup, one could just skip the check in question and mark it as TODO later, and run the rest of checks. Without it, in the current situation, one would just not use check_estimator altogether because it would fail. I'm sure why the latter situation would be better.
It would give developers in scikit-learn contrib projects more flexibility if needed, without waiting for our 6month-12month release cycle. Flexibility is one of the things that was mentioned as limiting factor in #6715. Of course in the ideal world check_estimator would take into account all the needs of contrib projects, but currently we are not there yet.
Also honestly it's annoying to have one tests that runs several dozens checks. That's why we are parametrizing them in scikit-learn (before with yields now with pytest). Giving contrib projects a possibility to do the same, and trusting developers not to misuse it, would be nice IMO.
Also, some projects will never manage to be fully compliant with the scikit-learn API due to other constraints, e.g. hybrid recommendation, but at the same time, the API is somewhat inspired from scikit-learn, in which case one could imagine testing only the relevant subset of checks in check_estimator.
@rth that could be done with data formats and possibly tasks / estimator types.
But you make a good point that more flexibility is probably better and we're not going to cover 100% of use cases with our first version of estimator tags.
We can't just move the checks inside of the corresponding check_* functions (and skip if the estimator should not be run) because then we get an overly verbose list of tests that are harder to follow. E.g. if estimator check_classification_* is skipped for some estimator, currently it would typically mean that there is some issue why it was not supported as skipped as a workaround.
I think pytest.mark.xfail(run=false) is there for exactly such "workaround" cases, to be distinguished from skip.
Activity
rth commentedon Jul 18, 2018
We could for instance add a parameter
evaluate=Truetocheck_estimatorthat would make ityield check, name, estimator. In which case, downstream projects would be able use it, for instance with pytest as follows,the limitation of this approach is that,
Will make a PR to illustrate this better.
massich commentedon Jul 18, 2018
I'll give it a tryjnothman commentedon Jul 19, 2018
rth commentedon Jul 20, 2018
Interesting idea. The problem is that checks are generated based on the estimator, so the fixture would need to know which third party estimators to test which might be difficult.
azrdev commentedon Jul 21, 2018
what about separating this decision (does check apply to this estimator) from enumerating all checks? simplest way would be to move it into the check, but maybe there's an even better idea?
rth commentedon Jul 24, 2018
Generally some of this was discussed in #6715 but it would require some significant refactoring of the way estimator checks works. Estimator tags (#8022) could also be part of the solution in the long term.
We can't just move the checks inside of the corresponding
check_*functions (and skip if the estimator should not be run) because then we get an overly verbose list of tests that are harder to follow. E.g. if estimatorcheck_classification_*is skipped for some estimator, currently it would typically mean that there is some issue why it was not supported as skipped as a workaround. If the estimator is not a classifier in the first place, the check will not be run. With the proposed change it would be run for all estimators, which would be confusing IMO.amueller commentedon Jul 24, 2018
I thought I had commented on this. I'm not sure I'm convinced it's good to enable running individual tests because that will encourage not running all tests.
If your motivation is debugging, then really we should provide a better error message.
rth commentedon Jul 24, 2018
Thanks for the feedback. Still suppose one has a a single check that doesn't pass in
check_estimatorin a sklearn-contrib project. With an iterative setup, one could just skip the check in question and mark it as TODO later, and run the rest of checks. Without it, in the current situation, one would just not usecheck_estimatoraltogether because it would fail. I'm sure why the latter situation would be better.It would give developers in scikit-learn contrib projects more flexibility if needed, without waiting for our 6month-12month release cycle. Flexibility is one of the things that was mentioned as limiting factor in #6715. Of course in the ideal world
check_estimatorwould take into account all the needs of contrib projects, but currently we are not there yet.Also honestly it's annoying to have one tests that runs several dozens checks. That's why we are parametrizing them in scikit-learn (before with yields now with pytest). Giving contrib projects a possibility to do the same, and trusting developers not to misuse it, would be nice IMO.
rth commentedon Jul 24, 2018
Also, some projects will never manage to be fully compliant with the scikit-learn API due to other constraints, e.g. hybrid recommendation, but at the same time, the API is somewhat inspired from scikit-learn, in which case one could imagine testing only the relevant subset of checks in
check_estimator.amueller commentedon Jul 24, 2018
@rth that could be done with data formats and possibly tasks / estimator types.
But you make a good point that more flexibility is probably better and we're not going to cover 100% of use cases with our first version of estimator tags.
azrdev commentedon Apr 17, 2019
@rth commented on 24 Jul 2018
I think
pytest.mark.xfail(run=false)is there for exactly such "workaround" cases, to be distinguished fromskip.amueller commentedon Jun 7, 2019
Some possibly useful pointers:
I think this might be a good entry point:
https://docs.pytest.org/en/latest/usage.html#calling-pytest-from-python-code
Here's how to use hooks:
https://docs.pytest.org/en/latest/example/simple.html#incremental-testing-test-steps
I think you want to work with the collection hooks?
https://docs.pytest.org/en/latest/reference.html#collection-hooks
amueller commentedon Jul 10, 2019
Never mind, I was overthinking it, let's go with #11622 (comment)