# afw table and record should have useful str() and repr()

XMLWordPrintable

#### Details

• Type: Bug
• Status: Done
• Resolution: Done
• Fix Version/s: None
• Component/s:
• Labels:
• Story Points:
2
• Sprint:
• Team:

#### Description

To see the contents of an afw table in python, you have to do something like

 catalog[0].extract("*")

which is totally not discoverable and returns a dict which doesn't print well. Much more useful would be for str() on a record to produce a pretty-printed list of the contents, and str() on a table to produce some nicely formatted summary (like a numpy recarray does, only printing a few things separated "..." for large tables).

I'm not sure what the best repr() output would be (certainly for a Record it should be a full dump of the contents), but currently table.repr()==table.str(), which is equally unhelpful.

Maybe this will come "for free" when we get astropy.table views, but it makes exploring the contents of a table a pain right now.

#### Activity

Hide
John Parejko added a comment -

Doing this as part of today's pair coding exercise.

Show
John Parejko added a comment - Doing this as part of today's pair coding exercise.
Hide
John Parejko added a comment -

Thanks to Krzysztof Findeisen for pair coding this with me. It's not a perfect implementation, but I think it's a huge improvement over the previous.

Nate Lust, can you please review this? I'm not sure how well it conforms to RFC-298, but I'm not sure what would be appropriate for that in the context of a catalog anyway.

Show
John Parejko added a comment - Thanks to Krzysztof Findeisen for pair coding this with me. It's not a perfect implementation, but I think it's a huge improvement over the previous. Nate Lust , can you please review this? I'm not sure how well it conforms to RFC-298 , but I'm not sure what would be appropriate for that in the context of a catalog anyway.
Hide
Colin Slater added a comment -

The other suggestion I was going to make before standup intervened is that it would be particularly useful if tables printed nicely in jupyter notebooks. I think that might be as easy as passing _repr_html_ on to astropy as well.

Show
Colin Slater added a comment - The other suggestion I was going to make before standup intervened is that it would be particularly useful if tables printed nicely in jupyter notebooks. I think that might be as easy as passing _repr_html_ on to astropy as well.
Hide
Nate Lust added a comment -

two minor points in the pr. Also, is it worth considering Colin's question on this ticket?

Show
Nate Lust added a comment - two minor points in the pr. Also, is it worth considering Colin's question on this ticket?
Hide
John Parejko added a comment -

Thanks for the review, and the offline discussion. I responded to your question about non-contiguous tables in the PR, but just to summarize here: we're probably better off not special casing lots of code to deal with our non-contiguous tables, but rather fixing those to behave better. So, they'll continue to be annoying to work with until we do that, at the savings of not having lots of extra code in the stack.

And I did add repr_html, so catalogs will automagically pretty-print in jupyter notebooks.

Merged and done.

Show
John Parejko added a comment - Thanks for the review, and the offline discussion. I responded to your question about non-contiguous tables in the PR, but just to summarize here: we're probably better off not special casing lots of code to deal with our non-contiguous tables, but rather fixing those to behave better. So, they'll continue to be annoying to work with until we do that, at the savings of not having lots of extra code in the stack. And I did add repr_html , so catalogs will automagically pretty-print in jupyter notebooks. Merged and done.

#### People

Assignee:
John Parejko
Reporter:
John Parejko
Reviewers:
Nate Lust
Watchers:
Colin Slater, Jim Bosch, John Parejko, John Swinbank, Nate Lust, Russell Owen, Simon Krughoff