diff --git a/.travis.yml b/.travis.yml index 2f0cbf91067dd..0a28641762436 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,8 +42,9 @@ matrix: # It also runs tests requiring Pandas and PyAMG - env: DISTRIB="conda" PYTHON_VERSION="3.6.2" INSTALL_MKL="true" NUMPY_VERSION="1.13.1" SCIPY_VERSION="0.19.1" PANDAS_VERSION="0.20.3" - CYTHON_VERSION="0.26.1" PYAMG_VERSION="3.3.2" PILLOW_VERSION="4.3.0" - COVERAGE=true CHECK_PYTEST_SOFT_DEPENDENCY="true" + CYTHON_VERSION="0.26.1" PYAMG_VERSIONi="3.3.2" PILLOW_VERSION="4.3.0" + COVERAGE=true + CHECK_PYTEST_SOFT_DEPENDENCY="true" TEST_DOCSTRINGS="true" if: type != cron # flake8 linting on diff wrt common ancestor with upstream/master - env: RUN_FLAKE8="true" SKIP_TESTS="true" diff --git a/sklearn/utils/testing.py b/sklearn/utils/testing.py index 6e2d9d5902add..85023ece04ccf 100644 --- a/sklearn/utils/testing.py +++ b/sklearn/utils/testing.py @@ -862,23 +862,16 @@ def check_docstring_parameters(func, doc=None, ignore=None, class_name=None): param_names = [] for name, type_definition, param_doc in doc['Parameters']: - if (type_definition.strip() == "" or - type_definition.strip().startswith(':')): - - param_name = name.lstrip() - - # If there was no space between name and the colon - # "verbose:" -> len(["verbose", ""][0]) -> 7 - # If "verbose:"[7] == ":", then there was no space - if (':' not in param_name or - param_name[len(param_name.split(':')[0].strip())] == ':'): + if not type_definition.strip(): + if ':' in name and name[:name.index(':')][-1:].strip(): incorrect += [func_name + ' There was no space between the param name and ' - 'colon ("%s")' % name] - else: - incorrect += [func_name + ' Incorrect type definition for ' - 'param: "%s" (type definition was "%s")' - % (name.split(':')[0], type_definition)] + 'colon (%r)' % name] + elif name.rstrip().endswith(':'): + incorrect += [func_name + + ' Parameter %r has an empty type spec. ' + 'Remove the colon' % (name.lstrip())] + if '*' not in name: param_names.append(name.split(':')[0].strip('` ')) diff --git a/sklearn/utils/tests/test_testing.py b/sklearn/utils/tests/test_testing.py index 48b774fa41371..0aca27861e0bb 100644 --- a/sklearn/utils/tests/test_testing.py +++ b/sklearn/utils/tests/test_testing.py @@ -325,7 +325,7 @@ def f_missing(a, b): return c -def f_check_param_definition(a, b, c, d): +def f_check_param_definition(a, b, c, d, e): """Function f Parameters @@ -338,6 +338,8 @@ def f_check_param_definition(a, b, c, d): Parameter c d:int Parameter d + e + No typespec is allowed without colon """ return a + b + c + d @@ -402,8 +404,8 @@ def predict(self, X): """ return self.delegate.predict(X) - @deprecated("Testing a deprecated delegated method") @if_delegate_has_method(delegate=('delegate')) + @deprecated("Testing a deprecated delegated method") def score(self, X): """This is available only if delegate has score. @@ -424,20 +426,7 @@ def predict_proba(self, X): """ return X - @deprecated('Testing deprecated function with incorrect params') - @if_delegate_has_method(delegate=('delegate')) - def predict_log_proba(self, X): - """This is available only if delegate has predict_proba. - - Parameters - --------- - y : ndarray - Parameter X - """ - return X - @deprecated('Testing deprecated function with wrong params') - @if_delegate_has_method(delegate=('delegate')) def fit(self, X, y): """Incorrect docstring but should not be tested""" @@ -451,20 +440,32 @@ def test_check_docstring_parameters(): "numpydoc is required to test the docstrings") incorrect = check_docstring_parameters(f_ok) - assert_equal(incorrect, []) + assert incorrect == [] incorrect = check_docstring_parameters(f_ok, ignore=['b']) - assert_equal(incorrect, []) + assert incorrect == [] incorrect = check_docstring_parameters(f_missing, ignore=['b']) - assert_equal(incorrect, []) + assert incorrect == [] assert_raise_message(RuntimeError, 'Unknown section Results', check_docstring_parameters, f_bad_sections) assert_raise_message(RuntimeError, 'Unknown section Parameter', check_docstring_parameters, Klass.f_bad_sections) + incorrect = check_docstring_parameters(f_check_param_definition) + assert ( + incorrect == [ + "sklearn.utils.tests.test_testing.f_check_param_definition There " + "was no space between the param name and colon ('a: int')", + "sklearn.utils.tests.test_testing.f_check_param_definition There " + "was no space between the param name and colon ('b:')", + "sklearn.utils.tests.test_testing.f_check_param_definition " + "Parameter 'c :' has an empty type spec. Remove the colon", + "sklearn.utils.tests.test_testing.f_check_param_definition There " + "was no space between the param name and colon ('d:int')", + ]) + messages = ["a != b", "arg mismatch: ['b']", "arg mismatch: ['X', 'y']", "predict y != X", "predict_proba arg mismatch: ['X']", - "predict_log_proba arg mismatch: ['X']", "score arg mismatch: ['X']", ".fit arg mismatch: ['X', 'y']"] @@ -473,21 +474,7 @@ def test_check_docstring_parameters(): for mess, f in zip(messages, [f_bad_order, f_missing, Klass.f_missing, mock_meta.predict, mock_meta.predict_proba, - mock_meta.predict_log_proba, mock_meta.score, mock_meta.fit]): incorrect = check_docstring_parameters(f) - assert_true(len(incorrect) >= 1) - assert_true(mess in incorrect[0], - '"%s" not in "%s"' % (mess, incorrect[0])) - - incorrect = check_docstring_parameters(f_check_param_definition) - assert_equal( - incorrect, - ['sklearn.utils.tests.test_testing.f_check_param_definition There was ' - 'no space between the param name and colon ("a: int")', - 'sklearn.utils.tests.test_testing.f_check_param_definition There was ' - 'no space between the param name and colon ("b:")', - 'sklearn.utils.tests.test_testing.f_check_param_definition Incorrect ' - 'type definition for param: "c " (type definition was "")', - 'sklearn.utils.tests.test_testing.f_check_param_definition There was ' - 'no space between the param name and colon ("d:int")']) + assert len(incorrect) >= 1 + assert mess in incorrect[0], '"%s" not in "%s"' % (mess, incorrect[0])