From 46c994ca4af42f0988ce0ec15439849404949ee6 Mon Sep 17 00:00:00 2001 From: debnathshoham Date: Sat, 31 Jul 2021 15:22:21 +0530 Subject: [PATCH 1/8] TST: raising ValueError when inserting one dataframe in another --- pandas/tests/frame/indexing/test_insert.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/tests/frame/indexing/test_insert.py b/pandas/tests/frame/indexing/test_insert.py index 4f5ec8eff29a6..84b05b8248097 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -89,3 +89,9 @@ def test_insert_item_cache(self, using_array_manager): ser.values[0] = 99 assert df.iloc[0, 0] == df[0][0] + + def test_insert_frame(self): + df = DataFrame({"col1": [1, 2], "col2": [3, 4]}) + msg = "Wrong number of items passed 2, placement implies 1" + with pytest.raises(ValueError, match=msg): + df.insert(1, "newcol", df) From c5f17ac3d3f66817c164b274842aee88d0e9a1aa Mon Sep 17 00:00:00 2001 From: debnathshoham Date: Sat, 31 Jul 2021 15:23:37 +0530 Subject: [PATCH 2/8] added GH issue reference --- pandas/tests/frame/indexing/test_insert.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/frame/indexing/test_insert.py b/pandas/tests/frame/indexing/test_insert.py index 84b05b8248097..c1a57f1031b0c 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -91,6 +91,7 @@ def test_insert_item_cache(self, using_array_manager): assert df.iloc[0, 0] == df[0][0] def test_insert_frame(self): + # GH#42403 df = DataFrame({"col1": [1, 2], "col2": [3, 4]}) msg = "Wrong number of items passed 2, placement implies 1" with pytest.raises(ValueError, match=msg): From 45464d79433ac0a1207ef1143eb12a4a18572ca0 Mon Sep 17 00:00:00 2001 From: debnathshoham Date: Sun, 1 Aug 2021 15:04:22 +0530 Subject: [PATCH 3/8] rev msg --- pandas/tests/frame/indexing/test_insert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/indexing/test_insert.py b/pandas/tests/frame/indexing/test_insert.py index c1a57f1031b0c..8a664b12294e0 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -93,6 +93,6 @@ def test_insert_item_cache(self, using_array_manager): def test_insert_frame(self): # GH#42403 df = DataFrame({"col1": [1, 2], "col2": [3, 4]}) - msg = "Wrong number of items passed 2, placement implies 1" + msg = "Expected a 1D array, got an array with shape (2, 2)" with pytest.raises(ValueError, match=msg): df.insert(1, "newcol", df) From 785283e1b2d9c21fd9a28569f1167253edef83d2 Mon Sep 17 00:00:00 2001 From: debnathshoham Date: Wed, 4 Aug 2021 20:15:43 +0530 Subject: [PATCH 4/8] included both msgs --- pandas/tests/frame/indexing/test_insert.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/frame/indexing/test_insert.py b/pandas/tests/frame/indexing/test_insert.py index 8a664b12294e0..16fdfd1ad2f2e 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -93,6 +93,7 @@ def test_insert_item_cache(self, using_array_manager): def test_insert_frame(self): # GH#42403 df = DataFrame({"col1": [1, 2], "col2": [3, 4]}) - msg = "Expected a 1D array, got an array with shape (2, 2)" + msg = r"Expected a 1D array, got an array with shape\ + \(2, 2\)|Wrong number of items passed 2, placement implies 1" with pytest.raises(ValueError, match=msg): df.insert(1, "newcol", df) From 078165a6dfab31aa1924e760d451d39ec0d5e1bb Mon Sep 17 00:00:00 2001 From: debnathshoham Date: Wed, 4 Aug 2021 21:53:37 +0530 Subject: [PATCH 5/8] updated --- pandas/tests/frame/indexing/test_insert.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/frame/indexing/test_insert.py b/pandas/tests/frame/indexing/test_insert.py index 16fdfd1ad2f2e..14880c9ff5915 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -93,7 +93,9 @@ def test_insert_item_cache(self, using_array_manager): def test_insert_frame(self): # GH#42403 df = DataFrame({"col1": [1, 2], "col2": [3, 4]}) - msg = r"Expected a 1D array, got an array with shape\ - \(2, 2\)|Wrong number of items passed 2, placement implies 1" + msg = ( + "Expected a 1D array, got an array with shape " + "(2, 2)|Wrong number of items passed 2, placement implies 1" + ) with pytest.raises(ValueError, match=msg): df.insert(1, "newcol", df) From f7f0590c9b3666098dc3af474bca01e6b9f8cb19 Mon Sep 17 00:00:00 2001 From: Shoham Debnath Date: Wed, 4 Aug 2021 22:38:15 +0530 Subject: [PATCH 6/8] Update test_insert.py --- pandas/tests/frame/indexing/test_insert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/indexing/test_insert.py b/pandas/tests/frame/indexing/test_insert.py index 14880c9ff5915..b6df8d5eacd97 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -95,7 +95,7 @@ def test_insert_frame(self): df = DataFrame({"col1": [1, 2], "col2": [3, 4]}) msg = ( "Expected a 1D array, got an array with shape " - "(2, 2)|Wrong number of items passed 2, placement implies 1" + "\(2, 2\)|Wrong number of items passed 2, placement implies 1" ) with pytest.raises(ValueError, match=msg): df.insert(1, "newcol", df) From 242da5544981c6ac1ec06452170d71383c2815db Mon Sep 17 00:00:00 2001 From: Shoham Debnath Date: Wed, 4 Aug 2021 22:43:50 +0530 Subject: [PATCH 7/8] Update test_insert.py --- pandas/tests/frame/indexing/test_insert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/indexing/test_insert.py b/pandas/tests/frame/indexing/test_insert.py index b6df8d5eacd97..e34084d755a7c 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -95,7 +95,7 @@ def test_insert_frame(self): df = DataFrame({"col1": [1, 2], "col2": [3, 4]}) msg = ( "Expected a 1D array, got an array with shape " - "\(2, 2\)|Wrong number of items passed 2, placement implies 1" + r"\(2, 2\)|Wrong number of items passed 2, placement implies 1" ) with pytest.raises(ValueError, match=msg): df.insert(1, "newcol", df) From 5e7c49c51acfba56753a486bd807bcfbc1e9112a Mon Sep 17 00:00:00 2001 From: Shoham Debnath Date: Wed, 4 Aug 2021 22:44:28 +0530 Subject: [PATCH 8/8] Update test_insert.py --- pandas/tests/frame/indexing/test_insert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/indexing/test_insert.py b/pandas/tests/frame/indexing/test_insert.py index e34084d755a7c..c2c862be42625 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -95,7 +95,7 @@ def test_insert_frame(self): df = DataFrame({"col1": [1, 2], "col2": [3, 4]}) msg = ( "Expected a 1D array, got an array with shape " - r"\(2, 2\)|Wrong number of items passed 2, placement implies 1" + r"\(2, 2\)|Wrong number of items passed 2, placement implies 1" ) with pytest.raises(ValueError, match=msg): df.insert(1, "newcol", df)