API: Styler copy
, export
, use
, clear
methods purpose and implementation
#40675
Labels
API Design
Master Tracker
High level tracker for similar issues
Styler
conditional formatting using DataFrame.style
PR Tracking
Styler.export
#43318)Styler.export
#43318)Post
The 4 methods attached to Styler have weakly defined purposes and implementation. Some recent PRs have sought to address this
[#40664 and #39975] but none go all the way.
So lets define a purpose:
export
anduse
are designed to work together to transfer all non-data dependent styles from one Styler to another.copy
aims to recreate a new Styler object which contains the same data and styles as the original.clear
only operates on a single instance and seeks to set it to a default state.How does this work in practice with the different Styler attributes:
Non-Ambiguous Attributes
Fully Data Dependent: should be copied but not exported.
Non-Data Dependent: should be copied and exported
Ambiguous Attributes
The
apply
andapplymap
methods operate by default in a non-data dependent way and optionally become data dependent when thesubset
argument is used or if the functions given are somehow data dependent themselves.Table styles provide a generic non-data dependent way of adding styles. It can also be data dependent when the CSS selectors target specific rows or colums that might depend on the data. For consistency we include in export and make the user deal with data dependency. (Since Tooltips add table styles dynamically at render time this will not be exported.)
not copiedcopied and not exportedThe uuid is an attribute designed specifically to avoid CSS clashes. It is preferable to have 2 objects with different uuids, and potentially erroneous for them to have the same, therefore we avoid copying or exporting the uuid.edit 14-august-2021: In order to use
to_html
with args without impacting thestyler
we must be able to fully copy astyler
including uuid: see #43034. Therefore this is copied.A caption is usually data-dependent, although not necessarily hence not exported.
Clearing
Some attributes can be provided at class instantiation, so "clearing" a Styler could be seen as reseting to these values. In order to do this, the instantiation variables need to be saved, which is unnecessary overhead. Another interpretation is that the Styler instantiation is rarely called specifically with args, and these can be seen as syntactic sugar for, instead calling a default Styler and then immediately applying the relevant modifiers.
Weighing these arguments it seems best to
clear
a Styler back to its default instantiation without any applied arguments.The most thorough and future proof clearing method might be to re-instantiate a new object, with default inputs:
The text was updated successfully, but these errors were encountered: