[Numpy-discussion] mrecarray indexing behaviour

Joel Nothman jnothman@student.usyd.edu...
Sun Apr 7 03:45:13 CDT 2013


Hello all!

I am a bit confused by the behaviour of mrecarray:

>>> import numpy.ma.mrecords
>>> data = [(1, 'a'), (2, 'b')]
>>> ra = numpy.rec.fromrecords(data)
>>> mra = numpy.ma.mrecords.fromrecords(data)
>>> ra
rec.array([(1, 'a'), (2, 'b')],
      dtype=[('f0', '<i4'), ('f1', '|S1')])
>>> mra
masked_records(
    f0 : [1 2]
    f1 : [a b]
    fill_value : (999999, 'N')
              )
>>> for a in [ra, mra]:
...   for cname, cell in [('row first', a[0]['f1']), ('field first',
a['f1'][0])]:
...     print(type(a), cname, cell, type(cell), sep=', ')
...
<class 'numpy.core.records.recarray'>, row first, a, <type 'numpy.string_'>
<class 'numpy.core.records.recarray'>, field first, a, <type
'numpy.string_'>
<class 'numpy.ma.mrecords.MaskedRecords'>, row first, a, <class
'numpy.ma.core.MaskedArray'>
<class 'numpy.ma.mrecords.MaskedRecords'>, field first, a, <type
'numpy.string_'>

Why when I index an mrecarray by offset before field do I get a
zero-dimension MaskedArray instead of the object I get when indexing by
field then offset?

This seems strange behaviour. Is it documented?

It doesn't seem to be tested;
ma/tests/test_mrecords.py:79,87<https://github.com/numpy/numpy/blob/master/numpy/ma/tests/test_mrecords.py#L79>asserts
equality of value but says nothing about the types that should be
returned. Similarly:

>>> mra['f1'][0] == mra[0]['f1']
masked_array(data = True,
             mask = False,
       fill_value = True)

>>> type(mra['f1'][0]) == type(mra[0]['f1'])
False

I look forward to any explanation or clarification!

Thanks,

- Joel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130407/b965f6f9/attachment.html 


More information about the NumPy-Discussion mailing list