Skip to content

Commit 48c2f4c

Browse files
committed
BUG: Ignore style column headers when None
1 parent a15248a commit 48c2f4c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pandas/core/style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def _translate(self):
216216
"class": " ".join(cs)})
217217
head.append(row_es)
218218

219-
if self.data.index.names:
219+
if self.data.index.names and self.data.index.names != [None]:
220220
index_header_row = []
221221

222222
for c, name in enumerate(self.data.index.names):

pandas/tests/test_style.py

+21
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,27 @@ def test_set_properties_subset(self):
129129
expected = {(0, 0): ['color: white']}
130130
self.assertEqual(result, expected)
131131

132+
def test_empty_index_name_doesnt_display(self):
133+
# https://github.com/pydata/pandas/pull/12090#issuecomment-180695902
134+
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4], 'C': [5, 6]})
135+
result = df.style._translate()
136+
137+
expected = [[{'class': 'blank', 'type': 'th', 'value': ''},
138+
{'class': 'col_heading level0 col0',
139+
'display_value': 'A',
140+
'type': 'th',
141+
'value': 'A'},
142+
{'class': 'col_heading level0 col1',
143+
'display_value': 'B',
144+
'type': 'th',
145+
'value': 'B'},
146+
{'class': 'col_heading level0 col2',
147+
'display_value': 'C',
148+
'type': 'th',
149+
'value': 'C'}]]
150+
151+
self.assertEqual(result['head'], expected)
152+
132153
def test_index_name(self):
133154
# https://github.com/pydata/pandas/issues/11655
134155
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4], 'C': [5, 6]})

0 commit comments

Comments
 (0)