Skip to content

Commit adc9830

Browse files
authored
BUG: Fix set_sticky background (#47082)
1 parent 33c52d2 commit adc9830

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ Styler
882882
^^^^^^
883883
- Bug when attempting to apply styling functions to an empty DataFrame subset (:issue:`45313`)
884884
- Bug in :class:`CSSToExcelConverter` leading to ``TypeError`` when border color provided without border style for ``xlsxwriter`` engine (:issue:`42276`)
885+
- Bug in :meth:`Styler.set_sticky` leading to white text on white background in dark mode (:issue:`46984`)
885886

886887
Metadata
887888
^^^^^^^^

pandas/io/formats/style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ def set_sticky(
22832283
obj = self.data.index if axis == 0 else self.data.columns
22842284
pixel_size = (75 if axis == 0 else 25) if not pixel_size else pixel_size
22852285

2286-
props = "position:sticky; background-color:white;"
2286+
props = "position:sticky; background-color:inherit;"
22872287
if not isinstance(obj, pd.MultiIndex):
22882288
# handling MultiIndexes requires different CSS
22892289

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ def test_sticky_basic(styler, index, columns, index_name):
302302
styler.set_sticky(axis=1)
303303

304304
left_css = (
305-
"#T_ {0} {{\n position: sticky;\n background-color: white;\n"
305+
"#T_ {0} {{\n position: sticky;\n background-color: inherit;\n"
306306
" left: 0px;\n z-index: {1};\n}}"
307307
)
308308
top_css = (
309-
"#T_ {0} {{\n position: sticky;\n background-color: white;\n"
309+
"#T_ {0} {{\n position: sticky;\n background-color: inherit;\n"
310310
" top: {1}px;\n z-index: {2};\n{3}}}"
311311
)
312312

@@ -338,11 +338,11 @@ def test_sticky_mi(styler_mi, index, columns):
338338
styler_mi.set_sticky(axis=1)
339339

340340
left_css = (
341-
"#T_ {0} {{\n position: sticky;\n background-color: white;\n"
341+
"#T_ {0} {{\n position: sticky;\n background-color: inherit;\n"
342342
" left: {1}px;\n min-width: 75px;\n max-width: 75px;\n z-index: {2};\n}}"
343343
)
344344
top_css = (
345-
"#T_ {0} {{\n position: sticky;\n background-color: white;\n"
345+
"#T_ {0} {{\n position: sticky;\n background-color: inherit;\n"
346346
" top: {1}px;\n height: 25px;\n z-index: {2};\n}}"
347347
)
348348

@@ -374,11 +374,11 @@ def test_sticky_levels(styler_mi, index, columns, levels):
374374
styler_mi.set_sticky(axis=1, levels=levels)
375375

376376
left_css = (
377-
"#T_ {0} {{\n position: sticky;\n background-color: white;\n"
377+
"#T_ {0} {{\n position: sticky;\n background-color: inherit;\n"
378378
" left: {1}px;\n min-width: 75px;\n max-width: 75px;\n z-index: {2};\n}}"
379379
)
380380
top_css = (
381-
"#T_ {0} {{\n position: sticky;\n background-color: white;\n"
381+
"#T_ {0} {{\n position: sticky;\n background-color: inherit;\n"
382382
" top: {1}px;\n height: 25px;\n z-index: {2};\n}}"
383383
)
384384

0 commit comments

Comments
 (0)