Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Added a `fill_value` keyword to `MaskedArray.view`, and clarify the b…

…ehavior in the docstring.
  • Loading branch information...
commit 2a43ed339f1350872207b9871ebdc3fbd0a68d26 1 parent 3e99f32
@astrofrog astrofrog authored
Showing with 16 additions and 4 deletions.
  1. +16 −4 numpy/ma/
20 numpy/ma/
@@ -2852,7 +2852,16 @@ def __array_wrap__(self, obj, context=None):
return result
- def view(self, dtype=None, type=None):
+ def view(self, dtype=None, type=None, fill_value=None):
+ """
+ Return a view of the MaskedArray
+ If `fill_value` is not specified, but `dtype` is specified, the
+ `fill_value` of the MaskedArray will be reset. If neither `fill_value`
+ nor `dtype` are specified, then the fill value is preserved. Finally,
+ if `fill_value` is specified, but `dtype` is not, the fill value is
+ set to the specified value.
+ """
if dtype is None:
if type is None:
output = ndarray.view(self)
@@ -2882,10 +2891,13 @@ def view(self, dtype=None, type=None):
# Make sure to reset the _fill_value if needed
if getattr(output, '_fill_value', None) is not None:
- if dtype is None:
- pass # leave _fill_value as is
+ if fill_value is None:
+ if dtype is None:
+ pass # leave _fill_value as is
+ else:
+ output._fill_value = None
- output._fill_value = None
+ output._fill_value = fill_value
return output
view.__doc__ = ndarray.view.__doc__
Please sign in to comment.
Something went wrong with that request. Please try again.