Skip to content
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

ENH: styler.render.repr option #43180

Merged
merged 16 commits into from
Sep 1, 2021
Merged

Conversation

attack68
Copy link
Contributor

@attack68 attack68 commented Aug 23, 2021

offers option switching between "html" and "latex" output.

adds items to #41395.

also xref #39911 (technically after DataFrame.to_html is deprecated)

  • adds option
  • adds tests
  • updates options.rst docs
  • no public method docstrings
  • whatsnew

update to styler user guide as follow-on after all options are merged.

Screen Shot 2021-08-29 at 10 04 24

@attack68 attack68 marked this pull request as ready for review August 28, 2021 17:47
@attack68 attack68 changed the title WIP: ENH: styler.render.repr option to allow latex repr ENH: styler.render.repr option Aug 28, 2021
@@ -214,6 +214,8 @@ def _repr_html_(self) -> str:
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC aren't we supposed to have a _repr_latex_ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know. See if you prefer the new pattern, simple change.

"""
if get_option("styler.render.repr") == "latex":
Copy link
Contributor

Choose a reason for hiding this comment

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

do we actually still need this? or is this something controlled by the notebook itself?

Copy link
Contributor Author

@attack68 attack68 Sep 1, 2021

Choose a reason for hiding this comment

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

I tried to look this up, and I may be wrong but I think Notebook uses _repr_latex_ when converting the notebook to other formats, so it is useful.

When _repr_html_ and _repr_latex are present the notebook still renders the html version in browser. And I can't find docs on native iPython how to configure it to use the other. So the pandas options is userfriendly override (per issue)

@jreback jreback added Styler conditional formatting using DataFrame.style Enhancement labels Aug 31, 2021
@attack68
Copy link
Contributor Author

attack68 commented Sep 1, 2021

Have refactored this. This is the best, most generic pattern I think. When a _repr_ function returns None iPython moves on to the next mimetype. So here we are manually specifying only one _repr_mimetype_ to return a string.

@jreback jreback added this to the 1.4 milestone Sep 1, 2021
@jreback jreback merged commit ecaa78d into pandas-dev:master Sep 1, 2021
@jreback
Copy link
Contributor

jreback commented Sep 1, 2021

thanks I left the display issue open but xref

def _repr_latex_(self) -> str:
if get_option("styler.render.repr") == "latex":
return self.to_latex()
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.

@attack68 i think this is causing the mypy failures on CI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will take a look

@attack68 attack68 deleted the styler_latex_repr branch September 2, 2021 05:13
feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants