From 3afef5599c9547a411e15db638102d4a1856b710 Mon Sep 17 00:00:00 2001 From: phofl Date: Mon, 7 Sep 2020 21:45:49 +0200 Subject: [PATCH 1/3] Add test for 16784 --- pandas/tests/frame/methods/test_replace.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandas/tests/frame/methods/test_replace.py b/pandas/tests/frame/methods/test_replace.py index ea2488dfc0877..3b656f5c2a634 100644 --- a/pandas/tests/frame/methods/test_replace.py +++ b/pandas/tests/frame/methods/test_replace.py @@ -1599,3 +1599,16 @@ def test_replace_intervals(self): result = df.replace({"a": {pd.Interval(0, 1): "x"}}) expected = pd.DataFrame({"a": ["x", "x"]}) tm.assert_frame_equal(result, expected) + + def test_replace_unicode(self): + columns_values_map = { + 'positive': { + '正面': 1, + '中立': 1, + '负面': 0 + } + } + df1 = pd.DataFrame({'positive': np.ones(3)}) + result = df1.replace(columns_values_map) + expected = pd.DataFrame({'positive': np.ones(3)}) + tm.assert_frame_equal(result, expected) From 0ee7585df776d38af8dfd4cc5f890f3d7c199100 Mon Sep 17 00:00:00 2001 From: phofl Date: Mon, 7 Sep 2020 21:47:10 +0200 Subject: [PATCH 2/3] Run black pandas --- pandas/tests/frame/methods/test_replace.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pandas/tests/frame/methods/test_replace.py b/pandas/tests/frame/methods/test_replace.py index 3b656f5c2a634..7876499ded97a 100644 --- a/pandas/tests/frame/methods/test_replace.py +++ b/pandas/tests/frame/methods/test_replace.py @@ -1601,14 +1601,8 @@ def test_replace_intervals(self): tm.assert_frame_equal(result, expected) def test_replace_unicode(self): - columns_values_map = { - 'positive': { - '正面': 1, - '中立': 1, - '负面': 0 - } - } - df1 = pd.DataFrame({'positive': np.ones(3)}) + columns_values_map = {"positive": {"正面": 1, "中立": 1, "负面": 0}} + df1 = pd.DataFrame({"positive": np.ones(3)}) result = df1.replace(columns_values_map) - expected = pd.DataFrame({'positive': np.ones(3)}) + expected = pd.DataFrame({"positive": np.ones(3)}) tm.assert_frame_equal(result, expected) From f35be342257af56a4745e0abbe63bdd715570e88 Mon Sep 17 00:00:00 2001 From: phofl Date: Mon, 7 Sep 2020 21:47:31 +0200 Subject: [PATCH 3/3] Add gh issue number --- pandas/tests/frame/methods/test_replace.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/frame/methods/test_replace.py b/pandas/tests/frame/methods/test_replace.py index 7876499ded97a..a77753ed9f9d0 100644 --- a/pandas/tests/frame/methods/test_replace.py +++ b/pandas/tests/frame/methods/test_replace.py @@ -1601,6 +1601,7 @@ def test_replace_intervals(self): tm.assert_frame_equal(result, expected) def test_replace_unicode(self): + # GH: 16784 columns_values_map = {"positive": {"正面": 1, "中立": 1, "负面": 0}} df1 = pd.DataFrame({"positive": np.ones(3)}) result = df1.replace(columns_values_map)