From ca7291484f0f1b20a704fb9ffa5e13cf7bf80f9c Mon Sep 17 00:00:00 2001 From: sofiane87 Date: Sat, 2 Nov 2019 12:34:10 +0000 Subject: [PATCH 1/4] TST: Adding styler applymap multindex & code test [Ref: #25858] --- pandas/tests/io/formats/test_style.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index 0f1402d7da389..cd0c6b46f4cb5 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -376,6 +376,26 @@ def color_negative_red(val): (df.style.applymap(color_negative_red, subset=idx[:, idx["b", "d"]]).render()) + def test_applymap_subset_multiindex_code(self): + codes = np.array([[0, 0, 1, 1], [0, 1, 0, 1]]) + columns = pd.MultiIndex( + levels=[["a", "b"], ["%", "#"]], codes=codes, names=["", ""] + ) + df = DataFrame( + [[1, -1, 1, 1], [-1, 1, 1, 1]], index=["hello", "world"], columns=columns + ) + pct_subset = pd.IndexSlice[:, pd.IndexSlice[:, "%":"%"]] + + def color_negative_red(val): + color = "red" if val < 0 else "black" + return "color: %s" % color + + # Works on both 0.22 and 0.24. + df.loc[pct_subset] + + # This works on 0.22, but `TypeError: unhashable type` on 0.24! + df.style.applymap(color_negative_red, subset=pct_subset) + def test_where_with_one_style(self): # GH 17474 def f(x): From a27ec51cb0e8e7033ddfde0e7cff45d182796201 Mon Sep 17 00:00:00 2001 From: sofiane87 Date: Sat, 2 Nov 2019 12:45:18 +0000 Subject: [PATCH 2/4] removing commits removing comments --- pandas/tests/io/formats/test_style.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index cd0c6b46f4cb5..e120f57f2c7f1 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -390,10 +390,7 @@ def color_negative_red(val): color = "red" if val < 0 else "black" return "color: %s" % color - # Works on both 0.22 and 0.24. df.loc[pct_subset] - - # This works on 0.22, but `TypeError: unhashable type` on 0.24! df.style.applymap(color_negative_red, subset=pct_subset) def test_where_with_one_style(self): From a407ac2ca2701b48e16bf57ac0af86533e8fd382 Mon Sep 17 00:00:00 2001 From: sofiane87 Date: Sat, 2 Nov 2019 16:45:48 +0000 Subject: [PATCH 3/4] Adding Issue number commit --- pandas/tests/io/formats/test_style.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index e120f57f2c7f1..dd6129e5989a3 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -377,6 +377,7 @@ def color_negative_red(val): (df.style.applymap(color_negative_red, subset=idx[:, idx["b", "d"]]).render()) def test_applymap_subset_multiindex_code(self): + # https://github.com/pandas-dev/pandas/issues/25858 codes = np.array([[0, 0, 1, 1], [0, 1, 0, 1]]) columns = pd.MultiIndex( levels=[["a", "b"], ["%", "#"]], codes=codes, names=["", ""] From 0ad6af4274328866a9759eb56fefce2a43783321 Mon Sep 17 00:00:00 2001 From: sofiane87 Date: Sat, 2 Nov 2019 16:49:52 +0000 Subject: [PATCH 4/4] Adding one-liner comment --- pandas/tests/io/formats/test_style.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index dd6129e5989a3..0e88f5433c33b 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -378,6 +378,7 @@ def color_negative_red(val): def test_applymap_subset_multiindex_code(self): # https://github.com/pandas-dev/pandas/issues/25858 + # Checks styler.applymap works with multindex when codes are provided codes = np.array([[0, 0, 1, 1], [0, 1, 0, 1]]) columns = pd.MultiIndex( levels=[["a", "b"], ["%", "#"]], codes=codes, names=["", ""]