Skip to content

Commit 53104f5

Browse files
committed
REGR: styler.highlight_min/max did not ignore pd.NA and caused error (pandas-dev#42861)
(cherry picked from commit b9edc9a)
1 parent 3f11720 commit 53104f5

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

doc/source/whatsnew/v1.3.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Fixed regressions
2222
- Regression in :meth:`DataFrame.drop` does nothing if :class:`MultiIndex` has duplicates and indexer is a tuple or list of tuples (:issue:`42771`)
2323
- Fixed regression where :meth:`pandas.read_csv` raised a ``ValueError`` when parameters ``names`` and ``prefix`` were both set to None (:issue:`42387`)
2424
- Fixed regression in comparisons between :class:`Timestamp` object and ``datetime64`` objects outside the implementation bounds for nanosecond ``datetime64`` (:issue:`42794`)
25-
-
25+
- Fixed regression in :meth:`.Styler.highlight_min` and :meth:`.Styler.highlight_max` where ``pandas.NA`` was not successfully ignored (:issue:`42650`)
2626

2727
.. ---------------------------------------------------------------------------
2828

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

+22-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import pytest
33

44
from pandas import (
5+
NA,
56
DataFrame,
67
IndexSlice,
78
)
8-
import pandas._testing as tm
99

1010
pytest.importorskip("jinja2")
1111

@@ -55,9 +55,7 @@ def test_highlight_minmax_basic(df, f):
5555
}
5656
if f == "highlight_min":
5757
df = -df
58-
with tm.assert_produces_warning(RuntimeWarning):
59-
# All-NaN slice encountered
60-
result = getattr(df.style, f)(axis=1, color="red")._compute().ctx
58+
result = getattr(df.style, f)(axis=1, color="red")._compute().ctx
6159
assert result == expected
6260

6361

@@ -78,6 +76,26 @@ def test_highlight_minmax_ext(df, f, kwargs):
7876
assert result == expected
7977

8078

79+
@pytest.mark.parametrize("f", ["highlight_min", "highlight_max"])
80+
@pytest.mark.parametrize("axis", [None, 0, 1])
81+
def test_highlight_minmax_nulls(f, axis):
82+
# GH 42750
83+
expected = {
84+
(1, 0): [("background-color", "yellow")],
85+
(1, 1): [("background-color", "yellow")],
86+
}
87+
if axis == 1:
88+
expected.update({(2, 1): [("background-color", "yellow")]})
89+
90+
if f == "highlight_max":
91+
df = DataFrame({"a": [NA, 1, None], "b": [np.nan, 1, -1]})
92+
else:
93+
df = DataFrame({"a": [NA, -1, None], "b": [np.nan, -1, 1]})
94+
95+
result = getattr(df.style, f)(axis=axis)._compute().ctx
96+
assert result == expected
97+
98+
8199
@pytest.mark.parametrize(
82100
"kwargs",
83101
[

0 commit comments

Comments
 (0)