[SciPy-user] Record Array: How to add a column?

Pierre GM pgmdevlist at gmail.com
Tue Oct 14 13:14:22 EDT 2008


John,
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 
need.

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 
my drift...


P.


> 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 [217]: !cat test2.csv
>   date,age,name
>   2008-01-01,10,'tom'
>   2008-01-02,11,'dick'
>   2008-01-03,,'harry'
>   In [218]: type(r2)
>   Out[218]: <class 'numpy.ma.mrecords.MaskedRecords'>
>
>   In [219]: print r2.dtype
>   [('date', '|O4'), ('age', '<i4'), ('name', '|S7')]
>
>   In [220]: r2[0].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?
>
> Thanks,
> JDH
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user





More information about the SciPy-User mailing list