Skip to content

Commit bb78d2e

Browse files
shaneahmedJohn-P
andauthored
⬆️ Upgrade numpy Dependency (#543)
- np.int, np.bool, np.float is depreciated in v1.20 in favour of np.int_, np.bool_, np.float_ Waiting on some dependencies to update: - numba not yet compatible with numpy 1.24 > from numba.np.ufunc import _internal E SystemError: initialization of _internal failed without raising an exception - numba/numba#8464 - numba/numba#8691 - numba/numba#8841 - https://github.com/numba/numba/milestone/63 - [x] Waiting for next numba release with numpy 1.24 support. --------- Co-authored-by: John Pocock <[email protected]>
1 parent 28c52bf commit bb78d2e

File tree

8 files changed

+17
-14
lines changed

8 files changed

+17
-14
lines changed

requirements/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ imagecodecs>=2022.9.26
99
joblib>=1.1.1
1010
jupyterlab>=3.5.2
1111
matplotlib>=3.6.2
12-
numpy>=1.23.5, <1.24 # v1.24 produces error on Windows
12+
numba>=0.57.0
13+
numpy>=1.23.5
1314
opencv-python>=4.6.0
1415
openslide-python>=1.2.0
1516
pandas>=2.0.0

tests/models/test_patch_predictor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ def test_patch_dataset_crash(tmp_path):
134134
_ = PatchDataset(imgs)
135135

136136
# ndarray of mixed dtype
137-
imgs = np.array([np.random.randint(0, 255, (4, 5, 3)), "Should crash"])
137+
imgs = np.array(
138+
[np.random.randint(0, 255, (4, 5, 3)), "Should crash"], dtype=object
139+
)
138140
with pytest.raises(ValueError, match="Provided input array is non-numerical."):
139141
_ = PatchDataset(imgs)
140142

tests/test_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_imresize():
5252
# test for dtype conversion, pairs of
5353
# (original type, converted type)
5454
test_dtypes = [
55-
(np.bool, np.uint8),
55+
(np.bool_, np.uint8),
5656
(np.int8, np.int16),
5757
(np.int16, np.int16),
5858
(np.int32, np.float32),
@@ -1053,8 +1053,8 @@ def edge_mask(bounds: Tuple[int, int, int, int]) -> np.ndarray:
10531053
l, t, r, b = bounds
10541054
slide_width, slide_height = slide_dimensions
10551055
x, y = np.meshgrid(np.arange(l, r), np.arange(t, b), indexing="ij")
1056-
under = np.logical_or(x < 0, y < 0).astype(np.int)
1057-
over = np.logical_or(x >= slide_width, y >= slide_height).astype(np.int)
1056+
under = np.logical_or(x < 0, y < 0).astype(np.int_)
1057+
over = np.logical_or(x >= slide_width, y >= slide_height).astype(np.int_)
10581058
return under, over
10591059

10601060
loc = (-5, -5)

tests/test_wsireader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def read_bounds_level_consistency(wsi, bounds):
186186
# from interpolation when calculating the downsampled levels. This
187187
# adds some tolerance for the comparison.
188188
blurred = [cv2.GaussianBlur(img, (5, 5), cv2.BORDER_REFLECT) for img in resized]
189-
as_float = [img.astype(np.float) for img in blurred]
189+
as_float = [img.astype(np.float_) for img in blurred]
190190

191191
# Pair-wise check resolutions for mean squared error
192192
for i, a in enumerate(as_float):
@@ -2373,7 +2373,7 @@ def test_read_rect_level_consistency(sample_key, reader_class, kwargs):
23732373
# from interpolation when calculating the downsampled levels. This
23742374
# adds some tolerance for the comparison.
23752375
blurred = [cv2.GaussianBlur(img, (5, 5), cv2.BORDER_REFLECT) for img in resized]
2376-
as_float = [img.astype(np.float) for img in blurred]
2376+
as_float = [img.astype(np.float_) for img in blurred]
23772377

23782378
# Pair-wise check resolutions for mean squared error
23792379
for i, a in enumerate(as_float):

tiatoolbox/tools/registration/wsi_registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def compute_feature_distances(
486486
axis=len(features_x.shape),
487487
)
488488

489-
feature_size_2d = np.int(np.sqrt(feature_distance.shape[0]))
489+
feature_size_2d = np.int_(np.sqrt(feature_distance.shape[0]))
490490
ref_feature_size_2d = factor * feature_size_2d
491491
feature_size, ref_feature_size = feature_size_2d**2, ref_feature_size_2d**2
492492
feature_grid = np.kron(

tiatoolbox/utils/metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def dice(gt_mask, pred_mask):
9090
if gt_mask.shape != pred_mask.shape:
9191
raise ValueError(f'{"Shape mismatch between the two masks."}')
9292

93-
gt_mask = gt_mask.astype(np.bool)
94-
pred_mask = pred_mask.astype(np.bool)
93+
gt_mask = gt_mask.astype(np.bool_)
94+
pred_mask = pred_mask.astype(np.bool_)
9595
sum_masks = gt_mask.sum() + pred_mask.sum()
9696
if sum_masks == 0:
9797
return np.NAN

tiatoolbox/utils/transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def imresize(img, scale_factor=None, output_size=None, interpolation="optimise")
112112
# error). The `converted type` has been selected so that
113113
# they can maintain the numeric precision of the `original type`.
114114
dtype_mapping = [
115-
(np.bool, np.uint8),
115+
(np.bool_, np.uint8),
116116
(np.int8, np.int16),
117117
(np.int16, np.int16),
118118
(np.int32, np.float32),

tiatoolbox/wsicore/wsireader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,15 +911,15 @@ def _find_tile_params(
911911
level = np.log2(rescale)
912912
if not level.is_integer():
913913
raise ValueError
914-
level = np.int(level)
914+
level = np.int_(level)
915915
slide_dimension = self.info.level_dimensions[level]
916916
rescale = 1
917917
# Raise index error if desired pyramid level not embedded
918918
# in level_dimensions
919919
except IndexError:
920920
level = 0
921921
slide_dimension = self.info.level_dimensions[level]
922-
rescale = np.int(rescale)
922+
rescale = np.int_(rescale)
923923
logger.warning(
924924
"Reading WSI at level 0. Desired tile_objective_value %s "
925925
"not available.",
@@ -2508,7 +2508,7 @@ def _info(self):
25082508
box = glymur_wsi.box
25092509
description = box[3].xml.find("description")
25102510
matches = re.search(r"(?<=AppMag = )\d\d", description.text)
2511-
objective_power = np.int(matches[0])
2511+
objective_power = np.int_(matches[0])
25122512
image_header = box[2].box[0]
25132513
slide_dimensions = (image_header.width, image_header.height)
25142514

0 commit comments

Comments
 (0)