|
1 | 1 | import copy
|
2 | 2 | import textwrap
|
| 3 | +import re |
3 | 4 |
|
4 | 5 | import pytest
|
5 | 6 | import numpy as np
|
@@ -505,6 +506,14 @@ def test_uuid(self):
|
505 | 506 | assert result is styler
|
506 | 507 | assert result.uuid == 'aaa'
|
507 | 508 |
|
| 509 | + def test_unique_id(self): |
| 510 | + # See https://github.com/pandas-dev/pandas/issues/16780 |
| 511 | + df = pd.DataFrame({'a': [1, 3, 5, 6], 'b': [2, 4, 12, 21]}) |
| 512 | + result = df.style.render(uuid='test') |
| 513 | + assert 'test' in result |
| 514 | + ids = re.findall('id="(.*?)"', result) |
| 515 | + assert np.unique(ids).size == len(ids) |
| 516 | + |
508 | 517 | def test_table_styles(self):
|
509 | 518 | style = [{'selector': 'th', 'props': [('foo', 'bar')]}]
|
510 | 519 | styler = Styler(self.df, table_styles=style)
|
@@ -719,26 +728,29 @@ def test_mi_sparse(self):
|
719 | 728 | df = pd.DataFrame({'A': [1, 2]},
|
720 | 729 | index=pd.MultiIndex.from_arrays([['a', 'a'],
|
721 | 730 | [0, 1]]))
|
| 731 | + |
722 | 732 | result = df.style._translate()
|
723 | 733 | body_0 = result['body'][0][0]
|
724 | 734 | expected_0 = {
|
725 | 735 | "value": "a", "display_value": "a", "is_visible": True,
|
726 | 736 | "type": "th", "attributes": ["rowspan=2"],
|
727 |
| - "class": "row_heading level0 row0", |
| 737 | + "class": "row_heading level0 row0", "id": "level0_row0" |
728 | 738 | }
|
729 | 739 | tm.assert_dict_equal(body_0, expected_0)
|
730 | 740 |
|
731 | 741 | body_1 = result['body'][0][1]
|
732 | 742 | expected_1 = {
|
733 | 743 | "value": 0, "display_value": 0, "is_visible": True,
|
734 | 744 | "type": "th", "class": "row_heading level1 row0",
|
| 745 | + "id": "level1_row0" |
735 | 746 | }
|
736 | 747 | tm.assert_dict_equal(body_1, expected_1)
|
737 | 748 |
|
738 | 749 | body_10 = result['body'][1][0]
|
739 | 750 | expected_10 = {
|
740 | 751 | "value": 'a', "display_value": 'a', "is_visible": False,
|
741 | 752 | "type": "th", "class": "row_heading level0 row1",
|
| 753 | + "id": "level0_row1" |
742 | 754 | }
|
743 | 755 | tm.assert_dict_equal(body_10, expected_10)
|
744 | 756 |
|
|
0 commit comments