@@ -574,36 +574,6 @@ def test_index_name(self):
574
574
}
575
575
assert expected .items () <= result ["head" ][1 ][0 ].items ()
576
576
577
- def test_multiindex_name (self ):
578
- # https://github.com/pandas-dev/pandas/issues/11655
579
- df = DataFrame ({"A" : [1 , 2 ], "B" : [3 , 4 ], "C" : [5 , 6 ]})
580
- result = df .set_index (["A" , "B" ]).style ._translate (True , True )
581
-
582
- expected = [
583
- {
584
- "class" : "index_name level0" ,
585
- "type" : "th" ,
586
- "value" : "A" ,
587
- "is_visible" : True ,
588
- "display_value" : "A" ,
589
- },
590
- {
591
- "class" : "index_name level1" ,
592
- "type" : "th" ,
593
- "value" : "B" ,
594
- "is_visible" : True ,
595
- "display_value" : "B" ,
596
- },
597
- {
598
- "class" : "blank col0" ,
599
- "type" : "th" ,
600
- "value" : self .blank_value ,
601
- "is_visible" : True ,
602
- "display_value" : self .blank_value ,
603
- },
604
- ]
605
- assert result ["head" ][1 ] == expected
606
-
607
577
def test_numeric_columns (self ):
608
578
# https://github.com/pandas-dev/pandas/issues/12125
609
579
# smoke test for _translate
@@ -1037,7 +1007,7 @@ def test_get_level_lengths_un_sorted(self):
1037
1007
tm .assert_dict_equal (result , expected )
1038
1008
1039
1009
def test_mi_sparse_index_names (self ):
1040
- # TODO this test is verbose can be minimised to more directly target test
1010
+ # Test the class names and displayed value are correct on rendering MI names
1041
1011
df = DataFrame (
1042
1012
{"A" : [1 , 2 ]},
1043
1013
index = MultiIndex .from_arrays (
@@ -1049,28 +1019,22 @@ def test_mi_sparse_index_names(self):
1049
1019
expected = [
1050
1020
{
1051
1021
"class" : "index_name level0" ,
1052
- "value" : "idx_level_0" ,
1053
- "type" : "th" ,
1054
- "is_visible" : True ,
1055
1022
"display_value" : "idx_level_0" ,
1023
+ "is_visible" : True ,
1056
1024
},
1057
1025
{
1058
1026
"class" : "index_name level1" ,
1059
- "value" : "idx_level_1" ,
1060
- "type" : "th" ,
1061
- "is_visible" : True ,
1062
1027
"display_value" : "idx_level_1" ,
1028
+ "is_visible" : True ,
1063
1029
},
1064
1030
{
1065
1031
"class" : "blank col0" ,
1066
- "value" : self .blank_value ,
1067
- "type" : "th" ,
1068
- "is_visible" : True ,
1069
1032
"display_value" : self .blank_value ,
1033
+ "is_visible" : True ,
1070
1034
},
1071
1035
]
1072
-
1073
- assert head == expected
1036
+ for i , expected_dict in enumerate ( expected ):
1037
+ assert expected_dict . items () <= head [ i ]. items ()
1074
1038
1075
1039
def test_mi_sparse_column_names (self ):
1076
1040
df = DataFrame (
@@ -1080,60 +1044,27 @@ def test_mi_sparse_column_names(self):
1080
1044
names = ["idx_level_0" , "idx_level_1" ],
1081
1045
),
1082
1046
columns = MultiIndex .from_arrays (
1083
- [["C1" , "C1" , "C2" , "C2" ], [1 , 0 , 1 , 0 ]], names = ["col_0 " , "col_1 " ]
1047
+ [["C1" , "C1" , "C2" , "C2" ], [1 , 0 , 1 , 0 ]], names = ["colnam_0 " , "colnam_1 " ]
1084
1048
),
1085
1049
)
1086
1050
result = Styler (df , cell_ids = False )._translate (True , True )
1087
- head = result ["head" ][1 ]
1088
- expected = [
1089
- {
1090
- "class" : "blank" ,
1091
- "value" : self .blank_value ,
1092
- "display_value" : self .blank_value ,
1093
- "type" : "th" ,
1094
- "is_visible" : True ,
1095
- },
1096
- {
1097
- "class" : "index_name level1" ,
1098
- "value" : "col_1" ,
1099
- "display_value" : "col_1" ,
1100
- "is_visible" : True ,
1101
- "type" : "th" ,
1102
- },
1103
- {
1104
- "class" : "col_heading level1 col0" ,
1105
- "display_value" : "1" ,
1106
- "is_visible" : True ,
1107
- "type" : "th" ,
1108
- "value" : 1 ,
1109
- "attributes" : "" ,
1110
- },
1111
- {
1112
- "class" : "col_heading level1 col1" ,
1113
- "display_value" : "0" ,
1114
- "is_visible" : True ,
1115
- "type" : "th" ,
1116
- "value" : 0 ,
1117
- "attributes" : "" ,
1118
- },
1119
- {
1120
- "class" : "col_heading level1 col2" ,
1121
- "display_value" : "1" ,
1122
- "is_visible" : True ,
1123
- "type" : "th" ,
1124
- "value" : 1 ,
1125
- "attributes" : "" ,
1126
- },
1127
- {
1128
- "class" : "col_heading level1 col3" ,
1129
- "display_value" : "0" ,
1130
- "is_visible" : True ,
1131
- "type" : "th" ,
1132
- "value" : 0 ,
1133
- "attributes" : "" ,
1134
- },
1135
- ]
1136
- assert head == expected
1051
+
1052
+ for level in [0 , 1 ]:
1053
+ head = result ["head" ][level ]
1054
+ expected = [
1055
+ {
1056
+ "class" : "blank" ,
1057
+ "display_value" : self .blank_value ,
1058
+ "is_visible" : True ,
1059
+ },
1060
+ {
1061
+ "class" : f"index_name level{ level } " ,
1062
+ "display_value" : f"colnam_{ level } " ,
1063
+ "is_visible" : True ,
1064
+ },
1065
+ ]
1066
+ for i , expected_dict in enumerate (expected ):
1067
+ assert expected_dict .items () <= head [i ].items ()
1137
1068
1138
1069
def test_hide_column_headers (self ):
1139
1070
ctx = self .styler .hide (axis = "columns" )._translate (True , True )
0 commit comments