@@ -1061,7 +1061,7 @@ def test_precision(self):
1061
1061
1062
1062
s2 = s .set_precision (4 )
1063
1063
assert s is s2
1064
- assert s .precision == 4
1064
+ assert s .precision == 4
1065
1065
1066
1066
def test_apply_none (self ):
1067
1067
def f (x ):
@@ -1157,6 +1157,33 @@ def test_display_format_raises(self):
1157
1157
with pytest .raises (TypeError ):
1158
1158
df .style .format (True )
1159
1159
1160
+ def test_display_set_precision (self ):
1161
+ df = pd .DataFrame (data = [[1.0 ,2.0090 ],[3.2121 ,4.566 ]], columns = ['a' ,'b' ])
1162
+ s = Styler (df )
1163
+
1164
+ ctx = s .set_precision (1 )._translate ()
1165
+
1166
+ assert s .precision == 1
1167
+ assert ctx ["body" ][0 ][1 ]["display_value" ] == "1"
1168
+ assert ctx ["body" ][0 ][2 ]["display_value" ] == "2"
1169
+ assert ctx ["body" ][1 ][1 ]["display_value" ] == "3.2"
1170
+ assert ctx ["body" ][1 ][2 ]["display_value" ] == "4.6"
1171
+
1172
+ ctx = s .set_precision (2 )._translate ()
1173
+ assert s .precision == 2
1174
+ assert ctx ["body" ][0 ][1 ]["display_value" ] == "1"
1175
+ assert ctx ["body" ][0 ][2 ]["display_value" ] == "2.01"
1176
+ assert ctx ["body" ][1 ][1 ]["display_value" ] == "3.21"
1177
+ assert ctx ["body" ][1 ][2 ]["display_value" ] == "4.57"
1178
+
1179
+ ctx = s .set_precision (3 )._translate ()
1180
+ assert s .precision == 3
1181
+ assert ctx ["body" ][0 ][1 ]["display_value" ] == "1"
1182
+ assert ctx ["body" ][0 ][2 ]["display_value" ] == "2.009"
1183
+ assert ctx ["body" ][1 ][1 ]["display_value" ] == "3.212"
1184
+ assert ctx ["body" ][1 ][2 ]["display_value" ] == "4.566"
1185
+ # assert
1186
+
1160
1187
def test_display_subset (self ):
1161
1188
df = pd .DataFrame ([[0.1234 , 0.1234 ], [1.1234 , 1.1234 ]], columns = ["a" , "b" ])
1162
1189
ctx = df .style .format (
0 commit comments