From 16c2001f3fc6c7091de81dcc7cc5cefea4a910a8 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Thu, 31 Dec 2020 16:26:27 +0700 Subject: [PATCH 1/9] pandas-dev issue #25744 --- pandas/tests/series/methods/test_update.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index d00a4299cb690..23645eef17122 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -3,7 +3,7 @@ from pandas import CategoricalDtype, DataFrame, NaT, Series, Timestamp import pandas._testing as tm - +import pandas as pd class TestUpdate: def test_update(self): @@ -108,3 +108,11 @@ def test_update_from_non_series(self, series, other, expected): def test_update_extension_array_series(self, result, target, expected): result.update(target) tm.assert_series_equal(result, expected) + def test_update_categoricaldtype(self): + # GH 25744 + cats = pd.api.types.CategoricalDtype(['a', 'b', 'c', 'd']) + s1 = Series(['a', 'b', 'c'], index=[1, 2, 3], dtype=cats) + s2 = Series(['b', 'a'], index=[1, 2], dtype=cats) + result = s1.update(s2) + expected = Series({1 : "b", 2 : "a", 3 : "c"}, dtype = cats) + tm.assert_series_equal(result, expected) From 6e3176ef76b440c9a6e0d3476101b951b82155b0 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Fri, 1 Jan 2021 15:22:57 +0700 Subject: [PATCH 2/9] pandas-dev issue #27338 --- pandas/tests/dtypes/test_dtypes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 8ba8562affb67..dd95b6e9983ca 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -218,6 +218,12 @@ def test_repr_range_categories(self): expected = "CategoricalDtype(categories=range(0, 3), ordered=False)" assert result == expected + def test_update_dtype(self): + # GH 27338 + result = CategoricalDtype(['a']).update_dtype(Categorical(['b'], ordered=True)) + expected = CategoricalDtype(['b'], ordered=True) + assert result == expected + class TestDatetimeTZDtype(Base): @pytest.fixture From 0d2df961e7af27751daabd81c462b56bd36a391b Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Fri, 1 Jan 2021 15:34:10 +0700 Subject: [PATCH 3/9] pandas-dev issue #25744 --- pandas/tests/series/methods/test_update.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index 23645eef17122..8ee300985fe7c 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -3,7 +3,7 @@ from pandas import CategoricalDtype, DataFrame, NaT, Series, Timestamp import pandas._testing as tm -import pandas as pd + class TestUpdate: def test_update(self): @@ -108,11 +108,10 @@ def test_update_from_non_series(self, series, other, expected): def test_update_extension_array_series(self, result, target, expected): result.update(target) tm.assert_series_equal(result, expected) - def test_update_categoricaldtype(self): - # GH 25744 - cats = pd.api.types.CategoricalDtype(['a', 'b', 'c', 'd']) - s1 = Series(['a', 'b', 'c'], index=[1, 2, 3], dtype=cats) - s2 = Series(['b', 'a'], index=[1, 2], dtype=cats) + def test_update_with_categorical_type(self): + t = CategoricalDtype(["a", "b", "c", "d"]) + s1 = Series(["a", "b", "c"], index=[1, 2, 3], dtype=t) + s2 = Series(["b", "a"], index=[1, 2], dtype=t) result = s1.update(s2) - expected = Series({1 : "b", 2 : "a", 3 : "c"}, dtype = cats) + expected = Series(["b", "a", "c"], index=[1, 2, 3], dtype=t) tm.assert_series_equal(result, expected) From bcc927a902828b261ccd01a03a5b0db86cc94bf8 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Fri, 1 Jan 2021 15:35:57 +0700 Subject: [PATCH 4/9] pandas-dev issue #25744 --- pandas/tests/series/methods/test_update.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index 8ee300985fe7c..1773d72976768 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -109,6 +109,7 @@ def test_update_extension_array_series(self, result, target, expected): result.update(target) tm.assert_series_equal(result, expected) def test_update_with_categorical_type(self): + # GH 25744 t = CategoricalDtype(["a", "b", "c", "d"]) s1 = Series(["a", "b", "c"], index=[1, 2, 3], dtype=t) s2 = Series(["b", "a"], index=[1, 2], dtype=t) From 1e2561fc0f7ef63bea6d3b2a8fa3c2bd9d71c9ec Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Fri, 1 Jan 2021 16:15:31 +0700 Subject: [PATCH 5/9] pandas-dev issue #27338 --- pandas/tests/dtypes/test_dtypes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index dd95b6e9983ca..410731820dc73 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -220,8 +220,8 @@ def test_repr_range_categories(self): def test_update_dtype(self): # GH 27338 - result = CategoricalDtype(['a']).update_dtype(Categorical(['b'], ordered=True)) - expected = CategoricalDtype(['b'], ordered=True) + result = CategoricalDtype(["a"]).update_dtype(Categorical(["b"], ordered=True)) + expected = CategoricalDtype(["b"], ordered=True) assert result == expected From e8d0bbcc2dbc5b249cd036a23807f332441ad073 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Fri, 1 Jan 2021 16:34:50 +0700 Subject: [PATCH 6/9] pandas-dev issue #25744 --- pandas/tests/series/methods/test_update.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index 1773d72976768..f682ecab05099 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -110,9 +110,9 @@ def test_update_extension_array_series(self, result, target, expected): tm.assert_series_equal(result, expected) def test_update_with_categorical_type(self): # GH 25744 - t = CategoricalDtype(["a", "b", "c", "d"]) - s1 = Series(["a", "b", "c"], index=[1, 2, 3], dtype=t) - s2 = Series(["b", "a"], index=[1, 2], dtype=t) + t = CategoricalDtype(['a', 'b', 'c', 'd']) + s1 = Series(['a', 'b', 'c'], index=[1, 2, 3], dtype=t) + s2 = Series(['b', 'a'], index=[1, 2], dtype=t) result = s1.update(s2) - expected = Series(["b", "a", "c"], index=[1, 2, 3], dtype=t) + expected = Series(['b', 'a', 'c'], index=[1, 2, 3], dtype=t) tm.assert_series_equal(result, expected) From f7958feebc65e5902ed8ea1e0761a3c70d128b9a Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Sat, 2 Jan 2021 05:07:59 +0700 Subject: [PATCH 7/9] pandas-dev issue #25744 --- pandas/tests/series/methods/test_update.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index f682ecab05099..f609da835250d 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -108,11 +108,12 @@ def test_update_from_non_series(self, series, other, expected): def test_update_extension_array_series(self, result, target, expected): result.update(target) tm.assert_series_equal(result, expected) + def test_update_with_categorical_type(self): # GH 25744 - t = CategoricalDtype(['a', 'b', 'c', 'd']) - s1 = Series(['a', 'b', 'c'], index=[1, 2, 3], dtype=t) - s2 = Series(['b', 'a'], index=[1, 2], dtype=t) + dtype = CategoricalDtype(['a', 'b', 'c', 'd']) + s1 = Series(['a', 'b', 'c'], index=[1, 2, 3], dtype=dtype) + s2 = Series(['b', 'a'], index=[1, 2], dtype=dtype) result = s1.update(s2) - expected = Series(['b', 'a', 'c'], index=[1, 2, 3], dtype=t) + expected = Series(['b', 'a', 'c'], index=[1, 2, 3], dtype=dtype) tm.assert_series_equal(result, expected) From ff645715a567f56cf45115ebc68c41fd43653344 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Sat, 2 Jan 2021 16:41:53 +0700 Subject: [PATCH 8/9] pandas-dev issue #25744 --- pandas/tests/series/methods/test_update.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index f609da835250d..659ed3d22f772 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -111,9 +111,9 @@ def test_update_extension_array_series(self, result, target, expected): def test_update_with_categorical_type(self): # GH 25744 - dtype = CategoricalDtype(['a', 'b', 'c', 'd']) - s1 = Series(['a', 'b', 'c'], index=[1, 2, 3], dtype=dtype) - s2 = Series(['b', 'a'], index=[1, 2], dtype=dtype) + dtype = CategoricalDtype(["a", "b", "c", "d"]) + s1 = Series(["a", "b", "c"], index=[1, 2, 3], dtype=dtype) + s2 = Series(["b", "a"], index=[1, 2], dtype=dtype) result = s1.update(s2) - expected = Series(['b', 'a', 'c'], index=[1, 2, 3], dtype=dtype) + expected = Series(["b", "a", "c"], index=[1, 2, 3], dtype=dtype) tm.assert_series_equal(result, expected) From dfc92bbfe1071f3562c384f7c341559eba6de830 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Sun, 3 Jan 2021 09:03:11 +0700 Subject: [PATCH 9/9] pandas-dev issue #25744 --- pandas/tests/series/methods/test_update.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index 659ed3d22f772..51760c451ebca 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -114,6 +114,7 @@ def test_update_with_categorical_type(self): dtype = CategoricalDtype(["a", "b", "c", "d"]) s1 = Series(["a", "b", "c"], index=[1, 2, 3], dtype=dtype) s2 = Series(["b", "a"], index=[1, 2], dtype=dtype) - result = s1.update(s2) + s1.update(s2) + result = s1 expected = Series(["b", "a", "c"], index=[1, 2, 3], dtype=dtype) tm.assert_series_equal(result, expected)