@@ -28,28 +28,28 @@ def styler(df):
28
28
29
29
30
30
def test_display_format (styler ):
31
- ctx = styler .format ("{:0.1f}" )._translate ()
31
+ ctx = styler .format ("{:0.1f}" )._translate (True , True )
32
32
assert all (["display_value" in c for c in row ] for row in ctx ["body" ])
33
33
assert all ([len (c ["display_value" ]) <= 3 for c in row [1 :]] for row in ctx ["body" ])
34
34
assert len (ctx ["body" ][0 ][1 ]["display_value" ].lstrip ("-" )) <= 3
35
35
36
36
37
37
def test_format_dict (styler ):
38
- ctx = styler .format ({"A" : "{:0.1f}" , "B" : "{0:.2%}" })._translate ()
38
+ ctx = styler .format ({"A" : "{:0.1f}" , "B" : "{0:.2%}" })._translate (True , True )
39
39
assert ctx ["body" ][0 ][1 ]["display_value" ] == "0.0"
40
40
assert ctx ["body" ][0 ][2 ]["display_value" ] == "-60.90%"
41
41
42
42
43
43
def test_format_string (styler ):
44
- ctx = styler .format ("{:.2f}" )._translate ()
44
+ ctx = styler .format ("{:.2f}" )._translate (True , True )
45
45
assert ctx ["body" ][0 ][1 ]["display_value" ] == "0.00"
46
46
assert ctx ["body" ][0 ][2 ]["display_value" ] == "-0.61"
47
47
assert ctx ["body" ][1 ][1 ]["display_value" ] == "1.00"
48
48
assert ctx ["body" ][1 ][2 ]["display_value" ] == "-1.23"
49
49
50
50
51
51
def test_format_callable (styler ):
52
- ctx = styler .format (lambda v : "neg" if v < 0 else "pos" )._translate ()
52
+ ctx = styler .format (lambda v : "neg" if v < 0 else "pos" )._translate (True , True )
53
53
assert ctx ["body" ][0 ][1 ]["display_value" ] == "pos"
54
54
assert ctx ["body" ][0 ][2 ]["display_value" ] == "neg"
55
55
assert ctx ["body" ][1 ][1 ]["display_value" ] == "pos"
@@ -60,17 +60,17 @@ def test_format_with_na_rep():
60
60
# GH 21527 28358
61
61
df = DataFrame ([[None , None ], [1.1 , 1.2 ]], columns = ["A" , "B" ])
62
62
63
- ctx = df .style .format (None , na_rep = "-" )._translate ()
63
+ ctx = df .style .format (None , na_rep = "-" )._translate (True , True )
64
64
assert ctx ["body" ][0 ][1 ]["display_value" ] == "-"
65
65
assert ctx ["body" ][0 ][2 ]["display_value" ] == "-"
66
66
67
- ctx = df .style .format ("{:.2%}" , na_rep = "-" )._translate ()
67
+ ctx = df .style .format ("{:.2%}" , na_rep = "-" )._translate (True , True )
68
68
assert ctx ["body" ][0 ][1 ]["display_value" ] == "-"
69
69
assert ctx ["body" ][0 ][2 ]["display_value" ] == "-"
70
70
assert ctx ["body" ][1 ][1 ]["display_value" ] == "110.00%"
71
71
assert ctx ["body" ][1 ][2 ]["display_value" ] == "120.00%"
72
72
73
- ctx = df .style .format ("{:.2%}" , na_rep = "-" , subset = ["B" ])._translate ()
73
+ ctx = df .style .format ("{:.2%}" , na_rep = "-" , subset = ["B" ])._translate (True , True )
74
74
assert ctx ["body" ][0 ][2 ]["display_value" ] == "-"
75
75
assert ctx ["body" ][1 ][2 ]["display_value" ] == "120.00%"
76
76
@@ -85,13 +85,13 @@ def test_format_non_numeric_na():
85
85
)
86
86
87
87
with tm .assert_produces_warning (FutureWarning ):
88
- ctx = df .style .set_na_rep ("NA" )._translate ()
88
+ ctx = df .style .set_na_rep ("NA" )._translate (True , True )
89
89
assert ctx ["body" ][0 ][1 ]["display_value" ] == "NA"
90
90
assert ctx ["body" ][0 ][2 ]["display_value" ] == "NA"
91
91
assert ctx ["body" ][1 ][1 ]["display_value" ] == "NA"
92
92
assert ctx ["body" ][1 ][2 ]["display_value" ] == "NA"
93
93
94
- ctx = df .style .format (None , na_rep = "-" )._translate ()
94
+ ctx = df .style .format (None , na_rep = "-" )._translate (True , True )
95
95
assert ctx ["body" ][0 ][1 ]["display_value" ] == "-"
96
96
assert ctx ["body" ][0 ][2 ]["display_value" ] == "-"
97
97
assert ctx ["body" ][1 ][1 ]["display_value" ] == "-"
@@ -150,19 +150,19 @@ def test_format_with_precision():
150
150
df = DataFrame (data = [[1.0 , 2.0090 ], [3.2121 , 4.566 ]], columns = ["a" , "b" ])
151
151
s = Styler (df )
152
152
153
- ctx = s .format (precision = 1 )._translate ()
153
+ ctx = s .format (precision = 1 )._translate (True , True )
154
154
assert ctx ["body" ][0 ][1 ]["display_value" ] == "1.0"
155
155
assert ctx ["body" ][0 ][2 ]["display_value" ] == "2.0"
156
156
assert ctx ["body" ][1 ][1 ]["display_value" ] == "3.2"
157
157
assert ctx ["body" ][1 ][2 ]["display_value" ] == "4.6"
158
158
159
- ctx = s .format (precision = 2 )._translate ()
159
+ ctx = s .format (precision = 2 )._translate (True , True )
160
160
assert ctx ["body" ][0 ][1 ]["display_value" ] == "1.00"
161
161
assert ctx ["body" ][0 ][2 ]["display_value" ] == "2.01"
162
162
assert ctx ["body" ][1 ][1 ]["display_value" ] == "3.21"
163
163
assert ctx ["body" ][1 ][2 ]["display_value" ] == "4.57"
164
164
165
- ctx = s .format (precision = 3 )._translate ()
165
+ ctx = s .format (precision = 3 )._translate (True , True )
166
166
assert ctx ["body" ][0 ][1 ]["display_value" ] == "1.000"
167
167
assert ctx ["body" ][0 ][2 ]["display_value" ] == "2.009"
168
168
assert ctx ["body" ][1 ][1 ]["display_value" ] == "3.212"
@@ -173,26 +173,28 @@ def test_format_subset():
173
173
df = DataFrame ([[0.1234 , 0.1234 ], [1.1234 , 1.1234 ]], columns = ["a" , "b" ])
174
174
ctx = df .style .format (
175
175
{"a" : "{:0.1f}" , "b" : "{0:.2%}" }, subset = IndexSlice [0 , :]
176
- )._translate ()
176
+ )._translate (True , True )
177
177
expected = "0.1"
178
178
raw_11 = "1.123400"
179
179
assert ctx ["body" ][0 ][1 ]["display_value" ] == expected
180
180
assert ctx ["body" ][1 ][1 ]["display_value" ] == raw_11
181
181
assert ctx ["body" ][0 ][2 ]["display_value" ] == "12.34%"
182
182
183
- ctx = df .style .format ("{:0.1f}" , subset = IndexSlice [0 , :])._translate ()
183
+ ctx = df .style .format ("{:0.1f}" , subset = IndexSlice [0 , :])._translate (True , True )
184
184
assert ctx ["body" ][0 ][1 ]["display_value" ] == expected
185
185
assert ctx ["body" ][1 ][1 ]["display_value" ] == raw_11
186
186
187
- ctx = df .style .format ("{:0.1f}" , subset = IndexSlice ["a" ])._translate ()
187
+ ctx = df .style .format ("{:0.1f}" , subset = IndexSlice ["a" ])._translate (True , True )
188
188
assert ctx ["body" ][0 ][1 ]["display_value" ] == expected
189
189
assert ctx ["body" ][0 ][2 ]["display_value" ] == "0.123400"
190
190
191
- ctx = df .style .format ("{:0.1f}" , subset = IndexSlice [0 , "a" ])._translate ()
191
+ ctx = df .style .format ("{:0.1f}" , subset = IndexSlice [0 , "a" ])._translate (True , True )
192
192
assert ctx ["body" ][0 ][1 ]["display_value" ] == expected
193
193
assert ctx ["body" ][1 ][1 ]["display_value" ] == raw_11
194
194
195
- ctx = df .style .format ("{:0.1f}" , subset = IndexSlice [[0 , 1 ], ["a" ]])._translate ()
195
+ ctx = df .style .format ("{:0.1f}" , subset = IndexSlice [[0 , 1 ], ["a" ]])._translate (
196
+ True , True
197
+ )
196
198
assert ctx ["body" ][0 ][1 ]["display_value" ] == expected
197
199
assert ctx ["body" ][1 ][1 ]["display_value" ] == "1.1"
198
200
assert ctx ["body" ][0 ][2 ]["display_value" ] == "0.123400"
@@ -206,19 +208,19 @@ def test_format_thousands(formatter, decimal, precision):
206
208
s = DataFrame ([[1000000.123456789 ]]).style # test float
207
209
result = s .format (
208
210
thousands = "_" , formatter = formatter , decimal = decimal , precision = precision
209
- )._translate ()
211
+ )._translate (True , True )
210
212
assert "1_000_000" in result ["body" ][0 ][1 ]["display_value" ]
211
213
212
214
s = DataFrame ([[1000000 ]]).style # test int
213
215
result = s .format (
214
216
thousands = "_" , formatter = formatter , decimal = decimal , precision = precision
215
- )._translate ()
217
+ )._translate (True , True )
216
218
assert "1_000_000" in result ["body" ][0 ][1 ]["display_value" ]
217
219
218
220
s = DataFrame ([[1 + 1000000.123456789j ]]).style # test complex
219
221
result = s .format (
220
222
thousands = "_" , formatter = formatter , decimal = decimal , precision = precision
221
- )._translate ()
223
+ )._translate (True , True )
222
224
assert "1_000_000" in result ["body" ][0 ][1 ]["display_value" ]
223
225
224
226
@@ -229,11 +231,11 @@ def test_format_decimal(formatter, thousands, precision):
229
231
s = DataFrame ([[1000000.123456789 ]]).style # test float
230
232
result = s .format (
231
233
decimal = "_" , formatter = formatter , thousands = thousands , precision = precision
232
- )._translate ()
234
+ )._translate (True , True )
233
235
assert "000_123" in result ["body" ][0 ][1 ]["display_value" ]
234
236
235
237
s = DataFrame ([[1 + 1000000.123456789j ]]).style # test complex
236
238
result = s .format (
237
239
decimal = "_" , formatter = formatter , thousands = thousands , precision = precision
238
- )._translate ()
240
+ )._translate (True , True )
239
241
assert "000_123" in result ["body" ][0 ][1 ]["display_value" ]
0 commit comments