From 4a2f002eebd5289708af3a86fec22060e2de8bb8 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Thu, 5 Aug 2021 14:32:39 +0200 Subject: [PATCH 01/15] export and use refactor --- pandas/io/formats/style.py | 64 ++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 64b6de5722a56..137ca2bcdad26 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1418,9 +1418,9 @@ def set_table_attributes(self, attributes: str) -> Styler: self.table_attributes = attributes return self - def export(self) -> list[tuple[Callable, tuple, dict]]: + def export(self) -> dict(str, Any): """ - Export the styles applied to the current ``Styler``. + Export the styles applied to the current Styler. Can be applied to a second Styler with ``Styler.use``. @@ -1430,20 +1430,60 @@ def export(self) -> list[tuple[Callable, tuple, dict]]: See Also -------- - Styler.use: Set the styles on the current ``Styler``. + Styler.use: Set the styles on the current Styler. + Styler.copy: Create a copy of the current Styler. + + Notes + ----- + This method is designed to copy non-data dependent attributes of + one Styler to another. It differs from ``Styler.copy`` where data and + data dependent attributes are also copied. + + The following items are exported since they are not generally data dependent: + + - Styling functions added by the ``apply`` and ``applymap`` + - Whether axes are hidden from the display + - Table attributes + - Table styles + + The following attributes are considered data dependent and therefore not + exported: + + - Caption + - UUID + - Tooltips + - Any hidden rows or columns identified by Index labels + - Any formatting applied using ``Styler.format`` + - Any CSS classes added using ``Styler.set_td_classes`` """ - return self._todo + return { + "apply": self._todo, + "table_attributes": self.table_attributes, + "table_styles": self.table_styles, + "hide_index": self.hide_index_, + "hide_columns": self.hide_columns_, + } - def use(self, styles: list[tuple[Callable, tuple, dict]]) -> Styler: + def use(self, styles: dict(str, Any)) -> Styler: """ - Set the styles on the current ``Styler``. + Set the styles on the current Styler. Possibly uses styles from ``Styler.export``. Parameters ---------- - styles : list - List of style functions. + styles : dict(str, Any) + List of attributes to add to Styler. Dict keys should contain only: + - "apply": list of styler functions, typically added with ``apply`` or + ``applymap``. + - "table_attributes": HTML attributes, typically added with + ``set_table_attributes``. + - "table_styles": CSS seelctors and properties, typically added with + ``set_table_styles``. + - "hide_index": whether the index is hidden, typically added with + ``hide_index``. + - "hide_columns": whether column headers are hidden, typically added with + ``hide_columns``. Returns ------- @@ -1451,9 +1491,13 @@ def use(self, styles: list[tuple[Callable, tuple, dict]]) -> Styler: See Also -------- - Styler.export : Export the styles to applied to the current ``Styler``. + Styler.export : Export the non data dependent attributes to the current Styler. """ - self._todo.extend(styles) + self._todo.extend(styles.get("apply", [])) + self.set_table_attributes(styles.get("table_attributes", "")) + self.set_table_styles(styles.get("table_styles", [])) + self.hide_index_ = styles.get("hide_index", False) + self.hide_columns_ = styles.get("hide_columns", False) return self def set_uuid(self, uuid: str) -> Styler: From 3fed4ec302aaedd587cea43f9cac962194f92267 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sat, 7 Aug 2021 01:32:28 +0200 Subject: [PATCH 02/15] add tests --- pandas/tests/io/formats/style/test_style.py | 35 ++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index 6b084ecc2ca6c..098bcf38aff20 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -41,6 +41,7 @@ def mi_styler(mi_df): @pytest.fixture def mi_styler_comp(mi_styler): # comprehensively add features to mi_styler + mi_styler = mi_styler._copy(deepcopy=True) mi_styler.uuid_len = 5 mi_styler.uuid = "abcde_" mi_styler.set_caption("capt") @@ -260,6 +261,29 @@ def test_clear(mi_styler_comp): assert all(res) if hasattr(res, "__iter__") else res +def test_export(mi_styler_comp, mi_styler): + exp_attrs = [ + "_todo", + "hide_index_", + "hide_columns_", + "table_attributes", + "table_styles", + ] + for attr in exp_attrs: + check = getattr(mi_styler, attr) == getattr(mi_styler_comp, attr) + assert not ( + all(check) if (hasattr(check, "__iter__") and len(check) > 0) else check + ) + + export = mi_styler_comp.export() + used = mi_styler.use(export) + for attr in exp_attrs: + check = getattr(used, attr) == getattr(mi_styler_comp, attr) + assert all(check) if (hasattr(check, "__iter__") and len(check) > 0) else check + + used.to_html() + + def test_hide_raises(mi_styler): msg = "`subset` and `levels` cannot be passed simultaneously" with pytest.raises(ValueError, match=msg): @@ -937,17 +961,6 @@ def test_trim(self): result = self.df.style.highlight_max().render() assert result.count("#") == len(self.df.columns) - def test_export(self): - f = lambda x: "color: red" if x > 0 else "color: blue" - g = lambda x, z: f"color: {z}" if x > 0 else f"color: {z}" - style1 = self.styler - style1.applymap(f).applymap(g, z="b").highlight_max()._compute() # = render - result = style1.export() - style2 = self.df.style - style2.use(result) - assert style1._todo == style2._todo - style2.render() - def test_bad_apply_shape(self): df = DataFrame([[1, 2], [3, 4]]) msg = "returned the wrong shape" From 0ed2d4e7a5bb6465214370bc8b3bd74f80744f41 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (MBP)" Date: Tue, 31 Aug 2021 18:45:35 +0200 Subject: [PATCH 03/15] typing fix --- pandas/io/formats/style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index f1b5a23b7357f..eb7078aa42e4c 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1639,7 +1639,7 @@ def set_table_attributes(self, attributes: str) -> Styler: self.table_attributes = attributes return self - def export(self) -> dict(str, Any): + def export(self) -> dict[str, Any]: """ Export the styles applied to the current Styler. @@ -1685,7 +1685,7 @@ def export(self) -> dict(str, Any): "hide_columns": self.hide_columns_, } - def use(self, styles: dict(str, Any)) -> Styler: + def use(self, styles: dict[str, Any]) -> Styler: """ Set the styles on the current Styler. From 9af57546914ccaed5f9daad51c37394f4a5a04a4 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (MBP)" Date: Tue, 31 Aug 2021 21:31:35 +0200 Subject: [PATCH 04/15] test fixes --- pandas/io/formats/style.py | 7 +++++-- pandas/tests/io/formats/style/test_style.py | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index eb7078aa42e4c..8cd053593f691 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1715,8 +1715,11 @@ def use(self, styles: dict[str, Any]) -> Styler: Styler.export : Export the non data dependent attributes to the current Styler. """ self._todo.extend(styles.get("apply", [])) - self.set_table_attributes(styles.get("table_attributes", "")) - self.set_table_styles(styles.get("table_styles", [])) + table_attributes = self.table_attributes or "" + table_attributes += styles.get("table_attributes", "") + self.set_table_attributes(table_attributes) + if styles.get("table_styles"): + self.set_table_styles(styles.get("table_styles"), overwrite=False) self.hide_index_ = styles.get("hide_index", False) self.hide_columns_ = styles.get("hide_columns", False) return self diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index 3515f8c19d95b..b1ed3968ae9f9 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -207,6 +207,10 @@ def test_copy(comprehensive, render, deepcopy, mi_styler, mi_styler_comp): "cellstyle_map", # render time vars.. "cellstyle_map_columns", "cellstyle_map_index", + "template_latex", # render templates are class level + "template_html", + "template_html_style", + "template_html_table", ] if not deepcopy: # check memory locations are equal for all included attributes for attr in [a for a in styler.__dict__ if (not callable(a) and a not in excl)]: @@ -259,6 +263,10 @@ def test_clear(mi_styler_comp): "cellstyle_map_index", # execution time only "precision", # deprecated "na_rep", # deprecated + "template_latex", # render templates are class level + "template_html", + "template_html_style", + "template_html_table", ] # tests vars are not same vals on obj and clean copy before clear (except for excl) for attr in [a for a in styler.__dict__ if not (callable(a) or a in excl)]: From 081f043e95697203086c6b72f047de697e975515 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (MBP)" Date: Sun, 5 Sep 2021 00:47:37 +0200 Subject: [PATCH 05/15] fix tests --- pandas/io/formats/style.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 147626b42b8fe..64062b25d13b8 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1776,8 +1776,12 @@ def use(self, styles: dict[str, Any]) -> Styler: """ self._todo.extend(styles.get("apply", [])) table_attributes = self.table_attributes or "" - table_attributes += styles.get("table_attributes", "") - self.set_table_attributes(table_attributes) + obj_table_atts = ( + "" + if styles.get("table_attributes") is None + else styles.get("table_attributes") + ) + self.set_table_attributes((table_attributes + " " + obj_table_atts).strip()) if styles.get("table_styles"): self.set_table_styles(styles.get("table_styles"), overwrite=False) self.hide_index_ = styles.get("hide_index", False) From 0d0a1f90a28d0237c7495332c49df20646b7b354 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (MBP)" Date: Sun, 5 Sep 2021 00:53:26 +0200 Subject: [PATCH 06/15] fix tests / names --- pandas/io/formats/style.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 64062b25d13b8..04d1d1822f863 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1723,7 +1723,7 @@ def export(self) -> dict[str, Any]: The following items are exported since they are not generally data dependent: - Styling functions added by the ``apply`` and ``applymap`` - - Whether axes are hidden from the display + - Whether axes and names are hidden from the display - Table attributes - Table styles @@ -1743,6 +1743,8 @@ def export(self) -> dict[str, Any]: "table_styles": self.table_styles, "hide_index": self.hide_index_, "hide_columns": self.hide_columns_, + "hide_index_names": self.hide_index_names, + "hide_column_names": self.hide_column_names, } def use(self, styles: dict[str, Any]) -> Styler: @@ -1765,6 +1767,8 @@ def use(self, styles: dict[str, Any]) -> Styler: ``hide_index``. - "hide_columns": whether column headers are hidden, typically added with ``hide_columns``. + - "hide_index_names": whether index names are hidden. + - "hide_column_names" whether column header names are hidden. Returns ------- @@ -1786,6 +1790,8 @@ def use(self, styles: dict[str, Any]) -> Styler: self.set_table_styles(styles.get("table_styles"), overwrite=False) self.hide_index_ = styles.get("hide_index", False) self.hide_columns_ = styles.get("hide_columns", False) + self.hide_index_names = styles.get("hide_index_names", False) + self.hide_column_names = styles.get("hide_column_names", False) return self def set_uuid(self, uuid: str) -> Styler: From d5a3bd7389b526d76620e29e9f16cddf081e6481 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 19 Oct 2021 19:10:38 +0200 Subject: [PATCH 07/15] update tests --- pandas/io/formats/style.py | 8 ++++++-- pandas/tests/io/formats/style/test_style.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 1541d1f02dc80..80db98e4a7928 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1788,6 +1788,7 @@ def export(self) -> dict[str, Any]: "hide_columns": self.hide_columns_, "hide_index_names": self.hide_index_names, "hide_column_names": self.hide_column_names, + "css": self.css, } def use(self, styles: dict[str, Any]) -> Styler: @@ -1804,14 +1805,15 @@ def use(self, styles: dict[str, Any]) -> Styler: ``applymap``. - "table_attributes": HTML attributes, typically added with ``set_table_attributes``. - - "table_styles": CSS seelctors and properties, typically added with + - "table_styles": CSS selectors and properties, typically added with ``set_table_styles``. - "hide_index": whether the index is hidden, typically added with ``hide_index``. - "hide_columns": whether column headers are hidden, typically added with ``hide_columns``. - "hide_index_names": whether index names are hidden. - - "hide_column_names" whether column header names are hidden. + - "hide_column_names": whether column header names are hidden. + - "css": the css class names used. Returns ------- @@ -1835,6 +1837,8 @@ def use(self, styles: dict[str, Any]) -> Styler: self.hide_columns_ = styles.get("hide_columns", False) self.hide_index_names = styles.get("hide_index_names", False) self.hide_column_names = styles.get("hide_column_names", False) + if styles.get("css"): + self.css = styles.get("css") return self def set_uuid(self, uuid: str) -> Styler: diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index 2ac71f4b1fac8..a7a4970e33b15 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -337,9 +337,12 @@ def test_export(mi_styler_comp, mi_styler): exp_attrs = [ "_todo", "hide_index_", + "hide_index_names", "hide_columns_", + "hide_column_names", "table_attributes", "table_styles", + "css", ] for attr in exp_attrs: check = getattr(mi_styler, attr) == getattr(mi_styler_comp, attr) From 45b8cde4cb0687d2e16e676d9fe89ef82eea525c Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 19 Oct 2021 19:29:15 +0200 Subject: [PATCH 08/15] copy objects --- pandas/io/formats/style.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 80db98e4a7928..d471d57cdcadb 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1781,14 +1781,14 @@ def export(self) -> dict[str, Any]: - Any CSS classes added using ``Styler.set_td_classes`` """ return { - "apply": self._todo, + "apply": copy.copy(self._todo), "table_attributes": self.table_attributes, - "table_styles": self.table_styles, + "table_styles": copy.copy(self.table_styles), "hide_index": self.hide_index_, "hide_columns": self.hide_columns_, "hide_index_names": self.hide_index_names, "hide_column_names": self.hide_column_names, - "css": self.css, + "css": copy.copy(self.css), } def use(self, styles: dict[str, Any]) -> Styler: From 3d6b1355062ba3f8b14941edd3de5ea26151cc9f Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 19 Oct 2021 19:56:15 +0200 Subject: [PATCH 09/15] hidden levels adjustement --- doc/source/user_guide/style.ipynb | 8 ++++++-- pandas/io/formats/style.py | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/doc/source/user_guide/style.ipynb b/doc/source/user_guide/style.ipynb index 440cb85d1d6a6..5fe619c749d42 100644 --- a/doc/source/user_guide/style.ipynb +++ b/doc/source/user_guide/style.ipynb @@ -1380,8 +1380,12 @@ "metadata": {}, "outputs": [], "source": [ - "style1 = df2.style.applymap(style_negative, props='color:red;')\\\n", - " .applymap(lambda v: 'opacity: 20%;' if (v < 0.3) and (v > -0.3) else None)" + "style1 = df2.style\\\n", + " .applymap(style_negative, props='color:red;')\\\n", + " .applymap(lambda v: 'opacity: 20%;' if (v < 0.3) and (v > -0.3) else None)\\\n", + " .set_table_styles([{\"selector\": \"th\", \"props\": \"color: blue;\"}])\\\n", + " .hide_index()\n", + "style1" ] }, { diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index d471d57cdcadb..917414dd2df6f 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1766,7 +1766,7 @@ def export(self) -> dict[str, Any]: The following items are exported since they are not generally data dependent: - Styling functions added by the ``apply`` and ``applymap`` - - Whether axes and names are hidden from the display + - Whether axes and names are hidden from the display, if unambiguous. - Table attributes - Table styles @@ -1784,8 +1784,8 @@ def export(self) -> dict[str, Any]: "apply": copy.copy(self._todo), "table_attributes": self.table_attributes, "table_styles": copy.copy(self.table_styles), - "hide_index": self.hide_index_, - "hide_columns": self.hide_columns_, + "hide_index": all(self.hide_index_), + "hide_columns": all(self.hide_columns_), "hide_index_names": self.hide_index_names, "hide_column_names": self.hide_column_names, "css": copy.copy(self.css), @@ -1808,9 +1808,9 @@ def use(self, styles: dict[str, Any]) -> Styler: - "table_styles": CSS selectors and properties, typically added with ``set_table_styles``. - "hide_index": whether the index is hidden, typically added with - ``hide_index``. + ``hide_index``, or a boolean list for hidden levels. - "hide_columns": whether column headers are hidden, typically added with - ``hide_columns``. + ``hide_columns``, or a boolean list for hidden levels. - "hide_index_names": whether index names are hidden. - "hide_column_names": whether column header names are hidden. - "css": the css class names used. @@ -1833,8 +1833,16 @@ def use(self, styles: dict[str, Any]) -> Styler: self.set_table_attributes((table_attributes + " " + obj_table_atts).strip()) if styles.get("table_styles"): self.set_table_styles(styles.get("table_styles"), overwrite=False) - self.hide_index_ = styles.get("hide_index", False) - self.hide_columns_ = styles.get("hide_columns", False) + + for obj in ["index", "columns"]: + hide_obj = styles.get("hide_" + obj) + if hide_obj is not None: + if isinstance(hide_obj, bool): + n = getattr(self, obj).nlevels + setattr(self, "hide_" + obj + "_", [hide_obj] * n) + else: + setattr(self, "hide_" + obj + "_", hide_obj) + self.hide_index_names = styles.get("hide_index_names", False) self.hide_column_names = styles.get("hide_column_names", False) if styles.get("css"): From 6cb369ca0b5ee823022e7d6f3680d663e4f9d736 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Tue, 19 Oct 2021 20:01:11 +0200 Subject: [PATCH 10/15] whats new --- doc/source/whatsnew/v1.4.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 026429dabae84..2256a0cbfe91a 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -82,6 +82,7 @@ Styler - :meth:`Styler.to_html` omits CSSStyle rules for hidden table elements (:issue:`43619`) - Custom CSS classes can now be directly specified without string replacement (:issue:`43686`) - Bug where row trimming failed to reflect hidden rows (:issue:`43703`) + - Update and expand the export and use mechanics (:issue:`40675`) Formerly Styler relied on ``display.html.use_mathjax``, which has now been replaced by ``styler.html.mathjax``. From 89f17b4bdba0970dd45bc38bcc42f9f6dbcb6504 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Wed, 20 Oct 2021 17:38:16 +0200 Subject: [PATCH 11/15] fix merge --- pandas/io/formats/style.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 917414dd2df6f..2f244de1d75a8 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1824,11 +1824,11 @@ def use(self, styles: dict[str, Any]) -> Styler: Styler.export : Export the non data dependent attributes to the current Styler. """ self._todo.extend(styles.get("apply", [])) - table_attributes = self.table_attributes or "" - obj_table_atts = ( + table_attributes: str = self.table_attributes or "" + obj_table_atts: str = ( "" if styles.get("table_attributes") is None - else styles.get("table_attributes") + else str(styles.get("table_attributes")) ) self.set_table_attributes((table_attributes + " " + obj_table_atts).strip()) if styles.get("table_styles"): @@ -1846,7 +1846,7 @@ def use(self, styles: dict[str, Any]) -> Styler: self.hide_index_names = styles.get("hide_index_names", False) self.hide_column_names = styles.get("hide_column_names", False) if styles.get("css"): - self.css = styles.get("css") + self.css = styles.get("css") # type: ignore[assignment] return self def set_uuid(self, uuid: str) -> Styler: From eadb3f3b12d045b4b8482cc892ca750f4256d1ba Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Fri, 22 Oct 2021 18:47:37 +0200 Subject: [PATCH 12/15] examples --- pandas/io/formats/style.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 2f244de1d75a8..4941468697bde 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1750,7 +1750,7 @@ def export(self) -> dict[str, Any]: Returns ------- - styles : list + styles : dict See Also -------- @@ -1779,6 +1779,14 @@ def export(self) -> dict[str, Any]: - Any hidden rows or columns identified by Index labels - Any formatting applied using ``Styler.format`` - Any CSS classes added using ``Styler.set_td_classes`` + + Examples + -------- + + >>> styler, styler2 = DataFrame([[1, 2], [3, 4]]), DataFrame([[9, 9, 9]]) + >>> styler.hide_index().highlight_max(axis=1) + >>> export = styler.export() + >>> styler2.use(export) """ return { "apply": copy.copy(self._todo), @@ -1822,6 +1830,14 @@ def use(self, styles: dict[str, Any]) -> Styler: See Also -------- Styler.export : Export the non data dependent attributes to the current Styler. + + Examples + -------- + + >>> styler, styler2 = DataFrame([[1, 2], [3, 4]]), DataFrame([[9, 9, 9]]) + >>> styler.hide_index().highlight_max(axis=1) + >>> export = styler.export() + >>> styler2.use(export) """ self._todo.extend(styles.get("apply", [])) table_attributes: str = self.table_attributes or "" From 77cd4dcb64ac11665458d3c5d4eb53b6db73ea60 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Fri, 22 Oct 2021 20:47:46 +0200 Subject: [PATCH 13/15] err --- pandas/io/formats/style.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 4941468697bde..b6a34d630e51b 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1783,7 +1783,8 @@ def export(self) -> dict[str, Any]: Examples -------- - >>> styler, styler2 = DataFrame([[1, 2], [3, 4]]), DataFrame([[9, 9, 9]]) + >>> styler = DataFrame([[1, 2], [3, 4]]).style + >>> styler2 = DataFrame([[9, 9, 9]]).style >>> styler.hide_index().highlight_max(axis=1) >>> export = styler.export() >>> styler2.use(export) @@ -1834,7 +1835,8 @@ def use(self, styles: dict[str, Any]) -> Styler: Examples -------- - >>> styler, styler2 = DataFrame([[1, 2], [3, 4]]), DataFrame([[9, 9, 9]]) + >>> styler = DataFrame([[1, 2], [3, 4]]).style + >>> styler2 = DataFrame([[9, 9, 9]]).style >>> styler.hide_index().highlight_max(axis=1) >>> export = styler.export() >>> styler2.use(export) From b95e4f3f81d95c74378c755861feb08b797ab3ae Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sat, 23 Oct 2021 08:27:16 +0200 Subject: [PATCH 14/15] fix doctest --- pandas/io/formats/style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index b6a34d630e51b..4154568936c0c 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1787,7 +1787,7 @@ def export(self) -> dict[str, Any]: >>> styler2 = DataFrame([[9, 9, 9]]).style >>> styler.hide_index().highlight_max(axis=1) >>> export = styler.export() - >>> styler2.use(export) + >>> styler2.use(export) # doctest: +SKIP """ return { "apply": copy.copy(self._todo), @@ -1839,7 +1839,7 @@ def use(self, styles: dict[str, Any]) -> Styler: >>> styler2 = DataFrame([[9, 9, 9]]).style >>> styler.hide_index().highlight_max(axis=1) >>> export = styler.export() - >>> styler2.use(export) + >>> styler2.use(export) # doctest: +SKIP """ self._todo.extend(styles.get("apply", [])) table_attributes: str = self.table_attributes or "" From 3df69165ae0a40b83d7eec639e37e918c099da8d Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sat, 23 Oct 2021 10:20:05 +0200 Subject: [PATCH 15/15] doctests --- pandas/io/formats/style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 4154568936c0c..4b3405fb95bf5 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1785,7 +1785,7 @@ def export(self) -> dict[str, Any]: >>> styler = DataFrame([[1, 2], [3, 4]]).style >>> styler2 = DataFrame([[9, 9, 9]]).style - >>> styler.hide_index().highlight_max(axis=1) + >>> styler.hide_index().highlight_max(axis=1) # doctest: +SKIP >>> export = styler.export() >>> styler2.use(export) # doctest: +SKIP """ @@ -1837,7 +1837,7 @@ def use(self, styles: dict[str, Any]) -> Styler: >>> styler = DataFrame([[1, 2], [3, 4]]).style >>> styler2 = DataFrame([[9, 9, 9]]).style - >>> styler.hide_index().highlight_max(axis=1) + >>> styler.hide_index().highlight_max(axis=1) # doctest: +SKIP >>> export = styler.export() >>> styler2.use(export) # doctest: +SKIP """