diff options
author | pierregm <pierregm@localhost> | 2008-10-19 23:37:05 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2008-10-19 23:37:05 +0000 |
commit | 696b880e3e19e9728d1bf6a0e42a945427bf8d01 (patch) | |
tree | 22f4c38dd01b0b70fdf822dde6139869c4961ab8 /numpy | |
parent | 56bb8eb8e604e0bd2ebf8ce8e02e3909963b28f0 (diff) | |
download | numpy-696b880e3e19e9728d1bf6a0e42a945427bf8d01.tar.gz |
__getattribute__ : make sure than a np.void is returned when retrieving the unmasked attribute of a single record.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/ma/mrecords.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/numpy/ma/mrecords.py b/numpy/ma/mrecords.py index b85c8281a..a175be2ba 100644 --- a/numpy/ma/mrecords.py +++ b/numpy/ma/mrecords.py @@ -199,25 +199,31 @@ class MaskedRecords(MaskedArray, object): 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) - _mask = _localdict.get('_mask', None) # Reset the object's mask + hasmasked = False + _mask = _localdict.get('_mask', None) 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 |