Skip to content

BUG: don't manipulate styler object due to args in to_html #43034

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

Merged
merged 27 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5eac018
dont manipulate styler object on render through args
attack68 Aug 14, 2021
94f482e
copy uuid on Styler
attack68 Aug 14, 2021
abba0a5
copy uuid on Styler
attack68 Aug 14, 2021
0c3dccf
Merge branch 'styler_copy_uuid' into styler_no_obj_manip_to_html
attack68 Aug 14, 2021
57a8180
check clearing tests
attack68 Aug 14, 2021
5d23561
check clearing tests
attack68 Aug 14, 2021
df9f50e
revert uuid len
attack68 Aug 14, 2021
8d8d1e5
address the floating "_" in styler.uuid
attack68 Aug 14, 2021
321e7ca
address the floating "_" in styler.uuid
attack68 Aug 14, 2021
d31de7f
Merge remote-tracking branch 'upstream/master' into styelr_consistent…
attack68 Aug 15, 2021
40e6c13
Merge branch 'styelr_consistent_uuid_len' into styler_copy_uuid
attack68 Aug 15, 2021
47f216e
uuid test
attack68 Aug 15, 2021
43b6597
Merge branch 'styler_copy_uuid' into styler_no_obj_manip_to_html
attack68 Aug 15, 2021
64da7cd
Merge remote-tracking branch 'upstream/master' into styelr_consistent…
attack68 Aug 17, 2021
ff8a808
Merge branch 'styelr_consistent_uuid_len' into styler_copy_uuid
attack68 Aug 17, 2021
5de644b
Merge branch 'styler_copy_uuid' into styler_no_obj_manip_to_html
attack68 Aug 17, 2021
97f6142
Merge remote-tracking branch 'upstream/master' into styler_copy_uuid
attack68 Aug 17, 2021
8f3ebab
Merge branch 'styler_copy_uuid' into styler_no_obj_manip_to_html
attack68 Aug 17, 2021
0e29614
copy uuid_len
attack68 Aug 17, 2021
840a2a6
revert order
attack68 Aug 17, 2021
795d6d3
Merge remote-tracking branch 'upstream/master' into styler_copy_uuid
attack68 Aug 18, 2021
1a205d5
Merge branch 'styler_copy_uuid' into styler_no_obj_manip_to_html
attack68 Aug 18, 2021
c010147
Merge remote-tracking branch 'upstream/master' into styler_no_obj_man…
attack68 Aug 19, 2021
c34cb91
Merge remote-tracking branch 'upstream/master' into styler_no_obj_man…
attack68 Aug 19, 2021
6520cfe
also copy templates
attack68 Aug 19, 2021
5e92fb3
whats new
attack68 Aug 19, 2021
7b661ad
whats new
attack68 Aug 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ ExtensionArray
Styler
^^^^^^
- Minor bug in :class:`.Styler` where the ``uuid`` at initialization maintained a floating underscore (:issue:`43037`)
-
- Bug in :meth:`.Styler.to_html` where the ``Styler`` object was updated if the ``to_html`` method was called with some args (:issue:`43034`)

Other
^^^^^
Expand Down
12 changes: 9 additions & 3 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,19 +900,21 @@ def to_html(
--------
DataFrame.to_html: Write a DataFrame to a file, buffer or string in HTML format.
"""
obj = self._copy(deepcopy=True) # manipulate table_styles on obj, not self

if table_uuid:
self.set_uuid(table_uuid)
obj.set_uuid(table_uuid)

if table_attributes:
self.set_table_attributes(table_attributes)
obj.set_table_attributes(table_attributes)

if sparse_index is None:
sparse_index = get_option("styler.sparse.index")
if sparse_columns is None:
sparse_columns = get_option("styler.sparse.columns")

# Build HTML string..
html = self._render_html(
html = obj._render_html(
sparse_index=sparse_index,
sparse_columns=sparse_columns,
exclude_styles=exclude_styles,
Expand Down Expand Up @@ -1088,6 +1090,10 @@ def _copy(self, deepcopy: bool = False) -> Styler:
"caption",
"uuid",
"uuid_len",
"template_latex", # also copy templates if these have been customised
"template_html_style",
"template_html_table",
"template_html",
]
deep = [ # nested lists or dicts
"_display_funcs",
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/formats/style/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_from_custom_template_style(tmpdir):
assert result.env is not Styler.env
assert result.template_html_style is not Styler.template_html_style
styler = result(DataFrame({"A": [1, 2]}))
assert '<link rel="stylesheet" href="mystyle.css">\n\n<style' in styler.render()
assert '<link rel="stylesheet" href="mystyle.css">\n\n<style' in styler.to_html()


def test_caption_as_sequence(styler):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/formats/style/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def mi_styler(mi_df):
def mi_styler_comp(mi_styler):
# comprehensively add features to mi_styler
mi_styler.uuid_len = 5
mi_styler.uuid = "abcde_"
mi_styler.uuid = "abcde"
mi_styler.set_caption("capt")
mi_styler.set_table_styles([{"selector": "a", "props": "a:v;"}])
mi_styler.hide_columns()
Expand Down