Skip to content

Commit c9f4dd7

Browse files
authored
REFACTOR: support mypy checks in 'strict' mode (#346)
1 parent 487b13d commit c9f4dd7

28 files changed

+663
-447
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ repos:
3838
additional_dependencies:
3939
- numpy~=1.22
4040
- gamma-pytools~=2.0,!=2.0.0
41-
- sklearndf>=2.0.dev3,<3a
41+
- sklearndf~=2.0

condabuild/meta.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ test:
4545
- typing_inspect {{ environ.get('FACET_V_TYPING_INSPECT') }}
4646
# additional requirements of shap
4747
- ipython {{ environ.get('FACET_V_IPYTHON') }}
48+
- numba {{ environ.get('FACET_V_NUMBA') }}
4849
commands:
4950
- conda list
5051
- python -c 'import facet;

environment.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ dependencies:
1414
- python ~= 3.8.12
1515
- scikit-learn ~= 1.0.2
1616
- scipy ~= 1.8
17-
- shap ~=0.40
18-
- sklearndf >= 2.0.dev3, < 3a
17+
- shap ~= 0.41
18+
- sklearndf ~= 2.0
1919
# build/test
2020
- conda-build ~= 3.21
2121
- conda-verify ~= 3.1

mypy.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[mypy]
22
show_error_codes = True
3-
allow_redefinition = True
3+
strict = True
44

55
[mypy-catboost.*]
66
; TODO remove once PEP 561 is supported

pyproject.toml

+10-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ dist-name = "gamma-facet"
1414
license = "Apache Software License v2.0"
1515

1616
requires = [
17-
"gamma-pytools ~=2.0,>=2.0.1",
17+
"gamma-pytools ~=2.0",
1818
"matplotlib ~=3.0",
1919
"numpy >=1.21,<2a", # cannot use ~= due to conda bug
2020
"packaging >=20",
21-
"pandas >=1,<2a", # cannot use ~= due to conda bug
21+
"pandas ~=1.0",
2222
"scipy ~=1.2",
23-
"shap >=0.34,<0.41a",
24-
"sklearndf ~=2.0.dev3",
23+
"shap >=0.34,<0.42a",
24+
"sklearndf ~=2.0",
2525
]
2626

2727
requires-python = ">=3.7,<4a"
@@ -82,7 +82,7 @@ pandas = "~=1.0.5"
8282
python = ">=3.7.12,<3.8a" # cannot use ~= due to conda bug
8383
scipy = "~=1.4.1"
8484
shap = "~=0.34.0"
85-
sklearndf = "~=2.0.dev3"
85+
sklearndf = "~=2.0.0"
8686
# additional minimum requirements of sklearndf
8787
boruta = "~=0.3.0"
8888
lightgbm = "~=3.0.0"
@@ -93,18 +93,19 @@ joblib = "~=0.14.1"
9393
typing_inspect = "~=0.4.0"
9494
# additional minimum requirements of shap
9595
ipython = "==7.0"
96+
numba = "~=0.55" # required to support numpy 1.21
9697

9798
[build.matrix.max]
9899
# direct requirements of gamma-facet
99100
gamma-pytools = "~=2.0,>=2.0.1"
100101
matplotlib = "~=3.5"
101-
numpy = ">=1.23,<2a" # cannot use ~= due to conda bug
102+
numpy = ">=1.22,<2a" # cannot use ~= due to conda bug
102103
packaging = ">=20"
103104
pandas = "~=1.4"
104105
python = ">=3.8.10,<4a" # cannot use ~= due to conda bug
105106
scipy = "~=1.8"
106-
shap = "~=0.40.0"
107-
sklearndf = ">=2.0.dev3,<3a"
107+
shap = "~=0.41"
108+
sklearndf = "~=2.0"
108109
# additional maximum requirements of sklearndf
109110
boruta = "~=0.3"
110111
lightgbm = "~=3.3"
@@ -115,6 +116,7 @@ joblib = "~=1.1"
115116
typing_inspect = "~=0.7"
116117
# additional maximum requirements of shap
117118
ipython = ">=7"
119+
numba = ">=0.55.2" # required to support numpy 1.22
118120

119121
[tool.black]
120122
# quiet = "True"

src/facet/data/_sample.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181
observation
8282
"""
8383

84-
def _ensure_columns_exist(column_type: str, columns: List[str]):
84+
def _ensure_columns_exist(column_type: str, columns: List[str]) -> None:
8585
# check if all provided feature names actually exist in the observations df
8686
available_columns: pd.Index = observations.columns
8787
missing_columns = {
@@ -273,25 +273,25 @@ def subsample(
273273
)
274274
return subsample
275275

276-
def keep(self, *, feature_names: Union[str, Collection[str]]) -> "Sample":
276+
def keep(self, *, feature_names: Union[str, Iterable[str]]) -> "Sample":
277277
"""
278278
Return a new sample which only includes the features with the given names.
279279
280280
:param feature_names: name(s) of the features to be selected
281281
:return: copy of this sample, containing only the features with the given names
282282
"""
283283

284-
feature_names: List[str] = to_list(feature_names, element_type=str)
284+
feature_names_list: List[str] = to_list(feature_names, element_type=str)
285285

286-
if not set(feature_names).issubset(self._feature_names):
286+
if not set(feature_names_list).issubset(self._feature_names):
287287
raise ValueError(
288288
"arg feature_names is not a subset of the features in this sample"
289289
)
290290

291291
subsample = copy(self)
292-
subsample._feature_names = feature_names
292+
subsample._feature_names = feature_names_list
293293

294-
columns = [*feature_names, *self._target_names]
294+
columns = [*feature_names_list, *self._target_names]
295295
weight = self._weight_name
296296
if weight and weight not in columns:
297297
columns.append(weight)
@@ -306,17 +306,17 @@ def drop(self, *, feature_names: Union[str, Collection[str]]) -> "Sample":
306306
:param feature_names: name(s) of the features to be dropped
307307
:return: copy of this sample, excluding the features with the given names
308308
"""
309-
feature_names: Set[str] = to_set(feature_names, element_type=str)
309+
feature_names_set: Set[str] = to_set(feature_names, element_type=str)
310310

311-
unknown = feature_names.difference(self._feature_names)
311+
unknown = feature_names_set.difference(self._feature_names)
312312
if unknown:
313313
raise ValueError(f"unknown features in arg feature_names: {unknown}")
314314

315315
return self.keep(
316316
feature_names=[
317317
feature
318318
for feature in self._feature_names
319-
if feature not in feature_names
319+
if feature not in feature_names_set
320320
]
321321
)
322322

0 commit comments

Comments
 (0)