From 949656952b94b3c55a51ef3a758d1622f8f82bbc Mon Sep 17 00:00:00 2001 From: Jay <2594jaypatel@gmail.com> Date: Tue, 29 Jul 2025 01:03:51 -0400 Subject: [PATCH 01/14] BUG: Return NotImplemented for non-1D operands in BooleanArray ops; add tests for numeric EA shape errors --- pandas/core/arrays/boolean.py | 2 +- pandas/tests/arithmetic/test_numeric.py | 31 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 87c18fe346c62..1918898ad76f8 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -379,7 +379,7 @@ def _logical_method(self, other, op): # type: ignore[override] elif is_list_like(other): other = np.asarray(other, dtype="bool") if other.ndim > 1: - raise NotImplementedError("can only perform ops with 1-d structures") + return NotImplemented other, mask = coerce_to_array(other, copy=False) elif isinstance(other, np.bool_): other = other.item() diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index d205569270705..366b867b9fa03 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -564,6 +564,8 @@ def test_df_div_zero_series_does_not_commute(self): res2 = df / ser assert not res.fillna(0).equals(res2.fillna(0)) + + # ------------------------------------------------------------------ # Mod By Zero @@ -855,6 +857,35 @@ def test_modulo_zero_int(self): result = 0 % s expected = Series([np.nan, 0.0]) tm.assert_series_equal(result, expected) + + def test_np_array_mul_ea_array_returns_extensionarray(): + np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]) + ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]) + result = np_array * ea_array + tm.assert_isinstance(result, type(ea_array)) + tm.assert_equal(result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0])) + tm.assert_equal(result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0])) + + def test_df_mul_np_and_ea_array_shape_and_errors(): + df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values + NP_array = pd.array([i for i in range(10)], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(10, 1) + EA_array = pd.array([i for i in range(10)], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(10, 1) + + result_np = df * NP_array + tm.assert_isinstance(result_np, np.ndarray) + tm.assert_equal(result_np.shape, (10, 5)) + + with tm.assert_raises(TypeError): + _ = df * EA_array + + def test_non_1d_ea_raises_typeerror(): + ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(5, 1) + np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(5, 1) + + with tm.assert_raises(TypeError): + _ = ea_array * np_array + with tm.assert_raises(TypeError): + _ = np_array * ea_array class TestAdditionSubtraction: From 08e0e3734566e31402900644e54c088c334dc248 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Jul 2025 05:26:28 +0000 Subject: [PATCH 02/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/core/arrays/boolean.py | 2 +- pandas/tests/arithmetic/test_numeric.py | 34 ++++++++++++++++--------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 1918898ad76f8..812b507ea22c1 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -379,7 +379,7 @@ def _logical_method(self, other, op): # type: ignore[override] elif is_list_like(other): other = np.asarray(other, dtype="bool") if other.ndim > 1: - return NotImplemented + return NotImplemented other, mask = coerce_to_array(other, copy=False) elif isinstance(other, np.bool_): other = other.item() diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 366b867b9fa03..701ed244e6356 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -564,8 +564,6 @@ def test_df_div_zero_series_does_not_commute(self): res2 = df / ser assert not res.fillna(0).equals(res2.fillna(0)) - - # ------------------------------------------------------------------ # Mod By Zero @@ -857,35 +855,47 @@ def test_modulo_zero_int(self): result = 0 % s expected = Series([np.nan, 0.0]) tm.assert_series_equal(result, expected) - + def test_np_array_mul_ea_array_returns_extensionarray(): np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]) ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]) result = np_array * ea_array tm.assert_isinstance(result, type(ea_array)) - tm.assert_equal(result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0])) - tm.assert_equal(result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0])) + tm.assert_equal( + result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0]) + ) + tm.assert_equal( + result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0]) + ) def test_df_mul_np_and_ea_array_shape_and_errors(): df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values - NP_array = pd.array([i for i in range(10)], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(10, 1) - EA_array = pd.array([i for i in range(10)], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(10, 1) - + NP_array = pd.array( + [i for i in range(10)], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0] + ).reshape(10, 1) + EA_array = pd.array( + [i for i in range(10)], dtype=tm.SIGNED_INT_EA_DTYPES[0] + ).reshape(10, 1) + result_np = df * NP_array tm.assert_isinstance(result_np, np.ndarray) tm.assert_equal(result_np.shape, (10, 5)) with tm.assert_raises(TypeError): - _ = df * EA_array + _ = df * EA_array def test_non_1d_ea_raises_typeerror(): - ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(5, 1) - np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(5, 1) + ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape( + 5, 1 + ) + np_array = np.array( + [1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0] + ).reshape(5, 1) with tm.assert_raises(TypeError): _ = ea_array * np_array with tm.assert_raises(TypeError): - _ = np_array * ea_array + _ = np_array * ea_array class TestAdditionSubtraction: From f0c915793277547bedd0ae6e347368572e84ee94 Mon Sep 17 00:00:00 2001 From: Jay <2594jaypatel@gmail.com> Date: Tue, 29 Jul 2025 01:55:51 -0400 Subject: [PATCH 03/14] TST: fix test class methods and lint in test_numeric.py --- pandas/tests/arithmetic/test_numeric.py | 28 +++++++------------------ 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 701ed244e6356..1d8786a98d097 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -855,8 +855,8 @@ def test_modulo_zero_int(self): result = 0 % s expected = Series([np.nan, 0.0]) tm.assert_series_equal(result, expected) - - def test_np_array_mul_ea_array_returns_extensionarray(): + + def test_np_array_mul_ea_array_returns_extensionarray(self): np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]) ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]) result = np_array * ea_array @@ -864,19 +864,11 @@ def test_np_array_mul_ea_array_returns_extensionarray(): tm.assert_equal( result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0]) ) - tm.assert_equal( - result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0]) - ) - def test_df_mul_np_and_ea_array_shape_and_errors(): + def test_df_mul_np_and_ea_array_shape_and_errors(self): df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values - NP_array = pd.array( - [i for i in range(10)], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0] - ).reshape(10, 1) - EA_array = pd.array( - [i for i in range(10)], dtype=tm.SIGNED_INT_EA_DTYPES[0] - ).reshape(10, 1) - + NP_array = pd.array(list(range(10)), dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(10, 1) + EA_array = pd.array(list(range(10)), dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(10, 1) result_np = df * NP_array tm.assert_isinstance(result_np, np.ndarray) tm.assert_equal(result_np.shape, (10, 5)) @@ -884,13 +876,9 @@ def test_df_mul_np_and_ea_array_shape_and_errors(): with tm.assert_raises(TypeError): _ = df * EA_array - def test_non_1d_ea_raises_typeerror(): - ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape( - 5, 1 - ) - np_array = np.array( - [1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0] - ).reshape(5, 1) + def test_non_1d_ea_raises_typeerror(self): + ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(5, 1) + np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(5, 1) with tm.assert_raises(TypeError): _ = ea_array * np_array From ae5b4c185145a548d19aa42f44ce423bc597fd9b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Jul 2025 06:13:13 +0000 Subject: [PATCH 04/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/tests/arithmetic/test_numeric.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 1d8786a98d097..b17f47b4a893f 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -855,7 +855,7 @@ def test_modulo_zero_int(self): result = 0 % s expected = Series([np.nan, 0.0]) tm.assert_series_equal(result, expected) - + def test_np_array_mul_ea_array_returns_extensionarray(self): np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]) ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]) @@ -867,8 +867,12 @@ def test_np_array_mul_ea_array_returns_extensionarray(self): def test_df_mul_np_and_ea_array_shape_and_errors(self): df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values - NP_array = pd.array(list(range(10)), dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(10, 1) - EA_array = pd.array(list(range(10)), dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(10, 1) + NP_array = pd.array( + list(range(10)), dtype=tm.SIGNED_INT_NUMPY_DTYPES[0] + ).reshape(10, 1) + EA_array = pd.array(list(range(10)), dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape( + 10, 1 + ) result_np = df * NP_array tm.assert_isinstance(result_np, np.ndarray) tm.assert_equal(result_np.shape, (10, 5)) @@ -877,8 +881,12 @@ def test_df_mul_np_and_ea_array_shape_and_errors(self): _ = df * EA_array def test_non_1d_ea_raises_typeerror(self): - ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(5, 1) - np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(5, 1) + ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape( + 5, 1 + ) + np_array = np.array( + [1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0] + ).reshape(5, 1) with tm.assert_raises(TypeError): _ = ea_array * np_array From e8db6993a24127a6bb755b8ffd80b3f549b591be Mon Sep 17 00:00:00 2001 From: Jay <2594jaypatel@gmail.com> Date: Tue, 29 Jul 2025 12:59:13 -0400 Subject: [PATCH 05/14] TST: fix arithmetic tests for ExtensionArray and numpy, update asserts to use pytest --- pandas/tests/arithmetic/test_numeric.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index b17f47b4a893f..4d5d20737768c 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -860,7 +860,7 @@ def test_np_array_mul_ea_array_returns_extensionarray(self): np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]) ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]) result = np_array * ea_array - tm.assert_isinstance(result, type(ea_array)) + assert isinstance(result, type(ea_array)) tm.assert_equal( result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0]) ) @@ -874,10 +874,10 @@ def test_df_mul_np_and_ea_array_shape_and_errors(self): 10, 1 ) result_np = df * NP_array - tm.assert_isinstance(result_np, np.ndarray) + assert isinstance(result_np, np.ndarray) tm.assert_equal(result_np.shape, (10, 5)) - with tm.assert_raises(TypeError): + with pytest.raises(TypeError): _ = df * EA_array def test_non_1d_ea_raises_typeerror(self): @@ -888,9 +888,9 @@ def test_non_1d_ea_raises_typeerror(self): [1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0] ).reshape(5, 1) - with tm.assert_raises(TypeError): + with pytest.raises(TypeError): _ = ea_array * np_array - with tm.assert_raises(TypeError): + with pytest.raises(TypeError): _ = np_array * ea_array From 390fa8e9cbf18378ecd5c5a9c15775c148c5250c Mon Sep 17 00:00:00 2001 From: Jay <2594jaypatel@gmail.com> Date: Tue, 29 Jul 2025 13:40:44 -0400 Subject: [PATCH 06/14] BUG: Fix dtype and exception checks in arithmetic ExtensionArray tests --- pandas/tests/arithmetic/test_numeric.py | 29 ++++++++++--------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 4d5d20737768c..018853a9f50e9 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -857,40 +857,33 @@ def test_modulo_zero_int(self): tm.assert_series_equal(result, expected) def test_np_array_mul_ea_array_returns_extensionarray(self): - np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]) - ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]) + np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64) + ea_array = pd.array([1, 2, 3, 4, 5], dtype="Int64") result = np_array * ea_array assert isinstance(result, type(ea_array)) tm.assert_equal( - result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0]) + result, pd.array([1, 4, 9, 16, 25], dtype="Int64") ) def test_df_mul_np_and_ea_array_shape_and_errors(self): df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values - NP_array = pd.array( - list(range(10)), dtype=tm.SIGNED_INT_NUMPY_DTYPES[0] - ).reshape(10, 1) - EA_array = pd.array(list(range(10)), dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape( - 10, 1 - ) + NP_array = np.array( + list(range(10)), dtype=np.int64).reshape(10, 1) + EA_array = pd.array(list(range(10)), dtype="Int64").reshape(10, 1) result_np = df * NP_array assert isinstance(result_np, np.ndarray) tm.assert_equal(result_np.shape, (10, 5)) - with pytest.raises(TypeError): + with pytest.raises(NotImplementedError): _ = df * EA_array def test_non_1d_ea_raises_typeerror(self): - ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape( - 5, 1 - ) - np_array = np.array( - [1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0] - ).reshape(5, 1) + ea_array = pd.array([1, 2, 3, 4, 5], dtype="Int64").reshape(5, 1) + np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64).reshape(5, 1) - with pytest.raises(TypeError): + with pytest.raises(NotImplementedError): _ = ea_array * np_array - with pytest.raises(TypeError): + with pytest.raises(NotImplementedError): _ = np_array * ea_array From cb445f3c35b251a8522d69ad949e52dc40fb3c92 Mon Sep 17 00:00:00 2001 From: Jay <2594jaypatel@gmail.com> Date: Tue, 29 Jul 2025 14:33:31 -0400 Subject: [PATCH 07/14] TST: fix inconsistent-namespace-usage pre-commit errors by using --- pandas/tests/arithmetic/test_numeric.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 018853a9f50e9..0139250ed88a4 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -858,18 +858,18 @@ def test_modulo_zero_int(self): def test_np_array_mul_ea_array_returns_extensionarray(self): np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64) - ea_array = pd.array([1, 2, 3, 4, 5], dtype="Int64") + ea_array = array([1, 2, 3, 4, 5], dtype="Int64") result = np_array * ea_array assert isinstance(result, type(ea_array)) tm.assert_equal( - result, pd.array([1, 4, 9, 16, 25], dtype="Int64") + result, array([1, 4, 9, 16, 25], dtype="Int64") ) def test_df_mul_np_and_ea_array_shape_and_errors(self): df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values NP_array = np.array( list(range(10)), dtype=np.int64).reshape(10, 1) - EA_array = pd.array(list(range(10)), dtype="Int64").reshape(10, 1) + EA_array = array(list(range(10)), dtype="Int64").reshape(10, 1) result_np = df * NP_array assert isinstance(result_np, np.ndarray) tm.assert_equal(result_np.shape, (10, 5)) @@ -878,7 +878,7 @@ def test_df_mul_np_and_ea_array_shape_and_errors(self): _ = df * EA_array def test_non_1d_ea_raises_typeerror(self): - ea_array = pd.array([1, 2, 3, 4, 5], dtype="Int64").reshape(5, 1) + ea_array = array([1, 2, 3, 4, 5], dtype="Int64").reshape(5, 1) np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64).reshape(5, 1) with pytest.raises(NotImplementedError): From 7454a7d9684c829164c622f4de9e7bf28ca77da2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Jul 2025 18:43:33 +0000 Subject: [PATCH 08/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/tests/arithmetic/test_numeric.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 0139250ed88a4..9e3e7d6b3b1cb 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -861,14 +861,11 @@ def test_np_array_mul_ea_array_returns_extensionarray(self): ea_array = array([1, 2, 3, 4, 5], dtype="Int64") result = np_array * ea_array assert isinstance(result, type(ea_array)) - tm.assert_equal( - result, array([1, 4, 9, 16, 25], dtype="Int64") - ) + tm.assert_equal(result, array([1, 4, 9, 16, 25], dtype="Int64")) def test_df_mul_np_and_ea_array_shape_and_errors(self): df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values - NP_array = np.array( - list(range(10)), dtype=np.int64).reshape(10, 1) + NP_array = np.array(list(range(10)), dtype=np.int64).reshape(10, 1) EA_array = array(list(range(10)), dtype="Int64").reshape(10, 1) result_np = df * NP_array assert isinstance(result_np, np.ndarray) From 9ea174402035ddd6cf99e3560a9ad6d3563e2e09 Mon Sep 17 00:00:00 2001 From: Jay <2594jaypatel@gmail.com> Date: Wed, 30 Jul 2025 23:12:20 -0400 Subject: [PATCH 09/14] add match=, remove test, add GH#61866 reference --- pandas/tests/arithmetic/test_numeric.py | 30 ++++++++++++------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 9e3e7d6b3b1cb..ba0f3669f9539 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -857,31 +857,29 @@ def test_modulo_zero_int(self): tm.assert_series_equal(result, expected) def test_np_array_mul_ea_array_returns_extensionarray(self): + # GH#61866 np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64) ea_array = array([1, 2, 3, 4, 5], dtype="Int64") result = np_array * ea_array assert isinstance(result, type(ea_array)) tm.assert_equal(result, array([1, 4, 9, 16, 25], dtype="Int64")) - def test_df_mul_np_and_ea_array_shape_and_errors(self): - df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values - NP_array = np.array(list(range(10)), dtype=np.int64).reshape(10, 1) - EA_array = array(list(range(10)), dtype="Int64").reshape(10, 1) - result_np = df * NP_array - assert isinstance(result_np, np.ndarray) - tm.assert_equal(result_np.shape, (10, 5)) - - with pytest.raises(NotImplementedError): - _ = df * EA_array - - def test_non_1d_ea_raises_typeerror(self): + def test_non_1d_ea_raises_notimplementederror(self): + # GH#61866 ea_array = array([1, 2, 3, 4, 5], dtype="Int64").reshape(5, 1) np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64).reshape(5, 1) - with pytest.raises(NotImplementedError): - _ = ea_array * np_array - with pytest.raises(NotImplementedError): - _ = np_array * ea_array + with pytest.raises( + NotImplementedError, + match="non-1D ExtensionArray operations are not supported", + ): + ea_array * np_array + + with pytest.raises( + NotImplementedError, + match="non-1D ExtensionArray operations are not supported", + ): + np_array * ea_array class TestAdditionSubtraction: From 1ef4eb503b7ba026cc72b2576c44771f102171ab Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 31 Jul 2025 03:25:32 +0000 Subject: [PATCH 10/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/tests/arithmetic/test_numeric.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index ba0f3669f9539..198baf655d9ed 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -870,13 +870,13 @@ def test_non_1d_ea_raises_notimplementederror(self): np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64).reshape(5, 1) with pytest.raises( - NotImplementedError, + NotImplementedError, match="non-1D ExtensionArray operations are not supported", ): ea_array * np_array with pytest.raises( - NotImplementedError, + NotImplementedError, match="non-1D ExtensionArray operations are not supported", ): np_array * ea_array From 17159b6f040fa3c7af3cf4faab63873e65008039 Mon Sep 17 00:00:00 2001 From: Jay <2594jaypatel@gmail.com> Date: Wed, 30 Jul 2025 23:49:37 -0400 Subject: [PATCH 11/14] changed match= lines --- pandas/tests/arithmetic/test_numeric.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 198baf655d9ed..59140b01707f3 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -869,16 +869,12 @@ def test_non_1d_ea_raises_notimplementederror(self): ea_array = array([1, 2, 3, 4, 5], dtype="Int64").reshape(5, 1) np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64).reshape(5, 1) - with pytest.raises( - NotImplementedError, - match="non-1D ExtensionArray operations are not supported", - ): + msg = "can only perform ops with 1-d structures" + + with pytest.raises(NotImplementedError, match=msg): ea_array * np_array - with pytest.raises( - NotImplementedError, - match="non-1D ExtensionArray operations are not supported", - ): + with pytest.raises(NotImplementedError, match=msg): np_array * ea_array From 079547d4954d400579a3b2e96ec20b74676debc1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 31 Jul 2025 03:55:56 +0000 Subject: [PATCH 12/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/tests/arithmetic/test_numeric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 59140b01707f3..ae12ca892cd23 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -874,7 +874,7 @@ def test_non_1d_ea_raises_notimplementederror(self): with pytest.raises(NotImplementedError, match=msg): ea_array * np_array - with pytest.raises(NotImplementedError, match=msg): + with pytest.raises(NotImplementedError, match=msg): np_array * ea_array From f8fff382cc2f207d0633eaa7f3a694e5396c5c14 Mon Sep 17 00:00:00 2001 From: Jay <2594jaypatel@gmail.com> Date: Wed, 6 Aug 2025 11:18:35 -0400 Subject: [PATCH 13/14] removed 1d version --- pandas/tests/arithmetic/test_numeric.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index ae12ca892cd23..7a536c4ebda95 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -855,15 +855,7 @@ def test_modulo_zero_int(self): result = 0 % s expected = Series([np.nan, 0.0]) tm.assert_series_equal(result, expected) - - def test_np_array_mul_ea_array_returns_extensionarray(self): - # GH#61866 - np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64) - ea_array = array([1, 2, 3, 4, 5], dtype="Int64") - result = np_array * ea_array - assert isinstance(result, type(ea_array)) - tm.assert_equal(result, array([1, 4, 9, 16, 25], dtype="Int64")) - + def test_non_1d_ea_raises_notimplementederror(self): # GH#61866 ea_array = array([1, 2, 3, 4, 5], dtype="Int64").reshape(5, 1) From 672e7cc92af52c609839ac1c9bd04029e684f984 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 6 Aug 2025 15:24:45 +0000 Subject: [PATCH 14/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/tests/arithmetic/test_numeric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 7a536c4ebda95..2170957f8b7f2 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -855,7 +855,7 @@ def test_modulo_zero_int(self): result = 0 % s expected = Series([np.nan, 0.0]) tm.assert_series_equal(result, expected) - + def test_non_1d_ea_raises_notimplementederror(self): # GH#61866 ea_array = array([1, 2, 3, 4, 5], dtype="Int64").reshape(5, 1)