Skip to content

Adding Series._repr_html_ #16888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

AllenDowney
Copy link
Contributor

@AllenDowney AllenDowney commented Jul 11, 2017

This is intended to close #5563 by adding Series._repr_html_
As suggested by previous discussion, the HTML representation of a Series looks different from the representation of a DataFrame, specifically by omitting the <thead> row, which (for a DataFrame) contains the column names.
I've tested it in a Jupyter notebook; I can provide a screenshot if someone suggests the best way to do that.

  • closes Series do not display HTML repr #5563
  • tests added / passed
  • passes git diff upstream/master --name-only -- '*.py' | flake8 --diff (On Windows, git diff upstream/master -u -- "*.py" | flake8 --diff might work as an alternative.)
  • whatsnew entry

@jreback
Copy link
Contributor

jreback commented Jul 12, 2017

can you add some tests. also pls show a screen shot (with a series & dataframe of same)

@jreback jreback added the Output-Formatting __repr__ of pandas objects, to_string label Jul 12, 2017
@AllenDowney
Copy link
Contributor Author

Here's a demo that shows what it looks like.

https://github.com/AllenDowney/pandas/blob/master/series_html_demo.ipynb

@jreback
Copy link
Contributor

jreback commented Jul 12, 2017

can you update your notebook to add name to the Series, and names to the indexes (both for Series and DataFrame), just to show where they are printing.

@jreback jreback added the IO HTML read_html, to_html, Styler.apply, Styler.applymap label Jul 12, 2017
@AllenDowney
Copy link
Contributor Author

The current version strips the header, so if the series has a name or if the index of the series has a name, they don't appear. Assuming that's not the desired behavior, let's talk about what the desired behavior is. Would you agree:

  1. If the series has a name, it should appear.
  2. If the index of the series has a name, it should appear.
  3. The HTML representation of a Series should look different from a DataFrame.

In that case, maybe a different approach would be to change the style of the table rather than the content. What do we think of:

  1. Adding a border to the HTML repr of a DataFrame.
  2. Omit the border for a Series.

So the visual distinction is that DataFrames will have borders and Series will not.

Thoughts?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jul 12, 2017

I think the name and dtype in a caption at the bottom would be preferred. Something like

screen shot 2017-07-12 at 11 41 54 am

(with better styling of course). Since DataFrames put the column names above, I think this will be visually distinct enough.

If the index is named, that can stay in the table header.

@AllenDowney
Copy link
Contributor Author

AllenDowney commented Jul 12, 2017 via email

@AllenDowney
Copy link
Contributor Author

BTW is anyone at SciPy and interested in talking about this or working on it?

@TomAugspurger
Copy link
Contributor

@AllenDowney yeah that'd be great. I'm in the lightning talks right now, but perhaps we can sit down sometime later in the week?

@jreback
Copy link
Contributor

jreback commented Jul 12, 2017

I think the impl should follow how we do DataFrame output itself. It might be a bit of code duplication, but way more flexibility that post-processing the html.

@AllenDowney
Copy link
Contributor Author

AllenDowney commented Jul 13, 2017

@TomAugspurger and @phobson and I spoke this afternoon. We are leaning toward a quick implementation by calling DataFrame._repr_html_ and then making changes to the HTML. Not using lxml, though; that definitely seems like overkill. But with just a few lines of code we can add a caption with the name of the Series and the dtype, and it should be pretty robust.

@jreback, you are right that a real implementation would be better, but I think this is a case where a good enough solution is very easy, and the best solution is substantially harder.

@jreback
Copy link
Contributor

jreback commented Sep 7, 2017

closing as stale. I think we need a full fledged impl here.

@jreback jreback closed this Sep 7, 2017
@TomAugspurger
Copy link
Contributor

Whoops, this one fell off my radar. I think we had a decent way that avoids too much duplication. I'll see if I can find that branch.

@jreback
Copy link
Contributor

jreback commented Sep 7, 2017

ok feel free to reopen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series do not display HTML repr
3 participants