[SciPy-user] Record Array: How to add a column?
Tue Oct 14 12:14:22 CDT 2008
MaskedRecords have always been the poor lost child of MaskedArrays. In 1.3.x
and 1.2.1, I tried to improve the support of flexible-type, and MaskedRecords
should follow. Of course, I can only check whether it works in the cases I
Could you send me a self-contained example showing what you expect (example +
class definitions...) ?
My guess here is that when you query the field date on a standard 'recarray',
you get a date object, which has a 'year' attribute. However, when you query
it as a MaskedRecords, the 'date' column is transformed into a MaskedArray
(in order to handle missing data), and then you can't directly access
the 'year' attribute: you'd need to access 'date._data.year' instead.
Once again, that's a very first guess, I'd need to do some testing.
On a side note, TimeSeries objects support flexible type as well, if you catch
> In the next example, the data file has a missing value on the last row
> in the 'age' column, so we return a masked record array
> In : !cat test2.csv
> In : type(r2)
> Out: <class 'numpy.ma.mrecords.MaskedRecords'>
> In : print r2.dtype
> [('date', '|O4'), ('age', '<i4'), ('name', '|S7')]
> In : r2.date.year
> Traceback (most recent call last):
> File "<ipython console>", line 1, in ?
> AttributeError: 'MaskedArray' object has no attribute 'year'
> It would help us a lot in this regard if we could access the
> underlying object. Is there a reason why the masked array behaves
> differently when it comes to accessing the underlying object methods
> and is there a sensible way to make them compatible?
> SciPy-user mailing list
More information about the SciPy-user