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: add long and short captions to Styler.to_latex #41659

Merged
merged 9 commits into from
Jun 4, 2021

Conversation

attack68
Copy link
Contributor

completes an item on the list for DataFrame.to_latex deprecation #41649

@attack68 attack68 changed the title add long and short captions to Styler.to_latex ENH: add long and short captions to Styler.to_latex May 25, 2021
@attack68 attack68 requested a review from ivanovmg May 25, 2021 07:58
@simonjayhawkins simonjayhawkins added Enhancement Styler conditional formatting using DataFrame.style labels May 25, 2021
Copy link
Member

@ivanovmg ivanovmg left a comment

Choose a reason for hiding this comment

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

Minor comment from my side.
By the way, I am not an expert in html rendering, so I cannot provide a review on the html related changes.


def test_long_captions(styler):
result = styler.to_latex(caption=("short cap", "long cap"))
assert "\\caption[short cap]{long cap}" in result
Copy link
Member

Choose a reason for hiding this comment

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

Can you replicate the existing behavior as here https://github.com/pandas-dev/pandas/pull/35668/files?
Currently in DataFrame.to_latex we can pass a string full_caption or a tuple (full_caption, short_caption).
In your code it is vice versa (short_caption, full_caption).
Also I would rename this test function to test_short_caption, since it targets a feature of adding a short caption.
In addition, you would need to change the indices in the docstring as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. easy fix. should be ok now.

Copy link
Member

@ivanovmg ivanovmg left a comment

Choose a reason for hiding this comment

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

Looks good to me.
One should remember to add tests for short captions for longtables once those are implemented.

\caption{% raw %}{{% endraw %}{{caption}}{% raw %}}{% endraw %}

{% elif caption and caption is sequence %}
\caption[{{caption[1]}}]{% raw %}{{% endraw %}{{caption[0]}}{% raw %}}{% endraw %}
Copy link
Member

Choose a reason for hiding this comment

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

Please keep in mind that the same behavior should be implemented for longtable (once the longtables are implemented through the styler).

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

small comment. can you add this issue number to an existing whatsnew (for .to_latex stuff) ping on green

@@ -87,8 +87,8 @@ class Styler(StylerRenderer):
List of {selector: (attr, value)} dicts; see Notes.
uuid : str, default None
A unique identifier to avoid CSS collisions; generated automatically.
caption : str, default None
Caption to attach to the table.
caption : str, tuple, default None
Copy link
Contributor

Choose a reason for hiding this comment

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

would emphasize here and below tht this is (full caption, short caption)

@jreback jreback added this to the 1.3 milestone Jun 3, 2021
@jreback jreback merged commit 963561b into pandas-dev:master Jun 4, 2021
@jreback
Copy link
Contributor

jreback commented Jun 4, 2021

thanks

@attack68 attack68 deleted the to_latex_caption_enh branch June 4, 2021 18:10
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 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.

4 participants