Skip to content

Commit

Permalink
Added a fill_value keyword to MaskedArray.view, and clarify the b…
Browse files Browse the repository at this point in the history
…ehavior in the docstring.
  • Loading branch information
astrofrog committed Nov 20, 2012
1 parent 3e99f32 commit 2a43ed3
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions numpy/ma/core.py
Expand Up @@ -2852,7 +2852,16 @@ def __array_wrap__(self, obj, context=None):
return result 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 dtype is None:
if type is None: if type is None:
output = ndarray.view(self) output = ndarray.view(self)
Expand Down Expand Up @@ -2882,10 +2891,13 @@ def view(self, dtype=None, type=None):
pass pass
# Make sure to reset the _fill_value if needed # Make sure to reset the _fill_value if needed
if getattr(output, '_fill_value', None) is not None: if getattr(output, '_fill_value', None) is not None:
if dtype is None: if fill_value is None:
pass # leave _fill_value as is if dtype is None:
pass # leave _fill_value as is
else:
output._fill_value = None
else: else:
output._fill_value = None output._fill_value = fill_value
return output return output
view.__doc__ = ndarray.view.__doc__ view.__doc__ = ndarray.view.__doc__


Expand Down

0 comments on commit 2a43ed3

Please sign in to comment.