From 72c99828fd649d3767026ca02b11059ce310cdbf Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Thu, 6 Aug 2020 16:45:26 +0200 Subject: [PATCH 1/4] BUG: fix styler cell_ids arg so that blank style is ignored on False --- 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 fd1efa2d1b668..584f42a6cab12 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -390,7 +390,7 @@ def format_attr(pair): "is_visible": (c not in hidden_columns), } # only add an id if the cell has a style - if self.cell_ids or not (len(ctx[r, c]) == 1 and ctx[r, c][0] == ""): + if self.cell_ids or (r, c) in ctx: row_dict["id"] = "_".join(cs[1:]) row_es.append(row_dict) props = [] From ae39773c9d98388d6f042c2fd9960cca68346b4c Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Thu, 6 Aug 2020 18:48:51 +0200 Subject: [PATCH 2/4] BUG: fix styler cell_ids arg so that blank style is ignored on False --- 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 9c6910637fa7e..d3472e40bf249 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1682,6 +1682,11 @@ def f(a, b, styler): result = styler.pipe((f, "styler"), a=1, b=2) assert result == (1, 2, styler) + def test_no_cell_ids(self): + df = pd.DataFrame(data=[[0]]) + s = Styler(df, uuid='_', cell_ids=False).render() + assert s.find('') != -1 + @td.skip_if_no_mpl class TestStylerMatplotlibDep: From 0489e4fdf4aa2bf3d9891873ed9c9a0ac9b2c6b6 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Fri, 7 Aug 2020 09:19:14 +0200 Subject: [PATCH 3/4] BUG: fix styler cell_ids arg so that blank style is ignored on False --- doc/source/whatsnew/v1.1.1.rst | 1 + pandas/tests/io/formats/test_style.py | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v1.1.1.rst b/doc/source/whatsnew/v1.1.1.rst index 6a327a4fc732f..f9efd86ea1087 100644 --- a/doc/source/whatsnew/v1.1.1.rst +++ b/doc/source/whatsnew/v1.1.1.rst @@ -26,6 +26,7 @@ Fixed regressions Bug fixes ~~~~~~~~~ +- Bug in ``Styler`` whereby `cell_ids` argument had no effect due to other recent changes (:issue:`35588`). Categorical ^^^^^^^^^^^ diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index d3472e40bf249..c2a88d29b46c1 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1683,6 +1683,7 @@ def f(a, b, styler): assert result == (1, 2, styler) def test_no_cell_ids(self): + # GH 35588 df = pd.DataFrame(data=[[0]]) s = Styler(df, uuid='_', cell_ids=False).render() assert s.find('') != -1 From 2db75df8ca0d2d85132a8f4a3bf933cac17e34a2 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 7 Aug 2020 10:29:12 +0100 Subject: [PATCH 4/4] black fixup --- 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 c2a88d29b46c1..3ef5157655e78 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1685,7 +1685,7 @@ def f(a, b, styler): def test_no_cell_ids(self): # GH 35588 df = pd.DataFrame(data=[[0]]) - s = Styler(df, uuid='_', cell_ids=False).render() + s = Styler(df, uuid="_", cell_ids=False).render() assert s.find('') != -1