From f83efef2f0ad6d89e9e5f09575fe91f3f256fa3d Mon Sep 17 00:00:00 2001 From: Shawn Zhong Date: Sat, 21 May 2022 03:07:15 -0500 Subject: [PATCH] BUG: Fix `set_sticky` background --- doc/source/whatsnew/v1.5.0.rst | 1 + pandas/io/formats/style.py | 2 +- pandas/tests/io/formats/style/test_html.py | 12 ++++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 581473d3c4798..013fccaacf534 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -812,6 +812,7 @@ Styler ^^^^^^ - Bug when attempting to apply styling functions to an empty DataFrame subset (:issue:`45313`) - Bug in :class:`CSSToExcelConverter` leading to ``TypeError`` when border color provided without border style for ``xlsxwriter`` engine (:issue:`42276`) +- Bug in :meth:`Styler.set_sticky` leading to white text on white background in dark mode (:issue:`46984`) Metadata ^^^^^^^^ diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 90642ff2bb3fc..24646da9162b0 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -2283,7 +2283,7 @@ def set_sticky( obj = self.data.index if axis == 0 else self.data.columns pixel_size = (75 if axis == 0 else 25) if not pixel_size else pixel_size - props = "position:sticky; background-color:white;" + props = "position:sticky; background-color:inherit;" if not isinstance(obj, pd.MultiIndex): # handling MultiIndexes requires different CSS diff --git a/pandas/tests/io/formats/style/test_html.py b/pandas/tests/io/formats/style/test_html.py index bf4f79d0e89e6..46891863975ea 100644 --- a/pandas/tests/io/formats/style/test_html.py +++ b/pandas/tests/io/formats/style/test_html.py @@ -302,11 +302,11 @@ def test_sticky_basic(styler, index, columns, index_name): styler.set_sticky(axis=1) left_css = ( - "#T_ {0} {{\n position: sticky;\n background-color: white;\n" + "#T_ {0} {{\n position: sticky;\n background-color: inherit;\n" " left: 0px;\n z-index: {1};\n}}" ) top_css = ( - "#T_ {0} {{\n position: sticky;\n background-color: white;\n" + "#T_ {0} {{\n position: sticky;\n background-color: inherit;\n" " top: {1}px;\n z-index: {2};\n{3}}}" ) @@ -338,11 +338,11 @@ def test_sticky_mi(styler_mi, index, columns): styler_mi.set_sticky(axis=1) left_css = ( - "#T_ {0} {{\n position: sticky;\n background-color: white;\n" + "#T_ {0} {{\n position: sticky;\n background-color: inherit;\n" " left: {1}px;\n min-width: 75px;\n max-width: 75px;\n z-index: {2};\n}}" ) top_css = ( - "#T_ {0} {{\n position: sticky;\n background-color: white;\n" + "#T_ {0} {{\n position: sticky;\n background-color: inherit;\n" " top: {1}px;\n height: 25px;\n z-index: {2};\n}}" ) @@ -374,11 +374,11 @@ def test_sticky_levels(styler_mi, index, columns, levels): styler_mi.set_sticky(axis=1, levels=levels) left_css = ( - "#T_ {0} {{\n position: sticky;\n background-color: white;\n" + "#T_ {0} {{\n position: sticky;\n background-color: inherit;\n" " left: {1}px;\n min-width: 75px;\n max-width: 75px;\n z-index: {2};\n}}" ) top_css = ( - "#T_ {0} {{\n position: sticky;\n background-color: white;\n" + "#T_ {0} {{\n position: sticky;\n background-color: inherit;\n" " top: {1}px;\n height: 25px;\n z-index: {2};\n}}" )