Skip to content

Commit 5008ece

Browse files
authored
CLN: Todo test reductions in test_style.py (#44750)
1 parent f9ecd53 commit 5008ece

File tree

1 file changed

+24
-93
lines changed

1 file changed

+24
-93
lines changed

pandas/tests/io/formats/style/test_style.py

+24-93
Original file line numberDiff line numberDiff line change
@@ -574,36 +574,6 @@ def test_index_name(self):
574574
}
575575
assert expected.items() <= result["head"][1][0].items()
576576

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-
607577
def test_numeric_columns(self):
608578
# https://github.com/pandas-dev/pandas/issues/12125
609579
# smoke test for _translate
@@ -1037,7 +1007,7 @@ def test_get_level_lengths_un_sorted(self):
10371007
tm.assert_dict_equal(result, expected)
10381008

10391009
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
10411011
df = DataFrame(
10421012
{"A": [1, 2]},
10431013
index=MultiIndex.from_arrays(
@@ -1049,28 +1019,22 @@ def test_mi_sparse_index_names(self):
10491019
expected = [
10501020
{
10511021
"class": "index_name level0",
1052-
"value": "idx_level_0",
1053-
"type": "th",
1054-
"is_visible": True,
10551022
"display_value": "idx_level_0",
1023+
"is_visible": True,
10561024
},
10571025
{
10581026
"class": "index_name level1",
1059-
"value": "idx_level_1",
1060-
"type": "th",
1061-
"is_visible": True,
10621027
"display_value": "idx_level_1",
1028+
"is_visible": True,
10631029
},
10641030
{
10651031
"class": "blank col0",
1066-
"value": self.blank_value,
1067-
"type": "th",
1068-
"is_visible": True,
10691032
"display_value": self.blank_value,
1033+
"is_visible": True,
10701034
},
10711035
]
1072-
1073-
assert head == expected
1036+
for i, expected_dict in enumerate(expected):
1037+
assert expected_dict.items() <= head[i].items()
10741038

10751039
def test_mi_sparse_column_names(self):
10761040
df = DataFrame(
@@ -1080,60 +1044,27 @@ def test_mi_sparse_column_names(self):
10801044
names=["idx_level_0", "idx_level_1"],
10811045
),
10821046
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"]
10841048
),
10851049
)
10861050
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()
11371068

11381069
def test_hide_column_headers(self):
11391070
ctx = self.styler.hide(axis="columns")._translate(True, True)

0 commit comments

Comments
 (0)