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

Skip to content

Commit ce98e8f

Browse files
efiringanntzer
authored andcommitted
Improve readability of _combine_masks()
1 parent 09ff3df commit ce98e8f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,21 +1117,22 @@ def _combine_masks(*args):
11171117
if is_scalar_or_string(args[0]):
11181118
raise ValueError("First argument must be a sequence")
11191119
nrecs = len(args[0])
1120-
margs = []
1121-
seqlist = [False] * len(args)
1122-
masks = [] # list of masks that are True where bad
1120+
margs = [] # Output args; some may be modified.
1121+
seqlist = [False] * len(args) # Flags: True if output will be masked.
1122+
masks = [] # List of masks.
11231123
for i, x in enumerate(args):
1124-
if not isinstance(x, str) and np.iterable(x) and len(x) == nrecs:
1125-
if isinstance(x, np.ma.MaskedArray):
1126-
if x.ndim > 1:
1127-
raise ValueError("Masked arrays must be 1-D")
1124+
if is_scalar_or_string(x) or len(x) != nrecs:
1125+
margs.append(x) # Leave it unmodified.
1126+
else:
1127+
if isinstance(x, np.ma.MaskedArray) and x.ndim > 1:
1128+
raise ValueError("Masked arrays must be 1-D")
11281129
x = np.asanyarray(x)
11291130
if x.ndim == 1:
11301131
x = safe_masked_invalid(x)
11311132
seqlist[i] = True
11321133
if np.ma.is_masked(x):
11331134
masks.append(np.ma.getmaskarray(x))
1134-
margs.append(x)
1135+
margs.append(x) # Possibly modified.
11351136
if len(masks):
11361137
mask = np.logical_or.reduce(masks)
11371138
for i, x in enumerate(margs):

0 commit comments

Comments
 (0)