Skip to content

Commit b798b1c

Browse files
authored
Merge pull request #21 from stephenpardy/fix_numpy_aliases
Remove outdated numpy aliases
2 parents 41a33b6 + c540e59 commit b798b1c

15 files changed

Lines changed: 52 additions & 52 deletions

File tree

fasttreeshap/_explanation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ def _compute_shape(x):
798798
if first_shape == tuple():
799799
return (len(x),)
800800
else: # we have an array of arrays...
801-
matches = np.ones(len(first_shape), dtype=np.bool)
801+
matches = np.ones(len(first_shape), dtype=bool)
802802
for i in range(1, len(x)):
803803
shape = _compute_shape(x[i])
804804
assert len(shape) == len(first_shape), "Arrays in Explanation objects must have consistent inner dimensions!"

fasttreeshap/datasets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def imdb(display=False): # pylint: disable=unused-argument
5353

5454
with open(cache(github_data_url + "imdb_train.txt")) as f:
5555
data = f.readlines()
56-
y = np.ones(25000, dtype=np.bool)
56+
y = np.ones(25000, dtype=bool)
5757
y[:12500] = 0
5858
return data, y
5959

@@ -71,7 +71,7 @@ def communitiesandcrime(display=False): # pylint: disable=unused-argument
7171

7272
# find the indices where the total violent crimes are known
7373
valid_inds = np.where(np.invert(np.isnan(raw_data.iloc[:,-2])))[0]
74-
y = np.array(raw_data.iloc[valid_inds,-2], dtype=np.float)
74+
y = np.array(raw_data.iloc[valid_inds,-2], dtype=float)
7575

7676
# extract the predictive features and remove columns with missing values
7777
X = raw_data.iloc[valid_inds,5:-18]

fasttreeshap/explainers/_explainer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def _compute_main_effects(fm, expected_value, inds):
291291
"""
292292

293293
# mask each input on in isolation
294-
masks = np.zeros(2*len(inds)-1, dtype=np.int)
294+
masks = np.zeros(2*len(inds)-1, dtype=int)
295295
last_ind = -1
296296
for i in range(len(inds)):
297297
if i > 0:

fasttreeshap/explainers/_tree.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def _validate_inputs(self, X, y, tree_limit, check_additivity):
291291
X = X.reshape(1, X.shape[0])
292292
if X.dtype != self.model.input_dtype:
293293
X = X.astype(self.model.input_dtype)
294-
X_missing = np.isnan(X, dtype=np.bool)
294+
X_missing = np.isnan(X, dtype=bool)
295295
assert isinstance(X, np.ndarray), "Unknown instance type: " + str(type(X))
296296
assert len(X.shape) == 2, "Passed input data matrix X must have 1 or 2 dimensions!"
297297

@@ -1182,7 +1182,7 @@ def predict(self, X, y=None, output=None, tree_limit=None):
11821182
X = X.reshape(1, X.shape[0])
11831183
if X.dtype.type != self.input_dtype:
11841184
X = X.astype(self.input_dtype)
1185-
X_missing = np.isnan(X, dtype=np.bool)
1185+
X_missing = np.isnan(X, dtype=bool)
11861186
assert isinstance(X, np.ndarray), "Unknown instance type: " + str(type(X))
11871187
assert len(X.shape) == 2, "Passed input data matrix X must have 1 or 2 dimensions!"
11881188

@@ -1602,8 +1602,8 @@ def __init__(self, xgb_model):
16021602

16031603
def get_trees(self, data=None, data_missing=None):
16041604
shape = (self.num_trees, self.num_nodes.max())
1605-
self.children_default = np.zeros(shape, dtype=np.int)
1606-
self.features = np.zeros(shape, dtype=np.int)
1605+
self.children_default = np.zeros(shape, dtype=int)
1606+
self.features = np.zeros(shape, dtype=int)
16071607
self.thresholds = np.zeros(shape, dtype=np.float32)
16081608
self.values = np.zeros((shape[0], shape[1], 1), dtype=np.float32)
16091609
trees = []

fasttreeshap/maskers/_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __call__(self, mask, x):
7676

7777
# if mask is not given then we mask the whole image
7878
if mask is None:
79-
mask = np.zeros(np.prod(x.shape), dtype=np.bool)
79+
mask = np.zeros(np.prod(x.shape), dtype=bool)
8080

8181
if isinstance(self.mask_value, str):
8282
if self.blur_kernel is not None:

fasttreeshap/maskers/_masker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ def _standardize_mask(self, mask, *args):
2020
shape = self.shape
2121

2222
if mask is True:
23-
return np.ones(shape[1], dtype=np.bool)
24-
return np.zeros(shape[1], dtype=np.bool)
23+
return np.ones(shape[1], dtype=bool)
24+
return np.zeros(shape[1], dtype=bool)
2525
return mask

fasttreeshap/maskers/_tabular.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(self, data, max_samples=100, clustering=None):
7878

7979
# self._last_mask = np.zeros(self.data.shape[1], dtype=np.bool)
8080
self._masked_data = data.copy()
81-
self._last_mask = np.zeros(data.shape[1], dtype=np.bool)
81+
self._last_mask = np.zeros(data.shape[1], dtype=bool)
8282
self.shape = self.data.shape
8383
self.supports_delta_masking = True
8484
# self._last_x = None
@@ -98,9 +98,9 @@ def __call__(self, mask, x):
9898
if np.issubdtype(mask.dtype, np.integer):
9999

100100
variants = ~self.invariants(x)
101-
curr_delta_inds = np.zeros(len(mask), dtype=np.int)
101+
curr_delta_inds = np.zeros(len(mask), dtype=int)
102102
num_masks = (mask >= 0).sum()
103-
varying_rows_out = np.zeros((num_masks, self.shape[0]), dtype=np.bool)
103+
varying_rows_out = np.zeros((num_masks, self.shape[0]), dtype=bool)
104104
masked_inputs_out = np.zeros((num_masks * self.shape[0], self.shape[1]))
105105
self._last_mask[:] = False
106106
self._masked_data[:] = self.data

fasttreeshap/maskers/_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def invariants(self, s):
291291
"""
292292
self._update_s_cache(s)
293293

294-
invariants = np.zeros(len(self._tokenized_s), dtype=np.bool)
294+
invariants = np.zeros(len(self._tokenized_s), dtype=bool)
295295
if self.keep_prefix > 0:
296296
invariants[:self.keep_prefix] = True
297297
if self.keep_suffix > 0:

fasttreeshap/plots/_group_difference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def group_difference(shap_values, group_mask, feature_names=None, xlabel=None, x
5151
diff = shap_values[group_mask].mean(0) - shap_values[~group_mask].mean(0)
5252

5353
if sort is True:
54-
inds = np.argsort(-np.abs(diff)).astype(np.int)
54+
inds = np.argsort(-np.abs(diff)).astype(int)
5555
else:
5656
inds = np.arange(len(diff))
5757

fasttreeshap/plots/_scatter.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ def scatter(shap_values, color="#1E88E5", hist=True, axis_color="#333333", cmap=
274274
interaction_feature_values = encode_array_if_needed(features[:, interaction_index])
275275
cv = interaction_feature_values
276276
cd = display_features[:, interaction_index]
277-
clow = np.nanpercentile(cv.astype(np.float), 5)
278-
chigh = np.nanpercentile(cv.astype(np.float), 95)
277+
clow = np.nanpercentile(cv.astype(float), 5)
278+
chigh = np.nanpercentile(cv.astype(float), 95)
279279
if clow == chigh:
280-
clow = np.nanmin(cv.astype(np.float))
281-
chigh = np.nanmax(cv.astype(np.float))
280+
clow = np.nanmin(cv.astype(float))
281+
chigh = np.nanmax(cv.astype(float))
282282
if type(cd[0]) == str:
283283
cname_map = {}
284284
for i in range(len(cv)):
@@ -290,8 +290,8 @@ def scatter(shap_values, color="#1E88E5", hist=True, axis_color="#333333", cmap=
290290

291291
# discritize colors for categorical features
292292
if categorical_interaction and clow != chigh:
293-
clow = np.nanmin(cv.astype(np.float))
294-
chigh = np.nanmax(cv.astype(np.float))
293+
clow = np.nanmin(cv.astype(float))
294+
chigh = np.nanmax(cv.astype(float))
295295
bounds = np.linspace(clow, chigh, min(int(chigh - clow + 2), cmap.N-1))
296296
color_norm = matplotlib.colors.BoundaryNorm(bounds, cmap.N-1)
297297

@@ -301,7 +301,7 @@ def scatter(shap_values, color="#1E88E5", hist=True, axis_color="#333333", cmap=
301301
if x_jitter > 1: x_jitter = 1
302302
xvals = xv.copy()
303303
if isinstance(xvals[0], float):
304-
xvals = xvals.astype(np.float)
304+
xvals = xvals.astype(float)
305305
xvals = xvals[~np.isnan(xvals)]
306306
xvals = np.unique(xvals) # returns a sorted array
307307
if len(xvals) >= 2:
@@ -628,11 +628,11 @@ def dependence_legacy(ind, shap_values=None, features=None, feature_names=None,
628628
interaction_feature_values = encode_array_if_needed(features[:, interaction_index])
629629
cv = interaction_feature_values
630630
cd = display_features[:, interaction_index]
631-
clow = np.nanpercentile(cv.astype(np.float), 5)
632-
chigh = np.nanpercentile(cv.astype(np.float), 95)
631+
clow = np.nanpercentile(cv.astype(float), 5)
632+
chigh = np.nanpercentile(cv.astype(float), 95)
633633
if clow == chigh:
634-
clow = np.nanmin(cv.astype(np.float))
635-
chigh = np.nanmax(cv.astype(np.float))
634+
clow = np.nanmin(cv.astype(float))
635+
chigh = np.nanmax(cv.astype(float))
636636
if type(cd[0]) == str:
637637
cname_map = {}
638638
for i in range(len(cv)):
@@ -644,8 +644,8 @@ def dependence_legacy(ind, shap_values=None, features=None, feature_names=None,
644644

645645
# discritize colors for categorical features
646646
if categorical_interaction and clow != chigh:
647-
clow = np.nanmin(cv.astype(np.float))
648-
chigh = np.nanmax(cv.astype(np.float))
647+
clow = np.nanmin(cv.astype(float))
648+
chigh = np.nanmax(cv.astype(float))
649649
bounds = np.linspace(clow, chigh, min(int(chigh - clow + 2), cmap.N-1))
650650
color_norm = matplotlib.colors.BoundaryNorm(bounds, cmap.N-1)
651651

@@ -654,7 +654,7 @@ def dependence_legacy(ind, shap_values=None, features=None, feature_names=None,
654654
if x_jitter > 1: x_jitter = 1
655655
xvals = xv.copy()
656656
if isinstance(xvals[0], float):
657-
xvals = xvals.astype(np.float)
657+
xvals = xvals.astype(float)
658658
xvals = xvals[~np.isnan(xvals)]
659659
xvals = np.unique(xvals) # returns a sorted array
660660
if len(xvals) >= 2:

0 commit comments

Comments
 (0)