Skip to content

Commit 121b876

Browse files
stop relying on np.bool
1 parent f673026 commit 121b876

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

Diff for: packages/python/plotly/plotly/express/_imshow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _infer_zmax_from_type(img):
5050
elif im_max <= 65535 * rtol:
5151
return 65535
5252
else:
53-
return 2**32
53+
return 2 ** 32
5454

5555

5656
def imshow(
@@ -351,7 +351,7 @@ def imshow(
351351
binary_string = img.ndim >= (3 + slice_dimensions) and not is_dataframe
352352

353353
# Cast bools to uint8 (also one byte)
354-
if img.dtype == np.bool:
354+
if img.dtype == bool:
355355
img = 255 * img.astype(np.uint8)
356356

357357
if range_color is not None:

Diff for: packages/python/plotly/plotly/tests/test_optional/test_px/test_imshow.py

+7-17
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ def test_zmax():
4545

4646
def test_automatic_zmax_from_dtype():
4747
dtypes_dict = {
48-
np.uint8: 2**8 - 1,
49-
np.uint16: 2**16 - 1,
48+
np.uint8: 2 ** 8 - 1,
49+
np.uint16: 2 ** 16 - 1,
5050
np.float: 1,
51-
np.bool: 255,
51+
bool: 255,
5252
}
5353
for key, val in dtypes_dict.items():
5454
img = np.array([0, 1], dtype=key)
5555
img = np.dstack((img,) * 3)
5656
fig = px.imshow(img, binary_string=False)
5757
# For uint8 in "infer" mode we don't pass zmin/zmax unless specified
58-
if key in [np.uint8, np.bool]:
58+
if key in [np.uint8, bool]:
5959
assert fig.data[0]["zmax"] is None
6060
else:
6161
assert fig.data[0]["zmax"] == (val, val, val, 255)
@@ -195,9 +195,7 @@ def test_imshow_xarray_slicethrough():
195195

196196

197197
def test_imshow_labels_and_ranges():
198-
fig = px.imshow(
199-
[[1, 2], [3, 4], [5, 6]],
200-
)
198+
fig = px.imshow([[1, 2], [3, 4], [5, 6]],)
201199
assert fig.layout.xaxis.title.text is None
202200
assert fig.layout.yaxis.title.text is None
203201
assert fig.layout.coloraxis.colorbar.title.text is None
@@ -386,11 +384,7 @@ def test_facet_col(facet_col, binary_string):
386384
@pytest.mark.parametrize("binary_string", [False, True])
387385
def test_animation_frame_grayscale(animation_frame, binary_string):
388386
img = np.random.randint(255, size=(10, 9, 8)).astype(np.uint8)
389-
fig = px.imshow(
390-
img,
391-
animation_frame=animation_frame,
392-
binary_string=binary_string,
393-
)
387+
fig = px.imshow(img, animation_frame=animation_frame, binary_string=binary_string,)
394388
nslices = img.shape[animation_frame]
395389
assert len(fig.frames) == nslices
396390

@@ -399,11 +393,7 @@ def test_animation_frame_grayscale(animation_frame, binary_string):
399393
@pytest.mark.parametrize("binary_string", [False, True])
400394
def test_animation_frame_rgb(animation_frame, binary_string):
401395
img = np.random.randint(255, size=(10, 9, 8, 3)).astype(np.uint8)
402-
fig = px.imshow(
403-
img,
404-
animation_frame=animation_frame,
405-
binary_string=binary_string,
406-
)
396+
fig = px.imshow(img, animation_frame=animation_frame, binary_string=binary_string,)
407397
nslices = img.shape[animation_frame]
408398
assert len(fig.frames) == nslices
409399

0 commit comments

Comments
 (0)