Skip to content
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
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Styler
^^^^^^

- New method :meth:`.Styler.to_string` for alternative customisable output methods (:issue:`44502`)
- Various bug fixes, see below.

.. _whatsnew_150.enhancements.enhancement2:

Expand Down Expand Up @@ -206,7 +207,7 @@ ExtensionArray

Styler
^^^^^^
-
- Minor bug when attempting to apply styling functions to an empty DataFrame subset (:issue:`45313`)
-

Other
Expand Down
4 changes: 3 additions & 1 deletion pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,9 @@ def _apply(
subset = slice(None) if subset is None else subset
subset = non_reducing_slice(subset)
data = self.data.loc[subset]
if axis is None:
if data.empty:
result = DataFrame()
elif axis is None:
result = func(data, **kwargs)
if not isinstance(result, DataFrame):
if not isinstance(result, np.ndarray):
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/io/formats/style/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,3 +1548,9 @@ def test_col_trimming_hide_columns():
assert ctx["head"][0][c + 2]["is_visible"] == vals[1]

assert len(ctx["body"][0]) == 6 # index + 2 hidden + 2 visible + trimming col


def test_no_empty_apply(mi_styler):
# 45313
mi_styler.apply(lambda s: ["a:v;"] * 2, subset=[False, False])
mi_styler._compute()