[Numpy-discussion] pretty printing record array element - datetime

Travis Oliphant oliphant.travis at ieee.org
Tue May 15 19:00:21 EDT 2007


John Hunter wrote:
> I have a numpy record array and I want to pretty print a single
> element.  I was trying to loop over the names in the element dtype and
> use getattr to access the field value, but I got fouled up because
> getattr is trying to access the dtype attribute of one of the python
> objects (datetime.date) that I am storing in the record array.  The
> problem field in the example below is ('fiscaldate', '|O4') which is a
> python datetime.date object.
>   

Ah!  This is a bug introduced a long time ago when we decided to get rid 
of the "object-data-type" array scalars.  I'm working on a fix.

> In other news, would it be possible to add a pprint method to record
> array elements that did something like the pprint_element below?  It
> would be nice to be able to do tr.pprint() and get nice output which
> shows key/value pairs.
>   

That is easy enough to do and I have no objection.

-Travis




More information about the NumPy-Discussion mailing list