Skip to content

BUG: Series(extension array) + extension array values addition cause runtime exception #22478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
peterpanmj opened this issue Aug 23, 2018 · 2 comments · Fixed by #22479
Closed
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays.
Milestone

Comments

@peterpanmj
Copy link
Contributor

Code Sample, a copy-pastable example if possible

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()

INSTALLED VERSIONS ------------------ commit: 2be2ba5 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

@jorisvandenbossche
Copy link
Member

Thanks for the report. Yes, this is a know bug (#22325 (comment)), and fixed along the way in that linked PR.
But given that will probably still take some time to get fixed, seems fine to already fix just that with your PR.

@jorisvandenbossche
Copy link
Member

BTW, it is not because it are the values of itself, but a problem of series + array in general

@jorisvandenbossche jorisvandenbossche changed the title BUG: extension array add values of itself cause cause runtime exception BUG: Series(extension array) + extension array values addition cause runtime exception Aug 23, 2018
peterpanmj added a commit to peterpanmj/pandas that referenced this issue Sep 16, 2018
peterpanmj added a commit to peterpanmj/pandas that referenced this issue Sep 17, 2018
peterpanmj added a commit to peterpanmj/pandas that referenced this issue Sep 18, 2018
@jreback jreback added this to the 0.24.0 milestone Sep 18, 2018
peterpanmj added a commit to peterpanmj/pandas that referenced this issue Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants