Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated documentation
to explain the css of chained concats
  • Loading branch information
tsvikas authored Nov 17, 2022
commit fe4be54911f279a1333c4ab9236097223a91ebb3
6 changes: 4 additions & 2 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ def concat(self, other: Styler) -> Styler:
original Styler
- ``css`` will be inherited from the original Styler, and the value of
keys ``data``, ``row_heading`` and ``row`` will be prepended with
``foot_``. If several stylers are chained, they will all have only one
``foot_`` prepended.
``foot0_``. If more concats are chained, their styles will be prepended
Copy link
Member

Choose a reason for hiding this comment

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

So if there is only 1 Styler, before foot_ would be prepended and now foot0_will be prepended?

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't appear to have been addressed (please don't resolve unresolved conversations)

Copy link
Contributor

Choose a reason for hiding this comment

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

When chaining multiple Stylers the CSS needs a unique identifier. Previously it was only possible to compound multiple styler concatenations:

styler1.concat(styler2.concat(styler3))

which resulted in CSS classes None, foot_ and foot_foot_.

When allowing chained stylers you need an integer id, so

styler1.concat(styler2).concat(styler3.concat(styler4)).concat(styler5)

results in None, foot0_, foot1_ and foot1_foot0_, foot2_.

The CSS classes were not documented in 1.5.0 previously and not exposed to the user.
Here they are now amended and documented.

Copy link
Member

Choose a reason for hiding this comment

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

So just to confirm, a result with foot_ wasn't visible to the user previously and wouldn't see that foot0_ would now be returned?

Copy link
Contributor

Choose a reason for hiding this comment

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

foot_ is returned as part of the HTML string in 1.5.0. All of the automatically generated styling CSS ids reference foot_ so that the rendered HTML table, including styles works correctly.

Now the HTML string returned will contain foot0_ and all the auto generated CSS ids will reference that instead.

Unless the user is specifically adding a CSS rule for foot either with an external stylesheet or using set_table_styles there will be no visible difference in the rendered HTML display, either in a JupyterLab or browser.

i.e.

styler2.applymap(lambda v: "color: red;") styler1.concat(styler2)

will display the same in both versions even though the CSS class names have been changed.

Copy link
Member

Choose a reason for hiding this comment

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

Okay thanks for the explanation!

with ``foot1_``, ''foot_2'', etc., and if a concatenated style have
another concatanated style, the second style will be prepended with
``foot{parent}_foot{child}_``.

A common use case is to concatenate user defined functions with
``DataFrame.agg`` or with described statistics via ``DataFrame.describe``.
Expand Down