From ca8f101ad7b51c512b19928d825ddedf35f52fe4 Mon Sep 17 00:00:00 2001 From: peterpanmj Date: Thu, 23 Aug 2018 12:57:11 +0800 Subject: [PATCH 1/5] BUG: series of extension array add extension array values cause runtime exception #22478 --- pandas/core/ops.py | 2 +- pandas/tests/arrays/test_integer.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/core/ops.py b/pandas/core/ops.py index a7fc2839ea101..ee65f81d1b737 100644 --- a/pandas/core/ops.py +++ b/pandas/core/ops.py @@ -1182,7 +1182,7 @@ def dispatch_to_extension_op(op, left, right): new_right = [new_right] new_right = list(new_right) elif is_extension_array_dtype(right) and type(left) != type(right): - new_right = list(new_right) + new_right = list(right) else: new_right = right diff --git a/pandas/tests/arrays/test_integer.py b/pandas/tests/arrays/test_integer.py index 349a6aee5701e..5a7246381fcb7 100644 --- a/pandas/tests/arrays/test_integer.py +++ b/pandas/tests/arrays/test_integer.py @@ -587,6 +587,14 @@ def test_cross_type_arithmetic(): tm.assert_series_equal(result, expected) +def test_arith_extension_array_values(): + + s = pd.Series([1, 2, 3], dtype='Int64') + result = s + s.values + expected = pd.Series([2, 4, 6], dtype='Int64') + tm.assert_series_equal(result, expected) + + def test_groupby_mean_included(): df = pd.DataFrame({ "A": ['a', 'b', 'b'], From 9736f38fea5a3b4a6fab9422936c6fcd7e37f4d0 Mon Sep 17 00:00:00 2001 From: peterpanmj Date: Tue, 18 Sep 2018 17:48:34 +0800 Subject: [PATCH 2/5] clear some style error --- pandas/tests/arrays/test_integer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/arrays/test_integer.py b/pandas/tests/arrays/test_integer.py index 5a7246381fcb7..acef48150acc5 100644 --- a/pandas/tests/arrays/test_integer.py +++ b/pandas/tests/arrays/test_integer.py @@ -588,7 +588,6 @@ def test_cross_type_arithmetic(): def test_arith_extension_array_values(): - s = pd.Series([1, 2, 3], dtype='Int64') result = s + s.values expected = pd.Series([2, 4, 6], dtype='Int64') From 4f7ada3148e72b42500dff0c173ac0ff255ce273 Mon Sep 17 00:00:00 2001 From: peterpanmj Date: Wed, 19 Sep 2018 11:23:21 +0800 Subject: [PATCH 3/5] update whatsnew and add issue number --- doc/source/whatsnew/v0.24.0.txt | 1 + pandas/tests/arrays/test_integer.py | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 9e2c20c78f489..a5fb869c683e8 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -493,6 +493,7 @@ ExtensionType Changes - :meth:`Series.combine()` with scalar argument now works for any function type (:issue:`21248`) - :meth:`Series.astype` and :meth:`DataFrame.astype` now dispatch to :meth:`ExtensionArray.astype` (:issue:`21185:`). - Added :meth:`pandas.api.types.register_extension_dtype` to register an extension type with pandas (:issue:`22664`) +- Bug in :meth:`pandas.core.ops.dispatch_to_extension_op` where addition of ``Series`` of ``IntegerArray`` and ``IntegerArray`` values raise runtime exception (:issue `22478`) .. _whatsnew_0240.api.incompatibilities: diff --git a/pandas/tests/arrays/test_integer.py b/pandas/tests/arrays/test_integer.py index acef48150acc5..0241cbf7c9b1b 100644 --- a/pandas/tests/arrays/test_integer.py +++ b/pandas/tests/arrays/test_integer.py @@ -588,6 +588,7 @@ def test_cross_type_arithmetic(): def test_arith_extension_array_values(): + # GH 22478 s = pd.Series([1, 2, 3], dtype='Int64') result = s + s.values expected = pd.Series([2, 4, 6], dtype='Int64') From 215d7f7d397e39519c4d79376f6c21659c66d75d Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Sun, 30 Sep 2018 11:34:30 -0500 Subject: [PATCH 4/5] Update v0.24.0.txt --- doc/source/whatsnew/v0.24.0.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index a5fb869c683e8..9e2c20c78f489 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -493,7 +493,6 @@ ExtensionType Changes - :meth:`Series.combine()` with scalar argument now works for any function type (:issue:`21248`) - :meth:`Series.astype` and :meth:`DataFrame.astype` now dispatch to :meth:`ExtensionArray.astype` (:issue:`21185:`). - Added :meth:`pandas.api.types.register_extension_dtype` to register an extension type with pandas (:issue:`22664`) -- Bug in :meth:`pandas.core.ops.dispatch_to_extension_op` where addition of ``Series`` of ``IntegerArray`` and ``IntegerArray`` values raise runtime exception (:issue `22478`) .. _whatsnew_0240.api.incompatibilities: From 7efeed85c77617827f3d8d4b957b89d16145e966 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 2 Oct 2018 21:16:08 -0500 Subject: [PATCH 5/5] Move test to base, implement --- pandas/tests/arrays/test_integer.py | 8 -------- pandas/tests/extension/base/ops.py | 6 ++++++ pandas/tests/extension/json/test_json.py | 5 +++++ pandas/tests/extension/test_categorical.py | 6 ++++++ pandas/tests/extension/test_integer.py | 6 ++++++ 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pandas/tests/arrays/test_integer.py b/pandas/tests/arrays/test_integer.py index 0241cbf7c9b1b..349a6aee5701e 100644 --- a/pandas/tests/arrays/test_integer.py +++ b/pandas/tests/arrays/test_integer.py @@ -587,14 +587,6 @@ def test_cross_type_arithmetic(): tm.assert_series_equal(result, expected) -def test_arith_extension_array_values(): - # GH 22478 - s = pd.Series([1, 2, 3], dtype='Int64') - result = s + s.values - expected = pd.Series([2, 4, 6], dtype='Int64') - tm.assert_series_equal(result, expected) - - def test_groupby_mean_included(): df = pd.DataFrame({ "A": ['a', 'b', 'b'], diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index 05351c56862b8..ee4a92146128b 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -77,6 +77,12 @@ def test_divmod(self, data): self._check_divmod_op(s, divmod, 1, exc=TypeError) self._check_divmod_op(1, ops.rdivmod, s, exc=TypeError) + def test_add_series_with_extension_array(self, data): + s = pd.Series(data) + result = s + data + expected = pd.Series(data + data) + self.assert_series_equal(result, expected) + def test_error(self, data, all_arithmetic_operators): # invalid ops op_name = all_arithmetic_operators diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index 0126d771caf7f..93f10b7fbfc23 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -261,6 +261,11 @@ class TestArithmeticOps(BaseJSON, base.BaseArithmeticOpsTests): def test_error(self, data, all_arithmetic_operators): pass + def test_add_series_with_extension_array(self, data): + ser = pd.Series(data) + with tm.assert_raises_regex(TypeError, "unsupported"): + ser + data + class TestComparisonOps(BaseJSON, base.BaseComparisonOpsTests): pass diff --git a/pandas/tests/extension/test_categorical.py b/pandas/tests/extension/test_categorical.py index ff66f53eab6f6..c588552572aed 100644 --- a/pandas/tests/extension/test_categorical.py +++ b/pandas/tests/extension/test_categorical.py @@ -22,6 +22,7 @@ from pandas.api.types import CategoricalDtype from pandas import Categorical from pandas.tests.extension import base +import pandas.util.testing as tm def make_data(): @@ -202,6 +203,11 @@ def test_arith_series_with_scalar(self, data, all_arithmetic_operators): else: pytest.skip('rmod never called when string is first argument') + def test_add_series_with_extension_array(self, data): + ser = pd.Series(data) + with tm.assert_raises_regex(TypeError, "cannot perform"): + ser + data + class TestComparisonOps(base.BaseComparisonOpsTests): diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index 7aa33006dadda..fa5c89d85e548 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -143,6 +143,12 @@ def test_error(self, data, all_arithmetic_operators): # other specific errors tested in the integer array specific tests pass + @pytest.mark.xfail(reason="EA is listified. GH-22922", strict=True) + def test_add_series_with_extension_array(self, data): + super(TestArithmeticOps, self).test_add_series_with_extension_array( + data + ) + class TestComparisonOps(base.BaseComparisonOpsTests):