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