def generic_masked(arr, attrs=None, minv=None, maxv=None, mask_nan=True):
attrs = attrs or {}<EOL>if '<STR_LIT>' in attrs:<EOL><INDENT>minv = safe_attribute_typing(arr.dtype, attrs['<STR_LIT>'])<EOL><DEDENT>if '<STR_LIT>' in attrs:<EOL><INDENT>maxv = safe_attribute_typing(arr.dtype, attrs['<STR_LIT>'])<EOL><DEDENT>if '<STR_LIT>' in attrs:<EOL><INDENT>vr = attrs['<STR_LIT>']<EOL>minv = safe_attribute_typing(arr.dtype, vr[<NUM_LIT:0>])<EOL>maxv = safe_attribute_typing(arr.dtype, vr[<NUM_LIT:1>])<EOL><DEDENT>try:<EOL><INDENT>info = np.iinfo(arr.dtype)<EOL><DEDENT>except ValueError:<EOL><INDENT>info = np.finfo(arr.dtype)<EOL><DEDENT>minv = minv if minv is not None else info.min<EOL>maxv = maxv if maxv is not None else info.max<EOL>if mask_nan is True:<EOL><INDENT>arr = np.ma.fix_invalid(arr)<EOL><DEDENT>return np.ma.masked_outside(<EOL>arr,<EOL>minv,<EOL>maxv<EOL>)<EOL>
Returns a masked array with anything outside of values masked.
The minv and maxv parameters take precendence over any dict values.
The valid_range attribute takes precendence over the valid_min and
valid_max attributes.