Repository: pandas-dev/pandas

Issue:
BUG: Series(extension array) + extension array values addition cause runtime exception
#### Code Sample, a copy-pastable example if possible

```python
In [41]: s
Out[41]:
0    1
1    2
2    3
dtype: Int64

In [42]: s.values
Out[42]: IntegerArray([1, 2, 3], dtype='Int64')

In [43]: s + s.values
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-43-c3f015376225> in <module>()
----> 1 s + s.values

C:\Users\Public\pandas-peter\pandas\core\ops.py in wrapper(left, right)
   1231                 (is_extension_array_dtype(right) and not is_scalar(right
))):
   1232             # GH#22378 disallow scalar to exclude e.g. "category", "Int6
4"
-> 1233             return dispatch_to_extension_op(op, left, right)
   1234
   1235         elif is_datetime64_dtype(left) or is_datetime64tz_dtype(left):

C:\Users\Public\pandas-peter\pandas\core\ops.py in dispatch_to_extension_op(op,
left, right)
   1152             new_right = list(new_right)
   1153         elif is_extension_array_dtype(right) and type(left) != type(righ
t):
-> 1154             new_right = list(new_right)
   1155         else:
   1156             new_right = right

UnboundLocalError: local variable 'new_right' referenced before assignment

```
#### Problem description
Extension array add itself cause problems

#### Expected Output
In [2]: s + s.values
Out[2]:
0    2
1    4
2    6
dtype: Int64

#### Output of ``pd.show_versions()``

<details>
INSTALLED VERSIONS
------------------
commit: 2be2ba570453ab09f0c8da46dfd8e1a179771fee
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: zh_CN.UTF-8
LOCALE: None.None

pandas: 0.24.0.dev0+506.g2be2ba570
pytest: 3.7.1
pip: 9.0.1
setuptools: 38.4.0
Cython: 0.28.4
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.7
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.2
openpyxl: 2.4.10
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.1
pymysql: 0.7.11.None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

</details>



Discussion:

Resolving patch:
diff --git a/pandas/core/ops.py b/pandas/core/ops.py
--- a/pandas/core/ops.py
+++ b/pandas/core/ops.py
@@ -1218,7 +1218,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
 


Test patch:
diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py
--- 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
--- 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
--- 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
--- 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):