summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/release/1.10.0-notes.rst5
-rw-r--r--numpy/ma/core.py66
2 files changed, 29 insertions, 42 deletions
diff --git a/doc/release/1.10.0-notes.rst b/doc/release/1.10.0-notes.rst
index 50b1aa0b8..f60e87f8d 100644
--- a/doc/release/1.10.0-notes.rst
+++ b/doc/release/1.10.0-notes.rst
@@ -252,8 +252,9 @@ object arrays that were generated on Python 2.
MaskedArray support for more complicated base classes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Built-in assumptions that the baseclass behaved like a plain array are being
-removed. In particalur, setting and getting elements and ranges will respect
-baseclass overrides of ``__setitem__`` and ``__getitem__``.
+removed. In particular, setting and getting elements and ranges will respect
+baseclass overrides of ``__setitem__`` and ``__getitem__``, and arithmetic
+will respect overrides of ``__add__``, ``__sub__``, etc.
Changes
=======
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 877d07e02..8e14d7c1a 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3179,8 +3179,8 @@ class MaskedArray(ndarray):
"""Set the mask.
"""
- idtype = ndarray.__getattribute__(self, 'dtype')
- current_mask = ndarray.__getattribute__(self, '_mask')
+ idtype = self.dtype
+ current_mask = self._mask
if mask is masked:
mask = True
# Make sure the mask is set
@@ -3258,7 +3258,7 @@ class MaskedArray(ndarray):
A record is masked when all the fields are masked.
"""
- _mask = ndarray.__getattribute__(self, '_mask').view(ndarray)
+ _mask = self._mask.view(ndarray)
if _mask.dtype.names is None:
return _mask
return np.all(flatten_structured_array(_mask), axis= -1)
@@ -3695,7 +3695,7 @@ class MaskedArray(ndarray):
return masked
omask = getattr(other, '_mask', nomask)
if omask is nomask:
- check = ndarray.__eq__(self.filled(0), other)
+ check = self.filled(0).__eq__(other)
try:
check = check.view(type(self))
check._mask = self._mask
@@ -3704,7 +3704,7 @@ class MaskedArray(ndarray):
return check
else:
odata = filled(other, 0)
- check = ndarray.__eq__(self.filled(0), odata).view(type(self))
+ check = self.filled(0).__eq__(odata).view(type(self))
if self._mask is nomask:
check._mask = omask
else:
@@ -3728,7 +3728,7 @@ class MaskedArray(ndarray):
return masked
omask = getattr(other, '_mask', nomask)
if omask is nomask:
- check = ndarray.__ne__(self.filled(0), other)
+ check = self.filled(0).__ne__(other)
try:
check = check.view(type(self))
check._mask = self._mask
@@ -3737,7 +3737,7 @@ class MaskedArray(ndarray):
return check
else:
odata = filled(other, 0)
- check = ndarray.__ne__(self.filled(0), odata).view(type(self))
+ check = self.filled(0).__ne__(odata).view(type(self))
if self._mask is nomask:
check._mask = omask
else:
@@ -3831,10 +3831,8 @@ class MaskedArray(ndarray):
else:
if m is not nomask:
self._mask += m
- ndarray.__iadd__(
- self._data,
- np.where(self._mask, self.dtype.type(0), getdata(other))
- )
+ self._data.__iadd__(np.where(self._mask, self.dtype.type(0),
+ getdata(other)))
return self
#....
def __isub__(self, other):
@@ -3846,10 +3844,8 @@ class MaskedArray(ndarray):
self._mask += m
elif m is not nomask:
self._mask += m
- ndarray.__isub__(
- self._data,
- np.where(self._mask, self.dtype.type(0), getdata(other))
- )
+ self._data.__isub__(np.where(self._mask, self.dtype.type(0),
+ getdata(other)))
return self
#....
def __imul__(self, other):
@@ -3861,10 +3857,8 @@ class MaskedArray(ndarray):
self._mask += m
elif m is not nomask:
self._mask += m
- ndarray.__imul__(
- self._data,
- np.where(self._mask, self.dtype.type(1), getdata(other))
- )
+ self._data.__imul__(np.where(self._mask, self.dtype.type(1),
+ getdata(other)))
return self
#....
def __idiv__(self, other):
@@ -3879,10 +3873,8 @@ class MaskedArray(ndarray):
other_data = np.where(dom_mask, fval, other_data)
# self._mask = mask_or(self._mask, new_mask)
self._mask |= new_mask
- ndarray.__idiv__(
- self._data,
- np.where(self._mask, self.dtype.type(1), other_data)
- )
+ self._data.__idiv__(np.where(self._mask, self.dtype.type(1),
+ other_data))
return self
#....
def __ifloordiv__(self, other):
@@ -3897,10 +3889,8 @@ class MaskedArray(ndarray):
other_data = np.where(dom_mask, fval, other_data)
# self._mask = mask_or(self._mask, new_mask)
self._mask |= new_mask
- ndarray.__ifloordiv__(
- self._data,
- np.where(self._mask, self.dtype.type(1), other_data)
- )
+ self._data.__ifloordiv__(np.where(self._mask, self.dtype.type(1),
+ other_data))
return self
#....
def __itruediv__(self, other):
@@ -3915,10 +3905,8 @@ class MaskedArray(ndarray):
other_data = np.where(dom_mask, fval, other_data)
# self._mask = mask_or(self._mask, new_mask)
self._mask |= new_mask
- ndarray.__itruediv__(
- self._data,
- np.where(self._mask, self.dtype.type(1), other_data)
- )
+ self._data.__itruediv__(np.where(self._mask, self.dtype.type(1),
+ other_data))
return self
#...
def __ipow__(self, other):
@@ -3926,10 +3914,8 @@ class MaskedArray(ndarray):
other_data = getdata(other)
other_mask = getmask(other)
with np.errstate(divide='ignore', invalid='ignore'):
- ndarray.__ipow__(
- self._data,
- np.where(self._mask, self.dtype.type(1), other_data)
- )
+ self._data.__ipow__(np.where(self._mask, self.dtype.type(1),
+ other_data))
invalid = np.logical_not(np.isfinite(self._data))
if invalid.any():
if self._mask is not nomask:
@@ -4614,7 +4600,7 @@ class MaskedArray(ndarray):
<type 'numpy.int64'>
"""
- _mask = ndarray.__getattribute__(self, '_mask')
+ _mask = self._mask
newmask = _check_mask_axis(_mask, axis)
# No explicit output
if out is None:
@@ -4742,7 +4728,7 @@ class MaskedArray(ndarray):
array([ 2., 12.])
"""
- _mask = ndarray.__getattribute__(self, '_mask')
+ _mask = self._mask
newmask = _check_mask_axis(_mask, axis)
# No explicit output
if out is None:
@@ -5258,7 +5244,7 @@ class MaskedArray(ndarray):
Returns the minimum filling value for a given datatype.
"""
- _mask = ndarray.__getattribute__(self, '_mask')
+ _mask = self._mask
newmask = _check_mask_axis(_mask, axis)
if fill_value is None:
fill_value = minimum_fill_value(self)
@@ -5357,7 +5343,7 @@ class MaskedArray(ndarray):
Returns the maximum filling value for a given datatype.
"""
- _mask = ndarray.__getattribute__(self, '_mask')
+ _mask = self._mask
newmask = _check_mask_axis(_mask, axis)
if fill_value is None:
fill_value = maximum_fill_value(self)
@@ -5682,7 +5668,7 @@ class MaskedArray(ndarray):
"""
(_, shp, typ, isf, raw, msk, flv) = state
- ndarray.__setstate__(self, (shp, typ, isf, raw))
+ super(MaskedArray, self).__setstate__((shp, typ, isf, raw))
self._mask.__setstate__((shp, make_mask_descr(typ), isf, msk))
self.fill_value = flv
#