@@ -37,7 +37,8 @@ def h(x, foo="bar"):
37
37
]
38
38
39
39
def test_init_non_pandas (self ):
40
- with pytest .raises (TypeError ):
40
+ msg = "``data`` must be a Series or DataFrame"
41
+ with pytest .raises (TypeError , match = msg ):
41
42
Styler ([1 , 2 , 3 ])
42
43
43
44
def test_init_series (self ):
@@ -1013,7 +1014,8 @@ def test_bar_align_zero_nans(self):
1013
1014
1014
1015
def test_bar_bad_align_raises (self ):
1015
1016
df = pd .DataFrame ({"A" : [- 100 , - 60 , - 30 , - 20 ]})
1016
- with pytest .raises (ValueError ):
1017
+ msg = "`align` must be one of {'left', 'zero',' mid'}"
1018
+ with pytest .raises (ValueError , match = msg ):
1017
1019
df .style .bar (align = "poorly" , color = ["#d65f5f" , "#5fba7d" ])
1018
1020
1019
1021
def test_format_with_na_rep (self ):
@@ -1082,7 +1084,8 @@ def test_format_non_numeric_na(self):
1082
1084
def test_format_with_bad_na_rep (self ):
1083
1085
# GH 21527 28358
1084
1086
df = pd .DataFrame ([[None , None ], [1.1 , 1.2 ]], columns = ["A" , "B" ])
1085
- with pytest .raises (TypeError ):
1087
+ msg = "Expected a string, got -1 instead"
1088
+ with pytest .raises (TypeError , match = msg ):
1086
1089
df .style .format (None , na_rep = - 1 )
1087
1090
1088
1091
def test_highlight_null (self , null_color = "red" ):
@@ -1110,10 +1113,11 @@ def test_highlight_null_subset(self):
1110
1113
1111
1114
def test_nonunique_raises (self ):
1112
1115
df = pd .DataFrame ([[1 , 2 ]], columns = ["A" , "A" ])
1113
- with pytest .raises (ValueError ):
1116
+ msg = "style is not supported for non-unique indices."
1117
+ with pytest .raises (ValueError , match = msg ):
1114
1118
df .style
1115
1119
1116
- with pytest .raises (ValueError ):
1120
+ with pytest .raises (ValueError , match = msg ):
1117
1121
Styler (df )
1118
1122
1119
1123
def test_caption (self ):
@@ -1260,9 +1264,12 @@ def test_display_format(self):
1260
1264
1261
1265
def test_display_format_raises (self ):
1262
1266
df = pd .DataFrame (np .random .randn (2 , 2 ))
1263
- with pytest .raises (TypeError ):
1267
+ msg = "Expected a template string or callable, got 5 instead"
1268
+ with pytest .raises (TypeError , match = msg ):
1264
1269
df .style .format (5 )
1265
- with pytest .raises (TypeError ):
1270
+
1271
+ msg = "Expected a template string or callable, got True instead"
1272
+ with pytest .raises (TypeError , match = msg ):
1266
1273
df .style .format (True )
1267
1274
1268
1275
def test_display_set_precision (self ):
@@ -1335,35 +1342,39 @@ def test_display_dict(self):
1335
1342
1336
1343
def test_bad_apply_shape (self ):
1337
1344
df = pd .DataFrame ([[1 , 2 ], [3 , 4 ]])
1338
- with pytest .raises (ValueError ):
1345
+ msg = "returned the wrong shape"
1346
+ with pytest .raises (ValueError , match = msg ):
1339
1347
df .style ._apply (lambda x : "x" , subset = pd .IndexSlice [[0 , 1 ], :])
1340
1348
1341
- with pytest .raises (ValueError ):
1349
+ with pytest .raises (ValueError , match = msg ):
1342
1350
df .style ._apply (lambda x : ["" ], subset = pd .IndexSlice [[0 , 1 ], :])
1343
1351
1344
- with pytest .raises (ValueError ):
1352
+ with pytest .raises (ValueError , match = msg ):
1345
1353
df .style ._apply (lambda x : ["" , "" , "" , "" ])
1346
1354
1347
- with pytest .raises (ValueError ):
1355
+ with pytest .raises (ValueError , match = msg ):
1348
1356
df .style ._apply (lambda x : ["" , "" , "" ], subset = 1 )
1349
1357
1350
- with pytest .raises (ValueError ):
1358
+ msg = "Length mismatch: Expected axis has 3 elements"
1359
+ with pytest .raises (ValueError , match = msg ):
1351
1360
df .style ._apply (lambda x : ["" , "" , "" ], axis = 1 )
1352
1361
1353
1362
def test_apply_bad_return (self ):
1354
1363
def f (x ):
1355
1364
return ""
1356
1365
1357
1366
df = pd .DataFrame ([[1 , 2 ], [3 , 4 ]])
1358
- with pytest .raises (TypeError ):
1367
+ msg = "must return a DataFrame when passed to `Styler.apply` with axis=None"
1368
+ with pytest .raises (TypeError , match = msg ):
1359
1369
df .style ._apply (f , axis = None )
1360
1370
1361
1371
def test_apply_bad_labels (self ):
1362
1372
def f (x ):
1363
1373
return pd .DataFrame (index = [1 , 2 ], columns = ["a" , "b" ])
1364
1374
1365
1375
df = pd .DataFrame ([[1 , 2 ], [3 , 4 ]])
1366
- with pytest .raises (ValueError ):
1376
+ msg = "must have identical index and columns as the input"
1377
+ with pytest .raises (ValueError , match = msg ):
1367
1378
df .style ._apply (f , axis = None )
1368
1379
1369
1380
def test_get_level_lengths (self ):
0 commit comments