Skip to content

Function parametrize_with_checks does not accept classes #16707

Closed
@TomDLT

Description

@TomDLT

The documentation of parametrize_with_checks claims that classes are accepted, but the function only accepts instances. The following example from the doc fails (launched with pytest):

from sklearn.utils.estimator_checks import parametrize_with_checks
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeRegressor

@parametrize_with_checks([LogisticRegression, DecisionTreeRegressor])
def test_sklearn_compatible_estimator(estimator, check):
    check(estimator)
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/pluggy/hooks.py:289: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/pluggy/manager.py:87: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/pluggy/manager.py:81: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/_pytest/python.py:225: in pytest_pycollect_makeitem
    res = list(collector._genfunctions(name, obj))
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/_pytest/python.py:401: in _genfunctions
    self.ihook.pytest_generate_tests(metafunc=metafunc)
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/pluggy/hooks.py:289: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/pluggy/manager.py:87: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/pluggy/manager.py:81: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/_pytest/python.py:128: in pytest_generate_tests
    metafunc.parametrize(*marker.args, **marker.kwargs)
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/_pytest/python.py:993: in parametrize
    function_definition=self.definition,
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/_pytest/mark/structures.py:122: in _for_parametrize
    parameters = cls._parse_parametrize_parameters(argvalues, force_tuple)
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/_pytest/mark/structures.py:116: in _parse_parametrize_parameters
    ParameterSet.extract_from(x, force_tuple=force_tuple) for x in argvalues
../../../../miniconda3/envs/py37/lib/python3.7/site-packages/_pytest/mark/structures.py:116: in <listcomp>
    ParameterSet.extract_from(x, force_tuple=force_tuple) for x in argvalues
../scikit-learn/sklearn/utils/estimator_checks.py:403: in <genexpr>
    for estimator, check in checks_generator)
../scikit-learn/sklearn/utils/estimator_checks.py:364: in _mark_xfail_checks
    xfail_checks = _safe_tags(estimator, '_xfail_test')
../scikit-learn/sklearn/utils/estimator_checks.py:66: in _safe_tags
    return estimator._get_tags().get(key, _DEFAULT_TAGS[key])
E   TypeError: _get_tags() missing 1 required positional argument: 'self'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================== 1 error in 0.39 seconds ===========================================

Fix A: (quickfix) update the docstring in parametrize_with_checks to allow only instances and not classes. Also update the example in "Rolling your own estimator".
Fix B: fix the behavior to accept classes, and add a test.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions