-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: test_highlight.py
convert to functional tests not class
#40551
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
jreback
merged 6 commits into
pandas-dev:master
from
attack68:test_highlight_no_class_format
Mar 23, 2021
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5027d0f
test_highlight convert to functional tests not class
attack68 54b98a5
test_highlight convert to functional tests not class
attack68 7cb730c
Merge remote-tracking branch 'upstream/master' into test_highlight_no…
attack68 e7390bc
import order fix
attack68 1ebf210
Merge remote-tracking branch 'upstream/master' into test_highlight_no…
attack68 788290b
name change
attack68 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,61 +5,68 @@ | |
|
||
pytest.importorskip("jinja2") | ||
|
||
from pandas.io.formats.style import Styler | ||
|
||
class TestStylerHighlight: | ||
def setup_method(self, method): | ||
np.random.seed(24) | ||
self.s = DataFrame({"A": np.random.permutation(range(6))}) | ||
self.df = DataFrame({"A": [0, 1], "B": np.random.randn(2)}) | ||
|
||
def test_highlight_null(self): | ||
df = DataFrame({"A": [0, np.nan]}) | ||
result = df.style.highlight_null()._compute().ctx | ||
expected = {(1, 0): [("background-color", "red")]} | ||
assert result == expected | ||
@pytest.fixture | ||
def df(): | ||
return DataFrame({"A": [0, np.nan, 10], "B": [1, None, 2]}) | ||
|
||
def test_highlight_null_subset(self): | ||
# GH 31345 | ||
df = DataFrame({"A": [0, np.nan], "B": [0, np.nan]}) | ||
result = ( | ||
df.style.highlight_null(null_color="red", subset=["A"]) | ||
.highlight_null(null_color="green", subset=["B"]) | ||
._compute() | ||
.ctx | ||
) | ||
expected = { | ||
(1, 0): [("background-color", "red")], | ||
(1, 1): [("background-color", "green")], | ||
} | ||
assert result == expected | ||
|
||
@pytest.mark.parametrize("f", ["highlight_min", "highlight_max"]) | ||
def test_highlight_minmax_basic(self, f): | ||
expected = { | ||
(0, 0): [("background-color", "red")], | ||
(1, 0): [("background-color", "red")], | ||
} | ||
if f == "highlight_min": | ||
df = -self.df | ||
else: | ||
df = self.df | ||
result = getattr(df.style, f)(axis=1, color="red")._compute().ctx | ||
assert result == expected | ||
@pytest.fixture | ||
def s(df): | ||
return Styler(df, uuid_len=0) | ||
|
||
@pytest.mark.parametrize("f", ["highlight_min", "highlight_max"]) | ||
@pytest.mark.parametrize( | ||
"kwargs", | ||
[ | ||
{"axis": None, "color": "red"}, # test axis | ||
{"axis": 0, "subset": ["A"], "color": "red"}, # test subset | ||
{"axis": None, "props": "background-color: red"}, # test props | ||
], | ||
|
||
def test_highlight_null(s): | ||
result = s.highlight_null()._compute().ctx | ||
expected = { | ||
(1, 0): [("background-color", "red")], | ||
(1, 1): [("background-color", "red")], | ||
} | ||
assert result == expected | ||
|
||
|
||
def test_highlight_null_subset(s): | ||
# GH 31345 | ||
result = ( | ||
s.highlight_null(null_color="red", subset=["A"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can you line these up on the periods There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.highlight_null(null_color="green", subset=["B"]) | ||
._compute() | ||
.ctx | ||
) | ||
def test_highlight_minmax_ext(self, f, kwargs): | ||
expected = {(1, 0): [("background-color", "red")]} | ||
if f == "highlight_min": | ||
df = -self.df | ||
else: | ||
df = self.df | ||
result = getattr(df.style, f)(**kwargs)._compute().ctx | ||
assert result == expected | ||
expected = { | ||
(1, 0): [("background-color", "red")], | ||
(1, 1): [("background-color", "green")], | ||
} | ||
assert result == expected | ||
|
||
|
||
@pytest.mark.parametrize("f", ["highlight_min", "highlight_max"]) | ||
def test_highlight_minmax_basic(df, f): | ||
expected = { | ||
(0, 1): [("background-color", "red")], | ||
# ignores NaN row, | ||
(2, 0): [("background-color", "red")], | ||
} | ||
if f == "highlight_min": | ||
df = -df | ||
result = getattr(df.style, f)(axis=1, color="red")._compute().ctx | ||
assert result == expected | ||
|
||
|
||
@pytest.mark.parametrize("f", ["highlight_min", "highlight_max"]) | ||
@pytest.mark.parametrize( | ||
"kwargs", | ||
[ | ||
{"axis": None, "color": "red"}, # test axis | ||
{"axis": 0, "subset": ["A"], "color": "red"}, # test subset and ignores NaN | ||
{"axis": None, "props": "background-color: red"}, # test props | ||
], | ||
) | ||
def test_highlight_minmax_ext(df, f, kwargs): | ||
expected = {(2, 0): [("background-color", "red")]} | ||
if f == "highlight_min": | ||
df = -df | ||
result = getattr(df.style, f)(**kwargs)._compute().ctx | ||
assert result == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you call this maybe styler, s is too short
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done