Skip to content

Commit 2d5b8f9

Browse files
attack68feefladder
authored andcommitted
BUG: also copy uuid in Styler.copy (pandas-dev#43044)
1 parent b847b45 commit 2d5b8f9

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

doc/source/whatsnew/v1.4.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ Categorical
239239
- Bug in :meth:`Series.where` with ``CategoricalDtype`` when passing a dtype-incompatible value raising ``ValueError`` instead of ``TypeError`` (:issue:`41919`)
240240
- Bug in :meth:`Categorical.fillna` when passing a dtype-incompatible value raising ``ValueError`` instead of ``TypeError`` (:issue:`41919`)
241241
- Bug in :meth:`Categorical.fillna` with a tuple-like category raising ``ValueError`` instead of ``TypeError`` when filling with a non-category tuple (:issue:`41919`)
242+
- Bug in :meth:`.Styler.copy` where ``uuid`` was not previously copied (:issue:`40675`)
242243
-
243244

244245
Datetimelike

pandas/io/formats/style.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,14 +1079,15 @@ def _copy(self, deepcopy: bool = False) -> Styler:
10791079
# GH 40675
10801080
styler = Styler(
10811081
self.data, # populates attributes 'data', 'columns', 'index' as shallow
1082-
uuid_len=self.uuid_len,
10831082
)
10841083
shallow = [ # simple string or boolean immutables
10851084
"hide_index_",
10861085
"hide_columns_",
10871086
"table_attributes",
10881087
"cell_ids",
10891088
"caption",
1089+
"uuid",
1090+
"uuid_len",
10901091
]
10911092
deep = [ # nested lists or dicts
10921093
"_display_funcs",

pandas/io/formats/style_render.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def __init__(
8989
self.columns: Index = data.columns
9090
if not isinstance(uuid_len, int) or not uuid_len >= 0:
9191
raise TypeError("``uuid_len`` must be an integer in range [0, 32].")
92-
self.uuid_len = min(32, uuid_len)
93-
self.uuid = uuid or uuid4().hex[: self.uuid_len]
92+
self.uuid = uuid or uuid4().hex[: min(32, uuid_len)]
93+
self.uuid_len = len(self.uuid)
9494
self.table_styles = table_styles
9595
self.table_attributes = table_attributes
9696
self.caption = caption

pandas/tests/io/formats/style/test_style.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ def test_copy(comprehensive, render, deepcopy, mi_styler, mi_styler_comp):
203203
excl = [
204204
"na_rep", # deprecated
205205
"precision", # deprecated
206-
"uuid", # special
207206
"cellstyle_map", # render time vars..
208207
"cellstyle_map_columns",
209208
"cellstyle_map_index",
@@ -217,6 +216,7 @@ def test_copy(comprehensive, render, deepcopy, mi_styler, mi_styler_comp):
217216
"columns",
218217
"index",
219218
"uuid_len",
219+
"uuid",
220220
"caption",
221221
"cell_ids",
222222
"hide_index_",
@@ -242,7 +242,7 @@ def test_clear(mi_styler_comp):
242242
# to ensure proper testing of the 'copy', 'clear', 'export' methods with new feature
243243
# GH 40675
244244
styler = mi_styler_comp
245-
styler.to_html() # new attrs maybe created on render
245+
styler._compute() # execute applied methods
246246

247247
clean_copy = Styler(styler.data, uuid=styler.uuid)
248248

@@ -251,7 +251,7 @@ def test_clear(mi_styler_comp):
251251
"index",
252252
"columns",
253253
"uuid",
254-
"uuid_len",
254+
"uuid_len", # uuid is set to be the same on styler and clean_copy
255255
"cell_ids",
256256
"cellstyle_map", # execution time only
257257
"cellstyle_map_columns", # execution time only

0 commit comments

Comments
 (0)