Skip to content

Commit f5c69f6

Browse files
committed
MNT: do without try...except blocks
1 parent aa66aee commit f5c69f6

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lib/matplotlib/image.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,11 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
372372

373373
# we need these try/except blocks to handle
374374
# fully-masked/invalid input
375-
try:
376-
a_min = a_min.astype(scaled_dtype)
377-
except AttributeError:
378-
a_min = 0
379-
try:
380-
a_max = a_max.astype(scaled_dtype)
381-
except AttributeError:
382-
a_min = 1
375+
if np.ma.count(A) == 0:
376+
a_min, a_max = 0, 1 # all masked, so values don't matter
377+
else:
378+
a_min = np.ma.min(A).astype(scaled_dtype)
379+
a_max = np.ma.max(A).astype(scaled_dtype)
383380
# scale the input data to [.1, .9]. The Agg
384381
# interpolators clip to [0, 1] internally, use a
385382
# smaller input scale to identify which of the

0 commit comments

Comments
 (0)