From c53a4fa784d2adeab97e6248a98f4fe447c72c04 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Sun, 10 May 2020 17:28:56 +0200 Subject: [PATCH 1/3] Fix linting on azure --- azure-pipelines.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 196d4ca34f434..c850154afb24b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -18,27 +18,30 @@ jobs: - bash: sudo chown -R $USER $CONDA displayName: Take ownership of conda installation - bash: | + set -ex conda create --name flake8_env --yes python=3.8 - conda activate flake8_env + source activate flake8_env pip install flake8 mypy==0.770 displayName: Install flake8 - bash: | + set -ex if [[ $BUILD_SOURCEVERSIONMESSAGE =~ \[lint\ skip\] ]]; then # skip linting echo "Skipping linting" exit 0 else - conda activate flake8_env + source activate flake8_env ./build_tools/circle/linting.sh fi displayName: Run linting - bash: | + set -ex if [[ $BUILD_SOURCEVERSIONMESSAGE =~ \[lint\ skip\] ]]; then # skip linting echo "Skipping linting" exit 0 else - conda activate flake8_env + source activate flake8_env mypy sklearn/ --ignore-missing-imports fi displayName: Run mypy From 7f04efd0b4c6afdee7f7fb65d6b33e48c7bf1714 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Sun, 10 May 2020 17:34:11 +0200 Subject: [PATCH 2/3] Fix mypy errors --- sklearn/cluster/_agglomerative.py | 3 ++- sklearn/manifold/_t_sne.py | 3 ++- sklearn/utils/tests/test_utils.py | 6 +++--- sklearn/utils/validation.py | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/sklearn/cluster/_agglomerative.py b/sklearn/cluster/_agglomerative.py index 92246141d6fe8..2c317e474c721 100644 --- a/sklearn/cluster/_agglomerative.py +++ b/sklearn/cluster/_agglomerative.py @@ -21,7 +21,8 @@ from ..neighbors import DistanceMetric from ..neighbors._dist_metrics import METRIC_MAPPING -from . import _hierarchical_fast as _hierarchical +# mypy error: Module 'sklearn.cluster' has no attribute '_hierarchical_fast' +from . import _hierarchical_fast as _hierarchical # type: ignore from ._feature_agglomeration import AgglomerationTransform from ..utils._fast_dict import IntFloatDict from ..utils.fixes import _astype_copy_false diff --git a/sklearn/manifold/_t_sne.py b/sklearn/manifold/_t_sne.py index eef67d5460e22..1abed4ab9fa3c 100644 --- a/sklearn/manifold/_t_sne.py +++ b/sklearn/manifold/_t_sne.py @@ -22,7 +22,8 @@ from ..utils.validation import _deprecate_positional_args from ..decomposition import PCA from ..metrics.pairwise import pairwise_distances -from . import _utils +# mypy error: Module 'sklearn.manifold' has no attribute '_utils' +from . import _utils # type: ignore # mypy error: Module 'sklearn.manifold' has no attribute '_barnes_hut_tsne' from . import _barnes_hut_tsne # type: ignore diff --git a/sklearn/utils/tests/test_utils.py b/sklearn/utils/tests/test_utils.py index 6103febd73616..657811c6a9e5b 100644 --- a/sklearn/utils/tests/test_utils.py +++ b/sklearn/utils/tests/test_utils.py @@ -657,9 +657,9 @@ def test_print_elapsed_time(message, expected, capsys, monkeypatch): @pytest.mark.parametrize("value, result", [(float("nan"), True), (np.nan, True), - (np.float("nan"), True), - (np.float32("nan"), True), - (np.float64("nan"), True), + (np.float(float("nan")), True), + (np.float32(float("nan")), True), + (np.float64(float("nan")), True), (0, False), (0., False), (None, False), diff --git a/sklearn/utils/validation.py b/sklearn/utils/validation.py index 7a6ef1e05fdde..140b8d48a1bcd 100644 --- a/sklearn/utils/validation.py +++ b/sklearn/utils/validation.py @@ -18,7 +18,8 @@ from distutils.version import LooseVersion from inspect import signature, isclass, Parameter -from numpy.core.numeric import ComplexWarning +# mypy error: Module 'numpy.core.numeric' has no attribute 'ComplexWarning' +from numpy.core.numeric import ComplexWarning # type: ignore import joblib from contextlib import suppress From 041b39ebc09571e7d5337aec32a0c6e680e8b92c Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Sun, 10 May 2020 18:05:06 +0200 Subject: [PATCH 3/3] Use np.float64(np.nan) --- sklearn/utils/tests/test_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sklearn/utils/tests/test_utils.py b/sklearn/utils/tests/test_utils.py index 657811c6a9e5b..49eacb88766ce 100644 --- a/sklearn/utils/tests/test_utils.py +++ b/sklearn/utils/tests/test_utils.py @@ -657,9 +657,9 @@ def test_print_elapsed_time(message, expected, capsys, monkeypatch): @pytest.mark.parametrize("value, result", [(float("nan"), True), (np.nan, True), - (np.float(float("nan")), True), - (np.float32(float("nan")), True), - (np.float64(float("nan")), True), + (np.float(np.nan), True), + (np.float32(np.nan), True), + (np.float64(np.nan), True), (0, False), (0., False), (None, False),