Skip to content

Update Row repr to be consistent with Table repr - #4066

Merged
embray merged 2 commits into
astropy:masterfrom
taldcroft:table-row-repr
Aug 10, 2015
Merged

embray merged 2 commits into
astropy:masterfrom
taldcroft:table-row-repr

Conversation

@taldcroft

Copy link
Copy Markdown
Member

This updates the Row representation to be consistent with the corresponding Table representation for that row. It also adds HTML representation so a row displays nicely in IPython notebook.

The one substantive difference between the Row and Table repr is that for Row the max_width is set to -1, corresponding to no limit on the width. I think that when examining a Row is it more natural to get all the values even if it ends up wrapping. Also a row object has no pformat or pprint methods so there would be no way to get the full set of values for a wide table. Of course we could add those methods, but I don't think there is a huge need in this case.

@embray

embray commented Aug 10, 2015

Copy link
Copy Markdown
Member

To me it's not terribly natural to represent a single row as though it were a single-row table with all the column headings, etc. But I could see the argument for it.

@taldcroft

Copy link
Copy Markdown
Member Author

@embray - I find the current repr (and str) completely useless:

>>> t = simple_table(cols=20)
>>> t[1]
<Row 1 of table
 values=(2, 2.0, 'd', 5, 5.0, 'g', 8, 8.0, 'j', 11, 11.0, 'm', 14, 14.0, 'p', 
17, 17.0, 's', 20, 20.0)
 dtype=[('a', '<i4'), ('b', '<f4'), ('c', 'S1'), ('d', '<i4'), ('e', '<f4'), ('f', 'S1'), 
('g', '<i4'), ('h', '<f4'), ('i', 'S1'), ('j', '<i4'), ('k', '<f4'), ('l', 'S1'), ('m', '<i4'), 
('n', '<f4'), ('o', 'S1'), ('p', '<i4'), ('q', '<f4'), ('r', 'S1'), ('s', '<i4'), ('t', '<f4')]>

From a coding (and thinking) perspective the new look was the simplest and fastest, but if you have any other ideas I'm happy to listen.
image
I like the fact that you get units now.

@embray

embray commented Aug 10, 2015

Copy link
Copy Markdown
Member

My personal preference is still for something more tuple-like, with units inline with the numeric values. But I'll give you that--this is definitely better than the existing situation 👍

@taldcroft

Copy link
Copy Markdown
Member Author

That's interesting and definitely makes me think about it. I still worry that once you get beyond a handful of columns that it gets difficult to represent the name, type, value, and unit in a way that lets the user quickly associate all those for a single column.

@embray

embray commented Aug 10, 2015

Copy link
Copy Markdown
Member

Yeah, you're probably right. I don't have any better ideas.

embray added a commit that referenced this pull request Aug 10, 2015
Update Row repr to be consistent with Table repr
@embray
embray merged commit acf26d3 into astropy:master Aug 10, 2015
@taldcroft
taldcroft deleted the table-row-repr branch August 10, 2015 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants