Skip to content

Pin static-checking versions and add pre-commit Action #813

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
repos:
- repo: https://github.com/python/black
rev: 19.10b0
rev: 20.8b1
hooks:
- id: black
language_version: python3
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
rev: 3.8.3
hooks:
- id: flake8
language_version: python3
- repo: https://github.com/timothycrosley/isort
rev: 4.3.21
rev: 5.8.0
hooks:
- id: isort
language_version: python3
2 changes: 1 addition & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Checking isort... ' ; echo $MSG
isort --version-number
isort --recursive --check-only .
isort --profile=black --check-only .
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Checking mypy... ' ; echo $MSG
Expand Down
6 changes: 3 additions & 3 deletions ci/environment-3.6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ channels:
- conda-forge
- defaults
dependencies:
- black==19.10b0
- black==20.8b1
- coverage
- dask ==2.4.0
- dask-glm >=0.2.0
- distributed ==2.4.0
- flake8
- isort==4.3.21
- flake8==3.8.3
- isort==5.8.0
- msgpack-python ==0.6.2
- multipledispatch
- mypy
Copy link
Contributor Author

@hristog hristog Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reproducible/predictable CI runs, the mypy versions in these files should probably be pinned as well. Please, let me know if you've got any objections.

Expand Down
6 changes: 3 additions & 3 deletions ci/environment-3.7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
- defaults
dependencies:
- black==19.10b0
- black==20.8b1
- coverage
- codecov
# dask 2021.3.0 introduced a regression which causes tests to fail.
Expand All @@ -12,8 +12,8 @@ dependencies:
# to allow CI to pass
- dask !=2021.3.0
- dask-glm >=0.2.0
- flake8
- isort==4.3.21
- flake8==3.8.3
- isort==5.8.0
- multipledispatch >=0.4.9
- mypy
- numba
Expand Down
6 changes: 3 additions & 3 deletions ci/environment-3.8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
- defaults
dependencies:
- black==19.10b0
- black==20.8b1
- coverage
- codecov
# dask 2021.3.0 introduced a regression which causes tests to fail.
Expand All @@ -12,8 +12,8 @@ dependencies:
# to allow CI to pass
- dask !=2021.3.0
- dask-glm >=0.2.0
- flake8
- isort==4.3.21
- flake8==3.8.3
- isort==5.8.0
- multipledispatch >=0.4.9
- mypy
- numba
Expand Down
6 changes: 3 additions & 3 deletions ci/environment-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ channels:
- conda-forge
- defaults
dependencies:
- black
- black==20.8b1
- coverage
- flake8
- flake8==3.8.3
- graphviz
- heapdict
- ipykernel
- ipython
- isort==4.3.21
- isort==5.8.0
- multipledispatch
- mypy
- nbsphinx
Expand Down
2 changes: 1 addition & 1 deletion ci/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
black --check .

echo "[isort]"
isort --recursive --check-only .
isort --profile=black --check-only .

echo "[codecov]"
codecov
Expand Down
2 changes: 1 addition & 1 deletion dask_ml/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def dummy_context(*args: Any, **kwargs: Any):
def _check_multimetric_scoring(estimator, scoring=None):
# TODO: See if scikit-learn 0.24 solves the need for using
# a private method
from sklearn.metrics._scorer import _check_multimetric_scoring
from sklearn.metrics import check_scoring
from sklearn.metrics._scorer import _check_multimetric_scoring

if SK_024:
if callable(scoring) or isinstance(scoring, (type(None), str)):
Expand Down
9 changes: 6 additions & 3 deletions dask_ml/model_selection/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@ def fit(self, X, y, **fit_params):
len(missing) == 0
), "Expected fit parameter(s) %s not " "seen." % list(missing)
for key, value in fit_params.items():
assert len(value) == len(X), (
"Fit parameter %s has length"
"%d; expected %d." % (key, len(value), len(X),)
assert len(value) == len(
X
), "Fit parameter %s has length" "%d; expected %d." % (
key,
len(value),
len(X),
)
return self

Expand Down
3 changes: 1 addition & 2 deletions docs/dimensions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np

import matplotlib.pyplot as plt
import numpy as np


def draw_brace(ax, xspan, text):
Expand Down
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import dask_sphinx_theme

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import packaging.version

import dask_sphinx_theme
from dask_ml import __version__ as version

# import sys
Expand Down
2 changes: 1 addition & 1 deletion docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ installed.

black .
flake8
isort -rc dask_ml tests
isort --profile=black dask_ml tests

You may wish to setup a
`pre-commit hook <https://black.readthedocs.io/en/stable/version_control_integration.html>`_
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include_trailing_comma=True
force_grid_wrap=0
combine_as_imports=True
line_length=88
profile=black
skip=
Copy link
Contributor Author

@hristog hristog Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new profile=black option, skipping docs/source/conf.py is no longer necessary.

docs/source/conf.py

Expand Down
9 changes: 6 additions & 3 deletions tests/ensemble/test_blockwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class TestBlockwiseVotingClassifier:
def test_hard_voting_array(self):
X, y = dask_ml.datasets.make_classification(chunks=25)
clf = dask_ml.ensemble.BlockwiseVotingClassifier(
sklearn.linear_model.LogisticRegression(solver="lbfgs"), classes=[0, 1],
sklearn.linear_model.LogisticRegression(solver="lbfgs"),
classes=[0, 1],
)
clf.fit(X, y)
assert len(clf.estimators_) == 4
Expand Down Expand Up @@ -51,7 +52,8 @@ def test_bad_chunking_raises(self):
X = da.ones((10, 5), chunks=3)
y = da.ones(10, chunks=3)
clf = dask_ml.ensemble.BlockwiseVotingClassifier(
sklearn.linear_model.LogisticRegression(solver="lbfgs"), classes=[0, 1],
sklearn.linear_model.LogisticRegression(solver="lbfgs"),
classes=[0, 1],
)

with pytest.raises(TypeError):
Expand All @@ -64,7 +66,8 @@ def test_hard_voting_frame(self):
y = dd.from_dask_array(y)

clf = dask_ml.ensemble.BlockwiseVotingClassifier(
sklearn.linear_model.LogisticRegression(solver="lbfgs"), classes=[0, 1],
sklearn.linear_model.LogisticRegression(solver="lbfgs"),
classes=[0, 1],
)
clf.fit(X, y)
assert len(clf.estimators_) == 4
Expand Down
3 changes: 2 additions & 1 deletion tests/linear_model/test_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ def test_fit(fit_intercept, solver):
"solver", ["admm", "newton", "lbfgs", "proximal_grad", "gradient_descent"]
)
def test_fit_solver(solver):
import dask_glm
from distutils.version import LooseVersion

import dask_glm

if LooseVersion(dask_glm.__version__) <= "0.2.0":
pytest.skip("FutureWarning for dask config.")

Expand Down
13 changes: 11 additions & 2 deletions tests/model_selection/dask_searchcv/test_model_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,12 @@ def test_pipeline_sub_estimators():
},
]

gs = GridSearchCV(pipe, param_grid=param_grid, return_train_score=True, cv=3,)
gs = GridSearchCV(
pipe,
param_grid=param_grid,
return_train_score=True,
cv=3,
)
gs.fit(X, y)
dgs = dcv.GridSearchCV(
pipe, param_grid=param_grid, scheduler="sync", return_train_score=True, cv=3
Expand Down Expand Up @@ -946,7 +951,11 @@ def test_gridsearch_with_arraylike_fit_param(cache_cv):
param_grid = {"foo_param": [0.0001, 0.1]}

a = dcv.GridSearchCV(
MockClassifierWithFitParam(), param_grid, cv=3, refit=False, cache_cv=cache_cv,
MockClassifierWithFitParam(),
param_grid,
cv=3,
refit=False,
cache_cv=cache_cv,
)
b = GridSearchCV(MockClassifierWithFitParam(), param_grid, cv=3, refit=False)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def test_pandas_input():
# check cross_val_score doesn't destroy pandas dataframe
types = [(MockDataFrame, MockDataFrame)]
try:
from pandas import Series, DataFrame
from pandas import DataFrame, Series

types.append((DataFrame, Series))
except ImportError:
Expand Down
21 changes: 12 additions & 9 deletions tests/model_selection/test_hyperband.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,18 @@ def test_correct_params(c, s, a, b):
SHAs_params = [
bracket["SuccessiveHalvingSearchCV params"] for bracket in meta["brackets"]
]
SHA_params = base.union(
{
"n_initial_parameters",
"n_initial_iter",
"aggressiveness",
"max_iter",
"prefix",
}
) - {"estimator__sleep", "estimator__value", "estimator", "parameters"}
SHA_params = (
base.union(
{
"n_initial_parameters",
"n_initial_iter",
"aggressiveness",
"max_iter",
"prefix",
}
)
- {"estimator__sleep", "estimator__value", "estimator", "parameters"}
)

assert all(set(SHA) == SHA_params for SHA in SHAs_params)

Expand Down
13 changes: 11 additions & 2 deletions tests/model_selection/test_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,12 @@ def score(self, *args, **kwargs):
model = ConstantClassifier()

search = IncrementalSearchCV(
model, params, n_initial_parameters=10, patience=5, tol=0, max_iter=10,
model,
params,
n_initial_parameters=10,
patience=5,
tol=0,
max_iter=10,
)
yield search.fit(X, y, classes=[0, 1])

Expand Down Expand Up @@ -770,7 +775,11 @@ def test_search_patience_infeasible_tol(c, s, a, b):
max_iter = 10
score_increase = -10
search = IncrementalSearchCV(
model, params, max_iter=max_iter, patience=3, tol=score_increase,
model,
params,
max_iter=max_iter,
patience=3,
tol=score_increase,
)
yield search.fit(X, y, classes=[0, 1])

Expand Down
5 changes: 4 additions & 1 deletion tests/model_selection/test_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def test_keras(c, s, a, b):
assert y.dtype == np.dtype("int64")

model = KerasClassifier(
model=_keras_build_fn, lr=0.01, verbose=False, loss="categorical_crossentropy",
model=_keras_build_fn,
lr=0.01,
verbose=False,
loss="categorical_crossentropy",
)
params = {"lr": loguniform(1e-3, 1e-1)}

Expand Down
16 changes: 10 additions & 6 deletions tests/test_incremental_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
from dask_ml.utils import flip_vector_signs

try:
from sklearn.utils._testing import assert_almost_equal
from sklearn.utils._testing import assert_array_almost_equal
from sklearn.utils._testing import assert_allclose_dense_sparse
from sklearn.utils._testing import (
assert_allclose_dense_sparse,
assert_almost_equal,
assert_array_almost_equal,
)
except ImportError:
from sklearn.utils.testing import assert_almost_equal
from sklearn.utils.testing import assert_array_almost_equal
from sklearn.utils.testing import assert_allclose_dense_sparse
from sklearn.utils.testing import (
assert_allclose_dense_sparse,
assert_almost_equal,
assert_array_almost_equal,
)


iris = datasets.load_iris()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_spectral_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ def test_spectral_clustering(Xl_blobs_easy):

@pytest.mark.parametrize("keep", [[4, 7], [4, 5], [0, 3], [1, 9], [0, 1, 5, 8, 9]])
def test_slice_mostly_sorted(keep):
import numpy as np
import dask.array as da
import numpy as np
from dask.array.utils import assert_eq

from dask_ml.cluster.spectral import _slice_mostly_sorted

X = np.arange(10).reshape(-1, 1)
Expand Down