[Numpy-svn] r5949 - trunk/numpy/ma
numpy-svn at scipy.org
numpy-svn at scipy.org
Sun Oct 19 19:37:07 EDT 2008
Author: pierregm
Date: 2008-10-19 18:37:05 -0500 (Sun, 19 Oct 2008)
New Revision: 5949
Modified:
trunk/numpy/ma/mrecords.py
Log:
__getattribute__ : make sure than a np.void is returned when retrieving the unmasked attribute of a single record.
Modified: trunk/numpy/ma/mrecords.py
===================================================================
--- trunk/numpy/ma/mrecords.py 2008-10-19 19:33:51 UTC (rev 5948)
+++ trunk/numpy/ma/mrecords.py 2008-10-19 23:37:05 UTC (rev 5949)
@@ -199,25 +199,31 @@
if obj.dtype.fields:
raise NotImplementedError("MaskedRecords is currently limited to"\
"simple records...")
- obj = obj.view(MaskedArray)
- obj._baseclass = ndarray
- obj._isfield = True
# Get some special attributes
- _fill_value = _localdict.get('_fill_value', None)
+ # Reset the object's mask
+ hasmasked = False
_mask = _localdict.get('_mask', None)
- # Reset the object's mask
if _mask is not None:
try:
- obj._mask = _mask[attr]
+ _mask = _mask[attr]
except IndexError:
# Couldn't find a mask: use the default (nomask)
pass
- # Reset the field values
- if _fill_value is not None:
- try:
- obj._fill_value = _fill_value[attr]
- except ValueError:
- obj._fill_value = None
+ hasmasked = _mask.view((np.bool,(len(_mask.dtype) or 1))).any()
+ if (obj.shape or hasmasked):
+ obj = obj.view(MaskedArray)
+ obj._baseclass = ndarray
+ obj._isfield = True
+ obj._mask = _mask
+ # Reset the field values
+ _fill_value = _localdict.get('_fill_value', None)
+ if _fill_value is not None:
+ try:
+ obj._fill_value = _fill_value[attr]
+ except ValueError:
+ obj._fill_value = None
+ else:
+ obj = obj.item()
return obj
More information about the Numpy-svn
mailing list