Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 815d10a

Browse files
committed
Removed assertion from test case due to platform-specific behaviour. Changed warning to only emit on downcast from float96 or float128. Simplified condition
1 parent 095281d commit 815d10a

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

lib/matplotlib/image.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,11 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
363363
if inp_dtype.kind == 'f':
364364
scaled_dtype = A.dtype
365365
# Cast to float64
366-
if (A.dtype == np.longdouble
367-
or (not (A.dtype == np.float64
368-
or A.dtype == np.float32
369-
or A.dtype == np.float16))):
366+
if not (A.dtype == np.float32 or A.dtype == np.float16):
370367
if (A.dtype != np.float64):
371368
warnings.warn(
372-
'Casting input data to float64 for imshow.'
373-
)
369+
"Casting input data from '{0}' to 'float64'"
370+
"for imshow".format(A.dtype))
374371
scaled_dtype = np.float64
375372
else:
376373
# probably an integer of some type.

lib/matplotlib/tests/test_image.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -903,12 +903,8 @@ def test_empty_imshow(make_norm):
903903
def test_imshow_float128():
904904
fig, ax = plt.subplots()
905905
ax.imshow(np.zeros((3, 3), dtype=np.longdouble))
906-
# Ensure that drawing doesn't cause crash and warning message
907-
with warnings.catch_warnings(record=True) as warns:
908-
warnings.simplefilter("always")
909-
fig.canvas.draw()
910-
assert len(warns) == 1
911-
assert "Casting input data to float64 for imshow." in str(warns[-1].message)
906+
# Ensure that drawing doesn't cause crash
907+
fig.canvas.draw()
912908

913909

914910
def test_imshow_bool():

0 commit comments

Comments
 (0)