From 39ec7979fd4376d6ba94448e764c49701a9ffdaa Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Fri, 25 Dec 2020 15:42:46 +0700 Subject: [PATCH 01/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index d2d564be88942..5b768c1c233e3 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -208,6 +208,14 @@ def test_replace_with_dict_with_bool_keys(self): expected = pd.Series(["yes", False, "yes"]) tm.assert_series_equal(result, expected) + @pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64']) + def test_replace_int_with_na(self, dtype): + result = pd.Series([0, 1]).astype(dtype) + result.replace(0, pd.NA) + expected = pd.Series([0, None]).astype(dtype) + expected.fillna(0).replace(0, pd.NA) + tm.assert_series_equal(result, expected) + def test_replace2(self): N = 100 ser = pd.Series(np.fabs(np.random.randn(N)), tm.makeDateIndex(N), dtype=object) From a83dbcbb043044f8e30868d616174ab1dd498147 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Fri, 25 Dec 2020 16:08:27 +0700 Subject: [PATCH 02/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 5b768c1c233e3..0cd54e415ce34 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -210,7 +210,7 @@ def test_replace_with_dict_with_bool_keys(self): @pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64']) def test_replace_int_with_na(self, dtype): - result = pd.Series([0, 1]).astype(dtype) + result = pd.Series([0, None]).astype(dtype) result.replace(0, pd.NA) expected = pd.Series([0, None]).astype(dtype) expected.fillna(0).replace(0, pd.NA) From 3db04e75575098bbb373e627253fcc5f7051f7c6 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Sat, 26 Dec 2020 09:19:31 +0700 Subject: [PATCH 03/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 0cd54e415ce34..357fdc21a24b0 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -210,10 +210,9 @@ def test_replace_with_dict_with_bool_keys(self): @pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64']) def test_replace_int_with_na(self, dtype): - result = pd.Series([0, None]).astype(dtype) - result.replace(0, pd.NA) - expected = pd.Series([0, None]).astype(dtype) - expected.fillna(0).replace(0, pd.NA) + # GH 38267 + result = pd.Series([0, None]).astype(dtype).replace(0, pd.NA) + expected = pd.Series([0, None]).astype(dtype).fillna(0).replace(0, pd.NA) tm.assert_series_equal(result, expected) def test_replace2(self): From b8ccce5801e6401702f4910465c387f642139721 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Sat, 26 Dec 2020 10:26:32 +0700 Subject: [PATCH 04/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 357fdc21a24b0..30fe928bc98e3 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -208,7 +208,7 @@ def test_replace_with_dict_with_bool_keys(self): expected = pd.Series(["yes", False, "yes"]) tm.assert_series_equal(result, expected) - @pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64']) + @pytest.mark.parametrize("dtype", ["int8", "int16", "int32", "int64"]) def test_replace_int_with_na(self, dtype): # GH 38267 result = pd.Series([0, None]).astype(dtype).replace(0, pd.NA) From 9b3f075ca4ca0c437e8b8eab82cb6218b336c15f Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Sat, 26 Dec 2020 12:42:46 +0700 Subject: [PATCH 05/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 30fe928bc98e3..6218095b76b63 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -211,8 +211,9 @@ def test_replace_with_dict_with_bool_keys(self): @pytest.mark.parametrize("dtype", ["int8", "int16", "int32", "int64"]) def test_replace_int_with_na(self, dtype): # GH 38267 - result = pd.Series([0, None]).astype(dtype).replace(0, pd.NA) - expected = pd.Series([0, None]).astype(dtype).fillna(0).replace(0, pd.NA) + s = pd.Series([0, None]).astype(dtype) + result = s.replace(0, pd.NA) + expected = s.fillna(0).replace(0, pd.NA) tm.assert_series_equal(result, expected) def test_replace2(self): From 9d437ec74d28ca5a811327677a6a21580f6e1f56 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Sat, 26 Dec 2020 16:00:50 +0700 Subject: [PATCH 06/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 6218095b76b63..6aebba20f9e46 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -211,9 +211,8 @@ def test_replace_with_dict_with_bool_keys(self): @pytest.mark.parametrize("dtype", ["int8", "int16", "int32", "int64"]) def test_replace_int_with_na(self, dtype): # GH 38267 - s = pd.Series([0, None]).astype(dtype) - result = s.replace(0, pd.NA) - expected = s.fillna(0).replace(0, pd.NA) + result = pd.Series([0, None]).astype(dtype).replace(0, pd.NA) + expected = pd.Series([pd.NA, pd.NA]) tm.assert_series_equal(result, expected) def test_replace2(self): From 76e2fa6dadda218b9b5a51c3eda480abb25f521c Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Sun, 27 Dec 2020 09:15:52 +0700 Subject: [PATCH 07/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 6aebba20f9e46..3eb35ddb10e98 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -208,7 +208,7 @@ def test_replace_with_dict_with_bool_keys(self): expected = pd.Series(["yes", False, "yes"]) tm.assert_series_equal(result, expected) - @pytest.mark.parametrize("dtype", ["int8", "int16", "int32", "int64"]) + @pytest.mark.parametrize("dtype", ["Int8", "Int16", "Int32", "Int64"]) def test_replace_int_with_na(self, dtype): # GH 38267 result = pd.Series([0, None]).astype(dtype).replace(0, pd.NA) From 6320412b9f9518df195d816b0b38a05ef76028d5 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Sun, 27 Dec 2020 16:05:25 +0700 Subject: [PATCH 08/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 3eb35ddb10e98..043dfbb85644e 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -209,10 +209,10 @@ def test_replace_with_dict_with_bool_keys(self): tm.assert_series_equal(result, expected) @pytest.mark.parametrize("dtype", ["Int8", "Int16", "Int32", "Int64"]) - def test_replace_int_with_na(self, dtype): + def test_replace_Int_with_na(self, dtype): # GH 38267 - result = pd.Series([0, None]).astype(dtype).replace(0, pd.NA) - expected = pd.Series([pd.NA, pd.NA]) + result = pd.Series([0, None], dtype=dtype).replace(0, pd.NA) + expected = pd.Series([pd.NA, pd.NA], dtype=dtype) tm.assert_series_equal(result, expected) def test_replace2(self): From a5dc3c4c691fed17e961218811529cb65b1139f0 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Mon, 28 Dec 2020 05:30:29 +0700 Subject: [PATCH 09/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 043dfbb85644e..490b58b5b5af6 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -208,11 +208,15 @@ def test_replace_with_dict_with_bool_keys(self): expected = pd.Series(["yes", False, "yes"]) tm.assert_series_equal(result, expected) - @pytest.mark.parametrize("dtype", ["Int8", "Int16", "Int32", "Int64"]) - def test_replace_Int_with_na(self, dtype): + def test_replace_Int_with_na(self): # GH 38267 - result = pd.Series([0, None], dtype=dtype).replace(0, pd.NA) - expected = pd.Series([pd.NA, pd.NA], dtype=dtype) + from pandas.conftest import any_nullable_int_dtype + result = pd.Series([0, None], dtype=any_nullable_int_dtype).replace(0, pd.NA) + expected = pd.Series([pd.NA, pd.NA], dtype=any_nullable_int_dtype) + tm.assert_series_equal(result, expected) + + result = pd.Series([0, 1], dtype=any_nullable_int_dtype).replace(0, pd.NA) + expected = pd.Series([pd.NA, 1], dtype=any_nullable_int_dtype) tm.assert_series_equal(result, expected) def test_replace2(self): From ced83a6286e0e3af585007a3364fb02029a53d15 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Mon, 28 Dec 2020 06:34:02 +0700 Subject: [PATCH 10/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 490b58b5b5af6..1ab52870cac00 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -210,13 +210,10 @@ def test_replace_with_dict_with_bool_keys(self): def test_replace_Int_with_na(self): # GH 38267 - from pandas.conftest import any_nullable_int_dtype - result = pd.Series([0, None], dtype=any_nullable_int_dtype).replace(0, pd.NA) - expected = pd.Series([pd.NA, pd.NA], dtype=any_nullable_int_dtype) + result = pd.Series([0, None], dtype=pd.conftest.any_nullable_int_dtype).replace(0, pd.NA) + expected = pd.Series([pd.NA, pd.NA], dtype=pd.conftest.any_nullable_int_dtype) tm.assert_series_equal(result, expected) - - result = pd.Series([0, 1], dtype=any_nullable_int_dtype).replace(0, pd.NA) - expected = pd.Series([pd.NA, 1], dtype=any_nullable_int_dtype) + result = pd.Series([0, 1], dtype=pd.conftest.any_nullable_int_dtype).replace(0, pd.NA).replace(1, pd.NA) tm.assert_series_equal(result, expected) def test_replace2(self): From d486750fa671849b12ae725f8a9aa277b80f7ae5 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Mon, 28 Dec 2020 06:39:38 +0700 Subject: [PATCH 11/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 1ab52870cac00..59a7262b81234 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -208,12 +208,12 @@ def test_replace_with_dict_with_bool_keys(self): expected = pd.Series(["yes", False, "yes"]) tm.assert_series_equal(result, expected) - def test_replace_Int_with_na(self): + def test_replace_Int_with_na(self, any_nullable_int_dtype): # GH 38267 - result = pd.Series([0, None], dtype=pd.conftest.any_nullable_int_dtype).replace(0, pd.NA) - expected = pd.Series([pd.NA, pd.NA], dtype=pd.conftest.any_nullable_int_dtype) + result = pd.Series([0, None], dtype=any_nullable_int_dtype).replace(0, pd.NA) + expected = pd.Series([pd.NA, pd.NA], dtype=any_nullable_int_dtype) tm.assert_series_equal(result, expected) - result = pd.Series([0, 1], dtype=pd.conftest.any_nullable_int_dtype).replace(0, pd.NA).replace(1, pd.NA) + result = pd.Series([0, 1], dtype=any_nullable_int_dtype).replace(0, pd.NA).replace(1, pd.NA) tm.assert_series_equal(result, expected) def test_replace2(self): From d11fddcb09bcc07470d787b8361e350bbbe21db4 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Mon, 28 Dec 2020 08:34:51 +0700 Subject: [PATCH 12/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 59a7262b81234..1b48edd1b6106 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -213,7 +213,11 @@ def test_replace_Int_with_na(self, any_nullable_int_dtype): result = pd.Series([0, None], dtype=any_nullable_int_dtype).replace(0, pd.NA) expected = pd.Series([pd.NA, pd.NA], dtype=any_nullable_int_dtype) tm.assert_series_equal(result, expected) - result = pd.Series([0, 1], dtype=any_nullable_int_dtype).replace(0, pd.NA).replace(1, pd.NA) + result = ( ++ pd.Series([0, 1], dtype=any_nullable_int_dtype) ++ .replace(0, pd.NA) ++ .replace(1, pd.NA) ++ ) tm.assert_series_equal(result, expected) def test_replace2(self): From 778392cf3c29c83c3237664778b5cf0f3f5af332 Mon Sep 17 00:00:00 2001 From: ftrihardjo Date: Mon, 28 Dec 2020 08:59:28 +0700 Subject: [PATCH 13/13] pandas-dev issue #38267 --- pandas/tests/series/methods/test_replace.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 1b48edd1b6106..b619c9c9632e3 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -213,11 +213,8 @@ def test_replace_Int_with_na(self, any_nullable_int_dtype): result = pd.Series([0, None], dtype=any_nullable_int_dtype).replace(0, pd.NA) expected = pd.Series([pd.NA, pd.NA], dtype=any_nullable_int_dtype) tm.assert_series_equal(result, expected) - result = ( -+ pd.Series([0, 1], dtype=any_nullable_int_dtype) -+ .replace(0, pd.NA) -+ .replace(1, pd.NA) -+ ) + result = pd.Series([0, 1], dtype=any_nullable_int_dtype).replace(0, pd.NA) + result.replace(1, pd.NA, inplace=True) tm.assert_series_equal(result, expected) def test_replace2(self):