Skip to content

BUG: Fix set_sticky background #47082

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 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/io/formats/style/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}"
)

Expand Down Expand Up @@ -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}}"
)

Expand Down Expand Up @@ -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}}"
)

Expand Down