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

pandas 0.23 broke unary negative expression on Decimal data type #21380

Closed
rbu opened this Issue Jun 8, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@rbu

rbu commented Jun 8, 2018

Code Sample, a copy-pastable example if possible

import pandas as pd
from decimal import Decimal as D
series = pd.Series([D(1)])
print(series)
print(-(series))

Problem description

I'm dealing with decimal data where exact representation is required, thus I use Python's Decimal type with pandas. With the update from 0.22 to 0.23, the unary negative expression broke.

Expected Output (from 0.22)

>>> import pandas as pd
>>> from decimal import Decimal as D
>>> series = pd.Series([D(1)])
>>> print(series)
0    1
dtype: object
>>> print(-(series))
0    -1
dtype: object

Actual Output (from 0.23)

>>> import pandas as pd
>>> from decimal import Decimal as D
>>> series = pd.Series([D(1)])
>>> print(series)
0    1
dtype: object
>>> print(-(series))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "python3.6/site-packages/pandas/core/generic.py", line 1124, in __neg__
    .format(values.dtype))
TypeError: Unary negative expects numeric dtype, not object

Workaround (in 0.23)

Broadcasting against 0 has the expected effect:

>>> 0-series
0    -1
dtype: object
>>> (0-series).iloc[0]
Decimal('-1')

Output of pd.show_versions()

>>> pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.16.13-300.fc28.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.0
pytest: None
pip: 9.0.3
setuptools: 38.5.1
Cython: None
numpy: 1.14.4
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: 0.4.1
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: 1.1.15
pymysql: None
psycopg2: 2.7.3.2 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jorisvandenbossche

This comment has been minimized.

Member

jorisvandenbossche commented Jun 8, 2018

@rbu Thanks for the report. I tagged it as a regression for now, we should further look into the reason for the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment