Skip to content

BUG: add col<k> class identifier to blank index name row cells #39807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ Other
- 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`)
- Bug in :class:`Styler` where ``subset`` arg in methods raised an error for some valid multiindex slices (:issue:`33562`)
- :class:`Styler` rendered HTML output minor alterations to support w3 good code standard (:issue:`39626`)
- Bug in :class:`Styler` where rendered HTML was missing a column class identifier for certain header cells (:issue:`39716`)
- Bug in :meth:`DataFrame.equals`, :meth:`Series.equals`, :meth:`Index.equals` with object-dtype containing ``np.datetime64("NaT")`` or ``np.timedelta64("NaT")`` (:issue:`39650`)


Expand Down
11 changes: 9 additions & 2 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,15 @@ def _translate(self):
)

index_header_row.extend(
[{"type": "th", "value": BLANK_VALUE, "class": " ".join([BLANK_CLASS])}]
* (len(clabels[0]) - len(hidden_columns))
[
{
"type": "th",
"value": BLANK_VALUE,
"class": " ".join([BLANK_CLASS, f"col{c}"]),
}
for c in range(len(clabels[0]))
if c not in hidden_columns
]
)

head.append(index_header_row)
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/io/formats/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ def test_index_name(self):
],
[
{"class": "index_name level0", "type": "th", "value": "A"},
{"class": "blank", "type": "th", "value": ""},
{"class": "blank", "type": "th", "value": ""},
{"class": "blank col0", "type": "th", "value": ""},
{"class": "blank col1", "type": "th", "value": ""},
],
]

Expand Down Expand Up @@ -293,7 +293,7 @@ def test_multiindex_name(self):
[
{"class": "index_name level0", "type": "th", "value": "A"},
{"class": "index_name level1", "type": "th", "value": "B"},
{"class": "blank", "type": "th", "value": ""},
{"class": "blank col0", "type": "th", "value": ""},
],
]

Expand Down Expand Up @@ -1537,7 +1537,7 @@ def test_mi_sparse_index_names(self):
expected = [
{"class": "index_name level0", "value": "idx_level_0", "type": "th"},
{"class": "index_name level1", "value": "idx_level_1", "type": "th"},
{"class": "blank", "value": "", "type": "th"},
{"class": "blank col0", "value": "", "type": "th"},
]

assert head == expected
Expand Down