From afeaf58c7885ca83d29df54a344c5302ac2e9290 Mon Sep 17 00:00:00 2001 From: JoseNavy Date: Wed, 16 Dec 2020 16:59:13 -0700 Subject: [PATCH 1/9] BUG: Fix HTML formatting error in Styler.render() in rowspan attribute --- pandas/io/formats/style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 4557c10927a15..6ed31f38893dc 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -389,7 +389,7 @@ def format_attr(pair): rowspan = idx_lengths.get((c, r), 0) if rowspan > 1: es["attributes"] = [ - format_attr({"key": "rowspan", "value": rowspan}) + format_attr({"key": "rowspan", "value": f'"{rowspan}"'}) ] row_es.append(es) From 8bfffc6dd27007415efbb8279762a7f0b73d0091 Mon Sep 17 00:00:00 2001 From: JoseNavy Date: Wed, 16 Dec 2020 17:22:33 -0700 Subject: [PATCH 2/9] TST: Add test Styler.render() in rowspan attribute --- pandas/tests/io/formats/test_style.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index 64fe8a7730ae2..5c6fbdfca0ca6 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1740,6 +1740,11 @@ def test_colspan_w3(self): s = Styler(df, uuid="_", cell_ids=False) assert 'l0' in s.render() + def test_rowspan_w3(self): + df = DataFrame(data=[[1, 2]], index=[["l0", "l0"], ["l1a", "l1b"]]) + s = Styler(df, uuid="_", cell_ids=False) + assert 'l0' in s.render() + @pytest.mark.parametrize("len_", [1, 5, 32, 33, 100]) def test_uuid_len(self, len_): # GH 36345 From b1fba287130e1df289220d55afd61cde14406706 Mon Sep 17 00:00:00 2001 From: JoseNavy Date: Wed, 16 Dec 2020 17:43:47 -0700 Subject: [PATCH 3/9] Fix issue with flake8 --- pandas/tests/io/formats/test_style.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index 5c6fbdfca0ca6..a754ebc1715fc 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1743,7 +1743,10 @@ def test_colspan_w3(self): def test_rowspan_w3(self): df = DataFrame(data=[[1, 2]], index=[["l0", "l0"], ["l1a", "l1b"]]) s = Styler(df, uuid="_", cell_ids=False) - assert 'l0' in s.render() + assert ( + 'l0' + in s.render() + ) @pytest.mark.parametrize("len_", [1, 5, 32, 33, 100]) def test_uuid_len(self, len_): From 19ed3bb558218f068d83d156d06e243ce9aaaa5a Mon Sep 17 00:00:00 2001 From: JoseNavy Date: Wed, 16 Dec 2020 18:03:41 -0700 Subject: [PATCH 4/9] Fix whitespace issue with flake8 --- pandas/tests/io/formats/test_style.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index a754ebc1715fc..f5ca49b5df7e2 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1741,10 +1741,12 @@ def test_colspan_w3(self): assert 'l0' in s.render() def test_rowspan_w3(self): + # GH 38533 df = DataFrame(data=[[1, 2]], index=[["l0", "l0"], ["l1a", "l1b"]]) s = Styler(df, uuid="_", cell_ids=False) assert ( - 'l0' + 'l0' in s.render() ) From 4f63d26ac983f4d739aab09c32a4850a7d7a28d7 Mon Sep 17 00:00:00 2001 From: JoseNavy Date: Wed, 16 Dec 2020 18:13:08 -0700 Subject: [PATCH 5/9] Fix format issue with flake8 --- pandas/tests/io/formats/test_style.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index f5ca49b5df7e2..3f9bf7eeeb3a8 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1746,8 +1746,7 @@ def test_rowspan_w3(self): s = Styler(df, uuid="_", cell_ids=False) assert ( 'l0' - in s.render() + ' level0 row0" rowspan="2">l0' in s.render() ) @pytest.mark.parametrize("len_", [1, 5, 32, 33, 100]) From 7b5cdf9e31fb42d1404c36f4ac4a982681bcbd0e Mon Sep 17 00:00:00 2001 From: JoseNavy Date: Thu, 17 Dec 2020 10:02:55 -0700 Subject: [PATCH 6/9] Fix bad spacing in starting line --- pandas/tests/io/formats/test_style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index 3f9bf7eeeb3a8..f82132b27bd17 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1745,8 +1745,8 @@ def test_rowspan_w3(self): df = DataFrame(data=[[1, 2]], index=[["l0", "l0"], ["l1a", "l1b"]]) s = Styler(df, uuid="_", cell_ids=False) assert ( - 'l0' in s.render() + 'l0' in s.render() ) @pytest.mark.parametrize("len_", [1, 5, 32, 33, 100]) From 4355b2b53d341907460eda33a3276219103b3cc9 Mon Sep 17 00:00:00 2001 From: JoseNavy Date: Thu, 17 Dec 2020 11:04:28 -0700 Subject: [PATCH 7/9] Fix test_mi_sparse to accept new changes --- pandas/tests/io/formats/test_style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index f82132b27bd17..0bb422658df25 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1411,7 +1411,7 @@ def test_mi_sparse(self): "display_value": "a", "is_visible": True, "type": "th", - "attributes": ["rowspan=2"], + "attributes": ['rowspan="2"'], "class": "row_heading level0 row0", "id": "level0_row0", } From f89494c996a2c75f60ab0f03716cc2b384bf2301 Mon Sep 17 00:00:00 2001 From: JoseNavy Date: Tue, 22 Dec 2020 11:10:01 -0700 Subject: [PATCH 8/9] Whatsnew entry v1.2 --- doc/source/whatsnew/v1.2.0.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index e2521cedb64cc..2ec444066d97f 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -766,6 +766,10 @@ Plotting - Bug in :meth:`DataFrame.plot` and :meth:`Series.plot` was overwriting matplotlib's shared y axes behaviour when no ``sharey`` parameter was passed (:issue:`37942`) - Bug in :meth:`DataFrame.plot` was raising a ``TypeError`` with ``ExtensionDtype`` columns (:issue:`32073`) +Styler +^^^^^^ + +- Bug in :meth:`Styler.render` HTML was generated incorrectly beacause of formatting error in rowspan attribute, it now matches with w3 syntax. Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ From 16080e7af0b7ff4601d4fecc5e126330d51a7f0a Mon Sep 17 00:00:00 2001 From: JoseNavy Date: Tue, 22 Dec 2020 11:13:21 -0700 Subject: [PATCH 9/9] Whatsnew entry v1.2, added issue number --- doc/source/whatsnew/v1.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 2ec444066d97f..c4e1ecaf57c19 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -769,7 +769,7 @@ Plotting Styler ^^^^^^ -- Bug in :meth:`Styler.render` HTML was generated incorrectly beacause of formatting error in rowspan attribute, it now matches with w3 syntax. +- Bug in :meth:`Styler.render` HTML was generated incorrectly beacause of formatting error in rowspan attribute, it now matches with w3 syntax. (:issue:`38234`) Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^