Skip to content

Commit 8c3ad29

Browse files
efiringtacaswell
authored andcommitted
Handle min, max of possibly all-masked array
1 parent 07eaa4c commit 8c3ad29

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

lib/matplotlib/image.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -368,21 +368,14 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
368368
scaled_dtype = A.dtype
369369
else:
370370
scaled_dtype = np.float32
371-
# old versions of numpy do not work with `np.nammin`
372-
# and `np.nanmax` as inputs
373-
a_min = np.ma.min(A)
374-
a_max = np.ma.max(A)
375-
376-
# we need these try/except blocks to handle
377-
# fully-masked/invalid input
378-
try:
371+
372+
a_min = A.min()
373+
if a_min is np.ma.masked:
374+
a_min, a_max = 0, 1 # all masked, so values don't matter
375+
else:
379376
a_min = a_min.astype(scaled_dtype)
380-
except AttributeError:
381-
a_min = 0
382-
try:
383-
a_max = a_max.astype(scaled_dtype)
384-
except AttributeError:
385-
a_min = 1
377+
a_max = A.max().astype(scaled_dtype)
378+
386379
# scale the input data to [.1, .9]. The Agg
387380
# interpolators clip to [0, 1] internally, use a
388381
# smaller input scale to identify which of the

0 commit comments

Comments
 (0)