Skip to content

initial HTML rendering for Series #29248

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 6 commits into from
Closed

Conversation

big-o
Copy link

@big-o big-o commented Oct 27, 2019

Added to_html() and repr_html() to Series class.

@pep8speaks
Copy link

pep8speaks commented Oct 27, 2019

Hello @big-o! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-10-28 20:38:39 UTC

)
return formatter.to_html(notebook=True)
else:
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this warn/raise?

Copy link
Author

@big-o big-o Oct 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure - I just copied this behaviour from DataFrame._repr_html_() for consistency. Happy to change it if preferred, but if we do that then should the DataFrame behaviour also be changed?

@@ -226,7 +226,79 @@ def to_string(self) -> str:
return str("\n".join(result))


class SeriesFormatter:
class TableFormatter:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason this is moved up from below?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - the SeriesFormatter now inherits from TableFormatter, meaning it needs to be declared first.

@jbrockmendel
Copy link
Member

Can you add test(s) for this

@WillAyd
Copy link
Member

WillAyd commented Oct 28, 2019

Any chance you took a look at #27228 prior to this? Haven't reviewed in detail yet but just surprised this is a much larger change than that one. May or may not be an issue just curious

@WillAyd WillAyd added the IO HTML read_html, to_html, Styler.apply, Styler.applymap label Oct 28, 2019
@big-o
Copy link
Author

big-o commented Oct 28, 2019

Any chance you took a look at #27228 prior to this? Haven't reviewed in detail yet but just surprised this is a much larger change than that one. May or may not be an issue just curious

Yes I can see why - the implementation by @mrocklin is just calling to_frame, then tweaking the HTML representation to look more like a series. This implementation creates a SeriesFormatter which basically does the same thing as a DataFrameFormatter but assumes only one column, and creates different footer information (to mirror the to_string info). I went with this route because it didn't feel right to me to convert the series into a more complex object just to get some HTML rendering.

Edit: This PR also adds in support for to_html, rather than just repr_html.

I'll freely admit that there's a lot of repeated code between the SeriesFormatter and the DataFrameFormatter - I think that if the DataFrameFormatter was refactored into something more generic then most of this duplication could be removed, making the PR a lot smaller. But I only had a few hours to spare on this hence not wanting to make too many changes to existing code, especially on a project I've never done any dev work on before.

The only other difference really is the aesthetics. In my impl, the footer information sits outside of the HTML table rather than within it. It also uses some different formatting to highlight different bits of information:
series1a

If you'd rather see the extra refactoring done to reduce the total amount of code then that's probably more effort than I can afford right now, but if you're happy with the current approach then I can do the remaining work needed to fix old/add new unit tests.

Alternatively, if you prefer the appearance of my solution but the smaller footprint of the other PR, then I could modify that PR to use my footer logic instead.

@WillAyd
Copy link
Member

WillAyd commented Oct 31, 2019

The problem with a PR of this size is that it is difficult to review and adds a lot of code duplication. If there is no way to do this without copy / pasting a lot of code, can you alternately just try to implement repr_html first and then we can address the rest in a follow up PR? Seems like that may be an easier path to go down

@big-o
Copy link
Author

big-o commented Oct 31, 2019

That's understandable, but I don't think my changes would be much different by implementing just _repr_html_. The bulk of my work is in the SeriesFormatter and HTMLFromatter classes.

If you'd prefer a smaller change to start with, I think #27228 is basically what you'd end up with. If you'd like me to contribute what you see in the screenshots above, I'd say the best way is to branch off #27228 and make some small changes to it. I'd be happy to do this if you agree that's a good way forward?

I should also add that I'm sure it is possible to do the complete piece of work without the code duplication, but I don't have the time or the knowledge of the existing code to do that right now.

@WillAyd
Copy link
Member

WillAyd commented Nov 1, 2019

I'd say the best way is to branch off #27228 and make some small changes to it. I'd be happy to do this if you agree that's a good way forward?

Yea I would suggest that first. It seems to be in line with what the commentary was on that PR was as well, that just that one piece first would make sense instead of tackling all at once

@big-o
Copy link
Author

big-o commented Nov 3, 2019

Have submitted a new PR based on this conversation, #29383, to supercede this one.

@big-o big-o mentioned this pull request Nov 3, 2019
5 tasks
@big-o big-o closed this Nov 3, 2019
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series do not display HTML repr
4 participants