Skip to content

Commit 4ca4dd3

Browse files
authored
BUG: add col<k> class identifier to blank index name row cells (#39807)
1 parent f937909 commit 4ca4dd3

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ Other
474474
- Bug in :func:`pandas.testing.assert_series_equal`, :func:`pandas.testing.assert_frame_equal`, :func:`pandas.testing.assert_index_equal` and :func:`pandas.testing.assert_extension_array_equal` incorrectly raising when an attribute has an unrecognized NA type (:issue:`39461`)
475475
- Bug in :class:`Styler` where ``subset`` arg in methods raised an error for some valid multiindex slices (:issue:`33562`)
476476
- :class:`Styler` rendered HTML output minor alterations to support w3 good code standard (:issue:`39626`)
477+
- Bug in :class:`Styler` where rendered HTML was missing a column class identifier for certain header cells (:issue:`39716`)
477478
- Bug in :meth:`DataFrame.equals`, :meth:`Series.equals`, :meth:`Index.equals` with object-dtype containing ``np.datetime64("NaT")`` or ``np.timedelta64("NaT")`` (:issue:`39650`)
478479

479480

pandas/io/formats/style.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,15 @@ def _translate(self):
484484
)
485485

486486
index_header_row.extend(
487-
[{"type": "th", "value": BLANK_VALUE, "class": " ".join([BLANK_CLASS])}]
488-
* (len(clabels[0]) - len(hidden_columns))
487+
[
488+
{
489+
"type": "th",
490+
"value": BLANK_VALUE,
491+
"class": " ".join([BLANK_CLASS, f"col{c}"]),
492+
}
493+
for c in range(len(clabels[0]))
494+
if c not in hidden_columns
495+
]
489496
)
490497

491498
head.append(index_header_row)

pandas/tests/io/formats/test_style.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ def test_index_name(self):
254254
],
255255
[
256256
{"class": "index_name level0", "type": "th", "value": "A"},
257-
{"class": "blank", "type": "th", "value": ""},
258-
{"class": "blank", "type": "th", "value": ""},
257+
{"class": "blank col0", "type": "th", "value": ""},
258+
{"class": "blank col1", "type": "th", "value": ""},
259259
],
260260
]
261261

@@ -293,7 +293,7 @@ def test_multiindex_name(self):
293293
[
294294
{"class": "index_name level0", "type": "th", "value": "A"},
295295
{"class": "index_name level1", "type": "th", "value": "B"},
296-
{"class": "blank", "type": "th", "value": ""},
296+
{"class": "blank col0", "type": "th", "value": ""},
297297
],
298298
]
299299

@@ -1537,7 +1537,7 @@ def test_mi_sparse_index_names(self):
15371537
expected = [
15381538
{"class": "index_name level0", "value": "idx_level_0", "type": "th"},
15391539
{"class": "index_name level1", "value": "idx_level_1", "type": "th"},
1540-
{"class": "blank", "value": "", "type": "th"},
1540+
{"class": "blank col0", "value": "", "type": "th"},
15411541
]
15421542

15431543
assert head == expected

0 commit comments

Comments
 (0)