@@ -51,55 +51,6 @@ def df_mix():
51
51
return DataFrame ([[- 3 ], [1 ], [2 ]])
52
52
53
53
54
- class TestStylerBarAlign :
55
- def test_bar_align_mid_nans (self ):
56
- df = DataFrame ({"A" : [1 , None ], "B" : [- 1 , 3 ]})
57
- result = df .style .bar (align = "mid" , axis = None )._compute ().ctx
58
- expected = {
59
- (0 , 0 ): bar_grad (
60
- " transparent 25.0%" ,
61
- " #d65f5f 25.0%" ,
62
- " #d65f5f 50.0%" ,
63
- " transparent 50.0%" ,
64
- ),
65
- (0 , 1 ): bar_grad (" #d65f5f 25.0%" , " transparent 25.0%" ),
66
- (1 , 0 ): bar_grad (),
67
- (1 , 1 ): bar_grad (
68
- " transparent 25.0%" ,
69
- " #d65f5f 25.0%" ,
70
- " #d65f5f 100.0%" ,
71
- " transparent 100.0%" ,
72
- ),
73
- }
74
- assert result == expected
75
-
76
- def test_bar_align_zero_nans (self ):
77
- df = DataFrame ({"A" : [1 , None ], "B" : [- 1 , 2 ]})
78
- result = df .style .bar (align = "zero" , axis = None )._compute ().ctx
79
- expected = {
80
- (0 , 0 ): bar_grad (
81
- " transparent 50.0%" ,
82
- " #d65f5f 50.0%" ,
83
- " #d65f5f 75.0%" ,
84
- " transparent 75.0%" ,
85
- ),
86
- (0 , 1 ): bar_grad (
87
- " transparent 25.0%" ,
88
- " #d65f5f 25.0%" ,
89
- " #d65f5f 50.0%" ,
90
- " transparent 50.0%" ,
91
- ),
92
- (1 , 0 ): bar_grad (),
93
- (1 , 1 ): bar_grad (
94
- " transparent 50.0%" ,
95
- " #d65f5f 50.0%" ,
96
- " #d65f5f 100.0%" ,
97
- " transparent 100.0%" ,
98
- ),
99
- }
100
- assert result == expected
101
-
102
-
103
54
@pytest .mark .parametrize (
104
55
"align, exp" ,
105
56
[
@@ -147,13 +98,18 @@ def test_align_negative_cases(df_neg, align, exp):
147
98
("zero" , [bar_to (50 ), bar_from_to (50 , 66.66 ), bar_from_to (50 , 83.33 )]),
148
99
("mean" , [bar_to (50 ), bar_from_to (50 , 66.66 ), bar_from_to (50 , 83.33 )]),
149
100
(- 0.0 , [bar_to (50 ), bar_from_to (50 , 66.66 ), bar_from_to (50 , 83.33 )]),
150
- (np .median , [bar_to (50 ), no_bar (), bar_from_to (50 , 62.5 )]),
101
+ (np .nanmedian , [bar_to (50 ), no_bar (), bar_from_to (50 , 62.5 )]),
151
102
],
152
103
)
153
- def test_align_mixed_cases (df_mix , align , exp ):
104
+ @pytest .mark .parametrize ("nans" , [True , False ])
105
+ def test_align_mixed_cases (df_mix , align , exp , nans ):
154
106
# test different align cases for mixed positive and negative values
155
- result = df_mix . style . bar ( align = align ). _compute (). ctx
107
+ # also test no impact of NaNs and no_bar
156
108
expected = {(0 , 0 ): exp [0 ], (1 , 0 ): exp [1 ], (2 , 0 ): exp [2 ]}
109
+ if nans :
110
+ df_mix .loc [3 , :] = np .nan
111
+ expected .update ({(3 , 0 ): no_bar ()})
112
+ result = df_mix .style .bar (align = align )._compute ().ctx
157
113
assert result == expected
158
114
159
115
0 commit comments