| 597 | df.style._translate(True, True) |
| 598 | |
| 599 | def test_apply_axis(self): |
| 600 | df = DataFrame({"A": [0, 0], "B": [1, 1]}) |
| 601 | f = lambda x: [f"val: {x.max()}" for v in x] |
| 602 | result = df.style.apply(f, axis=1) |
| 603 | assert len(result._todo) == 1 |
| 604 | assert len(result.ctx) == 0 |
| 605 | result._compute() |
| 606 | expected = { |
| 607 | (0, 0): [("val", "1")], |
| 608 | (0, 1): [("val", "1")], |
| 609 | (1, 0): [("val", "1")], |
| 610 | (1, 1): [("val", "1")], |
| 611 | } |
| 612 | assert result.ctx == expected |
| 613 | |
| 614 | result = df.style.apply(f, axis=0) |
| 615 | expected = { |
| 616 | (0, 0): [("val", "0")], |
| 617 | (0, 1): [("val", "1")], |
| 618 | (1, 0): [("val", "0")], |
| 619 | (1, 1): [("val", "1")], |
| 620 | } |
| 621 | result._compute() |
| 622 | assert result.ctx == expected |
| 623 | result = df.style.apply(f) # default |
| 624 | result._compute() |
| 625 | assert result.ctx == expected |
| 626 | |
| 627 | @pytest.mark.parametrize("axis", [0, 1]) |
| 628 | def test_apply_series_return(self, axis): |