Skip to content

Commit 327b386

Browse files
author
Igor Rukhovich
authored
Applied mypy + flake8 + ISort for all files (#58)
* Applied mypy + flake8 for all files * Sorted imports with ISort * Moved env change to runner * fixed all mypy errors and added mypy check to CI * Yet another mypy fixes * removed E265 ignoring for flake8 job * Applying comments
1 parent b847226 commit 327b386

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+694
-691
lines changed

azure-pipelines.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,18 @@ jobs:
6363
- script: |
6464
python -m pip install --upgrade pip setuptools
6565
pip install flake8
66-
flake8 --ignore=E265,E722,E402 --max-line-length=90 --count
66+
flake8 --max-line-length=100 --count
6767
displayName: 'PEP 8 check'
68+
- job: Mypy
69+
pool:
70+
vmImage: 'ubuntu-20.04'
71+
steps:
72+
- task: UsePythonVersion@0
73+
inputs:
74+
versionSpec: '3.7'
75+
addToPath: true
76+
- script: |
77+
python -m pip install --upgrade pip setuptools
78+
pip install mypy data-science-types
79+
mypy . --ignore-missing-imports
80+
displayName: 'mypy check'

bench.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,14 +12,15 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

1717
import argparse
18-
import numpy as np
19-
import sklearn
20-
import timeit
2118
import json
2219
import sys
20+
import timeit
21+
22+
import numpy as np
23+
import sklearn
2324

2425

2526
def get_dtype(data):

cuml_bench/__init__.py

Whitespace-only changes.

cuml_bench/dbscan.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,17 +12,15 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21-
import bench
2218

19+
import bench
2320
from cuml import DBSCAN
2421
from sklearn.metrics.cluster import davies_bouldin_score
2522

23+
2624
parser = argparse.ArgumentParser(description='cuML DBSCAN benchmark')
2725
parser.add_argument('-e', '--eps', '--epsilon', type=float, default=10.,
2826
help='Radius of neighborhood of a point')

cuml_bench/df_clsf.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,12 +12,11 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18+
from typing import Any
19+
2120
import bench
2221
import cuml
2322
from cuml.ensemble import RandomForestClassifier
@@ -63,6 +62,7 @@
6362
params.split_algorithm = 1
6463

6564
params.n_classes = y_train[y_train.columns[0]].nunique()
65+
clf: Any
6666

6767

6868
def fit(X, y):
@@ -80,6 +80,7 @@ def fit(X, y):
8080

8181

8282
def predict(X):
83+
global clf
8384
prediction_args = {'predict_model': 'GPU'}
8485
if int(cuml.__version__.split('.')[1]) <= 14:
8586
prediction_args.update({'num_classes': params.n_classes})

cuml_bench/df_regr.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,14 +12,12 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21-
import bench
18+
from typing import Any
2219

20+
import bench
2321
from cuml.ensemble import RandomForestRegressor
2422

2523
parser = argparse.ArgumentParser(description='cuml random forest '
@@ -61,6 +59,7 @@
6159
params.split_algorithm = 0
6260
else:
6361
params.split_algorithm = 1
62+
regr: Any
6463

6564

6665
# Create our random forest regressor
@@ -79,6 +78,7 @@ def fit(X, y):
7978

8079

8180
def predict(X):
81+
global regr
8282
return regr.predict(X, predict_model='GPU')
8383

8484

cuml_bench/elasticnet.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,16 +12,14 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21-
import bench
2218

19+
import bench
2320
from cuml.linear_model import ElasticNet
2421

22+
2523
parser = argparse.ArgumentParser(description='scikit-learn elastic-net regression '
2624
'benchmark')
2725
parser.add_argument('--no-fit-intercept', dest='fit_intercept', default=True,

cuml_bench/kmeans.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,17 +12,15 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21-
import bench
18+
import warnings
19+
from typing import Any
2220

21+
import bench
2322
import numpy as np
2423
from cuml import KMeans
25-
import warnings
2624
from sklearn.metrics.cluster import davies_bouldin_score
2725

2826
warnings.filterwarnings('ignore', category=FutureWarning)
@@ -41,16 +39,18 @@
4139
# Load and convert generated data
4240
X_train, X_test, _, _ = bench.load_data(params)
4341

42+
X_init: Any
4443
if params.filei == 'k-means++':
4544
X_init = 'k-means++'
4645
# Load initial centroids from specified path
4746
elif params.filei is not None:
48-
X_init = np.load(params.filei).astype(params.dtype)
49-
params.n_clusters = X_init.shape[0]
47+
X_init = {k: v.astype(params.dtype) for k, v in np.load(params.filei).items()}
48+
if isinstance(X_init, np.ndarray):
49+
params.n_clusters = X_init.shape[0]
5050
# or choose random centroids from training data
5151
else:
5252
np.random.seed(params.seed)
53-
centroids_idx = np.random.randint(0, X_train.shape[0],
53+
centroids_idx = np.random.randint(low=0, high=X_train.shape[0],
5454
size=params.n_clusters)
5555
if hasattr(X_train, "iloc"):
5656
X_init = X_train.iloc[centroids_idx].to_pandas().values

cuml_bench/knn_clsf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,15 +12,14 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18+
2119
import bench
2220
from cuml.neighbors import KNeighborsClassifier
2321

22+
2423
parser = argparse.ArgumentParser(
2524
description='cuML kNN classifier benchmark')
2625

@@ -77,4 +76,5 @@
7776
stages=['training', 'search'], params=params,
7877
functions=['knn_clsf.fit', 'knn_clsf.kneighbors'],
7978
times=[train_time, predict_time],
79+
accuracies=[], accuracy_type=None,
8080
data=[X_train, X_test], alg_instance=knn_clsf)

cuml_bench/lasso.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,16 +12,14 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21-
import bench
2218

19+
import bench
2320
from cuml.linear_model import Lasso
2421

22+
2523
parser = argparse.ArgumentParser(description='scikit-learn lasso regression '
2624
'benchmark')
2725
parser.add_argument('--no-fit-intercept', dest='fit_intercept', default=False,

cuml_bench/linear.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,15 +12,14 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18+
2119
import bench
2220
from cuml import LinearRegression
2321

22+
2423
parser = argparse.ArgumentParser(description='cuML linear regression '
2524
'benchmark')
2625
parser.add_argument('--no-fit-intercept', dest='fit_intercept', default=True,

cuml_bench/log_reg.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,15 +12,14 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18+
2119
import bench
2220
from cuml import LogisticRegression
2321

22+
2423
parser = argparse.ArgumentParser(description='cuML logistic '
2524
'regression benchmark')
2625
parser.add_argument('--no-fit-intercept', dest='fit_intercept',

cuml_bench/pca.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,16 +12,14 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21-
import bench
2218

19+
import bench
2320
from cuml import PCA
2421

22+
2523
parser = argparse.ArgumentParser(description='cuML PCA benchmark')
2624
parser.add_argument('--svd-solver', type=str, default='full',
2725
choices=['auto', 'full', 'jacobi'],

cuml_bench/ridge.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#===============================================================================
1+
# ===============================================================================
22
# Copyright 2020-2021 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,15 +12,14 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
#===============================================================================
15+
# ===============================================================================
1616

17-
import sys
18-
import os
1917
import argparse
20-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18+
2119
import bench
2220
from cuml import Ridge
2321

22+
2423
parser = argparse.ArgumentParser(description='cuML ridge regression '
2524
'benchmark')
2625
parser.add_argument('--no-fit-intercept', dest='fit_intercept', default=True,

0 commit comments

Comments
 (0)