Skip to content

Commit cab4a12

Browse files
DerWehpaulbkoch
andauthored
MNT: Clean typehints (#634)
* DEV: bump ruff's Python version Signed-off-by: DerWeh <andreas.weh@web.de> * BUG: use correct argument to load json from file Signed-off-by: DerWeh <andreas.weh@web.de> * MNT: update deprecated typing imports Signed-off-by: DerWeh <andreas.weh@web.de> --------- Signed-off-by: DerWeh <andreas.weh@web.de> Signed-off-by: Paul Koch <46825734+paulbkoch@users.noreply.github.com> Co-authored-by: Paul Koch <46825734+paulbkoch@users.noreply.github.com>
1 parent 99a755f commit cab4a12

File tree

2 files changed

+46
-45
lines changed

2 files changed

+46
-45
lines changed

python/interpret-core/interpret/glassbox/_ebm/_ebm.py

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
import logging
77
import os
8+
from collections.abc import Callable, Mapping, Sequence
89
from contextlib import nullcontext
910
from copy import deepcopy
1011
from dataclasses import dataclass, field
@@ -13,7 +14,7 @@
1314
from math import ceil, isnan
1415
from multiprocessing.managers import SharedMemoryManager
1516
from operator import itemgetter
16-
from typing import Callable, Dict, List, Mapping, Optional, Sequence, Tuple, Union
17+
from typing import Optional, Union
1718
from warnings import warn
1819

1920
import numpy as np
@@ -1950,7 +1951,7 @@ def _from_json(self, file):
19501951
UNTESTED_from_jsonable(self, jsonable)
19511952
else:
19521953
# file is a file-like object implementing .read()
1953-
jsonable = json.load(fp)
1954+
jsonable = json.load(file)
19541955
UNTESTED_from_jsonable(self, jsonable)
19551956
return self
19561957

@@ -3220,23 +3221,23 @@ class ExplainableBoostingClassifier(ClassifierMixin, EBMModel):
32203221
"""
32213222

32223223
n_features_in_: int
3223-
term_names_: List[str]
3224-
bins_: List[Union[List[Dict[str, int]], List[np.ndarray]]] # np.float64, 1D[cut]
3225-
feature_names_in_: List[str]
3226-
feature_types_in_: List[str]
3224+
term_names_: list[str]
3225+
bins_: list[Union[list[dict[str, int]], list[np.ndarray]]] # np.float64, 1D[cut]
3226+
feature_names_in_: list[str]
3227+
feature_types_in_: list[str]
32273228
feature_bounds_: np.ndarray # np.float64, 2D[feature, min_max]
3228-
term_features_: List[Tuple[int, ...]]
3229-
bin_weights_: List[np.ndarray] # np.float64, [bin0...]
3230-
bagged_scores_: List[np.ndarray] # np.float64, [bag, bin0..., ?class]
3231-
term_scores_: List[np.ndarray] # np.float64, [bin0..., ?class]
3232-
standard_deviations_: List[np.ndarray] # np.float64, [bin0..., ?class]
3229+
term_features_: list[tuple[int, ...]]
3230+
bin_weights_: list[np.ndarray] # np.float64, [bin0...]
3231+
bagged_scores_: list[np.ndarray] # np.float64, [bag, bin0..., ?class]
3232+
term_scores_: list[np.ndarray] # np.float64, [bin0..., ?class]
3233+
standard_deviations_: list[np.ndarray] # np.float64, [bin0..., ?class]
32333234
link_: str
32343235
link_param_: float
32353236
bag_weights_: np.ndarray # np.float64, 1D[bag]
32363237
best_iteration_: np.ndarray # np.int64, 2D[stage, bag]
32373238

3238-
histogram_edges_: List[Union[None, np.ndarray]] # np.float64, 1D[hist_edge]
3239-
histogram_weights_: List[np.ndarray] # np.float64, 1D[hist_bin]
3239+
histogram_edges_: list[Union[None, np.ndarray]] # np.float64, 1D[hist_edge]
3240+
histogram_weights_: list[np.ndarray] # np.float64, 1D[hist_bin]
32403241
unique_val_counts_: np.ndarray # np.int64, 1D[feature]
32413242

32423243
classes_: np.ndarray # np.int64, np.bool_, or np.unicode_, 1D[class]
@@ -3730,23 +3731,23 @@ class ExplainableBoostingRegressor(RegressorMixin, EBMModel):
37303731
"""
37313732

37323733
n_features_in_: int
3733-
term_names_: List[str]
3734-
bins_: List[Union[List[Dict[str, int]], List[np.ndarray]]] # np.float64, 1D[cut]
3735-
feature_names_in_: List[str]
3736-
feature_types_in_: List[str]
3734+
term_names_: list[str]
3735+
bins_: list[Union[list[dict[str, int]], list[np.ndarray]]] # np.float64, 1D[cut]
3736+
feature_names_in_: list[str]
3737+
feature_types_in_: list[str]
37373738
feature_bounds_: np.ndarray # np.float64, 2D[feature, min_max]
3738-
term_features_: List[Tuple[int, ...]]
3739-
bin_weights_: List[np.ndarray] # np.float64, [bin0...]
3740-
bagged_scores_: List[np.ndarray] # np.float64, [bag, bin0...]
3741-
term_scores_: List[np.ndarray] # np.float64, [bin0...]
3742-
standard_deviations_: List[np.ndarray] # np.float64, [bin0...]
3739+
term_features_: list[tuple[int, ...]]
3740+
bin_weights_: list[np.ndarray] # np.float64, [bin0...]
3741+
bagged_scores_: list[np.ndarray] # np.float64, [bag, bin0...]
3742+
term_scores_: list[np.ndarray] # np.float64, [bin0...]
3743+
standard_deviations_: list[np.ndarray] # np.float64, [bin0...]
37433744
link_: str
37443745
link_param_: float
37453746
bag_weights_: np.ndarray # np.float64, 1D[bag]
37463747
best_iteration_: np.ndarray # np.int64, 2D[stage, bag]
37473748

3748-
histogram_edges_: List[Union[None, np.ndarray]] # np.float64, 1D[hist_edge]
3749-
histogram_weights_: List[np.ndarray] # np.float64, 1D[hist_bin]
3749+
histogram_edges_: list[Union[None, np.ndarray]] # np.float64, 1D[hist_edge]
3750+
histogram_weights_: list[np.ndarray] # np.float64, 1D[hist_bin]
37503751
unique_val_counts_: np.ndarray # np.int64, 1D[feature]
37513752

37523753
intercept_: float
@@ -4007,16 +4008,16 @@ class DPExplainableBoostingClassifier(ClassifierMixin, EBMModel):
40074008
"""
40084009

40094010
n_features_in_: int
4010-
term_names_: List[str]
4011-
bins_: List[Union[List[Dict[str, int]], List[np.ndarray]]] # np.float64, 1D[cut]
4012-
feature_names_in_: List[str]
4013-
feature_types_in_: List[str]
4011+
term_names_: list[str]
4012+
bins_: list[Union[list[dict[str, int]], list[np.ndarray]]] # np.float64, 1D[cut]
4013+
feature_names_in_: list[str]
4014+
feature_types_in_: list[str]
40144015
feature_bounds_: np.ndarray # np.float64, 2D[feature, min_max]
4015-
term_features_: List[Tuple[int, ...]]
4016-
bin_weights_: List[np.ndarray] # np.float64, [bin]
4017-
bagged_scores_: List[np.ndarray] # np.float64, [bag, bin]
4018-
term_scores_: List[np.ndarray] # np.float64, [bin]
4019-
standard_deviations_: List[np.ndarray] # np.float64, [bin]
4016+
term_features_: list[tuple[int, ...]]
4017+
bin_weights_: list[np.ndarray] # np.float64, [bin]
4018+
bagged_scores_: list[np.ndarray] # np.float64, [bag, bin]
4019+
term_scores_: list[np.ndarray] # np.float64, [bin]
4020+
standard_deviations_: list[np.ndarray] # np.float64, [bin]
40204021
link_: str
40214022
link_param_: float
40224023
bag_weights_: np.ndarray # np.float64, 1D[bag]
@@ -4062,7 +4063,7 @@ def __init__(
40624063
composition: str = "gdp",
40634064
bin_budget_frac: float = 0.1,
40644065
privacy_bounds: Optional[
4065-
Union[np.ndarray, Mapping[Union[int, str], Tuple[float, float]]]
4066+
Union[np.ndarray, Mapping[Union[int, str], tuple[float, float]]]
40664067
] = None,
40674068
):
40684069
super().__init__(
@@ -4344,16 +4345,16 @@ class DPExplainableBoostingRegressor(RegressorMixin, EBMModel):
43444345
"""
43454346

43464347
n_features_in_: int
4347-
term_names_: List[str]
4348-
bins_: List[Union[List[Dict[str, int]], List[np.ndarray]]] # np.float64, 1D[cut]
4349-
feature_names_in_: List[str]
4350-
feature_types_in_: List[str]
4348+
term_names_: list[str]
4349+
bins_: list[Union[list[dict[str, int]], list[np.ndarray]]] # np.float64, 1D[cut]
4350+
feature_names_in_: list[str]
4351+
feature_types_in_: list[str]
43514352
feature_bounds_: np.ndarray # np.float64, 2D[feature, min_max]
4352-
term_features_: List[Tuple[int, ...]]
4353-
bin_weights_: List[np.ndarray] # np.float64, [bin0...]
4354-
bagged_scores_: List[np.ndarray] # np.float64, [bag, bin0..., ?class]
4355-
term_scores_: List[np.ndarray] # np.float64, [bin0..., ?class]
4356-
standard_deviations_: List[np.ndarray] # np.float64, [bin0..., ?class]
4353+
term_features_: list[tuple[int, ...]]
4354+
bin_weights_: list[np.ndarray] # np.float64, [bin0...]
4355+
bagged_scores_: list[np.ndarray] # np.float64, [bag, bin0..., ?class]
4356+
term_scores_: list[np.ndarray] # np.float64, [bin0..., ?class]
4357+
standard_deviations_: list[np.ndarray] # np.float64, [bin0..., ?class]
43574358
link_: str
43584359
link_param_: float
43594360
bag_weights_: np.ndarray # np.float64, 1D[bag]
@@ -4401,7 +4402,7 @@ def __init__(
44014402
composition: str = "gdp",
44024403
bin_budget_frac: float = 0.1,
44034404
privacy_bounds: Optional[
4404-
Union[np.ndarray, Mapping[Union[int, str], Tuple[float, float]]]
4405+
Union[np.ndarray, Mapping[Union[int, str], tuple[float, float]]]
44054406
] = None,
44064407
privacy_target_min: Optional[float] = None,
44074408
privacy_target_max: Optional[float] = None,

ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# match oldest supported version
2-
target-version = "py38"
2+
target-version = "py39"
33
[lint]
44
extend-select = [
55
"B", # flake8-bugbear

0 commit comments

Comments
 (0)