Skip to content

BUG: Unary minus raises for series with Int64Dtype #36063

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
3 tasks done
mila opened this issue Sep 2, 2020 · 5 comments · Fixed by #36303
Closed
3 tasks done

BUG: Unary minus raises for series with Int64Dtype #36063

mila opened this issue Sep 2, 2020 · 5 comments · Fixed by #36303
Labels
NA - MaskedArrays Related to pd.NA and nullable extension arrays Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@mila
Copy link

mila commented Sep 2, 2020

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas (commit 73c1d32)


Code Sample, a copy-pastable example

>>> import pandas as pd
>>> pd.__version__
'1.1.1'
>>> s = pd.Series([1, 2, 3], dtype="Int64")
>>> -s
Traceback (most recent call last):
  File "...", line 1, in <module>
    -s
  File ".../lib/python3.8/site-packages/pandas/core/generic.py", line 1297, in __neg__
    arr = operator.neg(values)
TypeError: bad operand type for unary -: 'IntegerArray'

Problem description

I cannot negate series with Int64Dtype. This was possible in previous versions (but it returned object dtype).

Expected Output

>>> import pandas as pd
>>> pd.__version__
'1.0.5'
>>> s = pd.Series([1, 2, 3], dtype="Int64")
>>> -s
0    -1
1    -2
2    -3
dtype: object

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2ca0a2
python : 3.8.3.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.1
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.15.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@mila mila added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 2, 2020
@kokes
Copy link
Contributor

kokes commented Sep 2, 2020

Bisection identified 67aae80 as the first bad commit. (PR #32422)

bisect log

# bad: [d9fff2792bf16178d4e450fe7384244e50635733] RLS: 1.1.0
git bisect bad d9fff2792bf16178d4e450fe7384244e50635733
# good: [b687cd4d9e520666a956a60849568a98dd00c672] RLS: 1.0.5
git bisect good b687cd4d9e520666a956a60849568a98dd00c672
# good: [d3f08566a80239a18a813ebda9a2ebb0368b1dc5] RLS: 1.0.0rc0
git bisect good d3f08566a80239a18a813ebda9a2ebb0368b1dc5
# bad: [63957e46c789d5f891344cf335eaf8eaccabe5ba] Requested ASV (#33197)
git bisect bad 63957e46c789d5f891344cf335eaf8eaccabe5ba
# good: [c0066f32b4667744d7b86d680e7e3e5d9a08e33d] REG: dont call func on empty input (#32121)
git bisect good c0066f32b4667744d7b86d680e7e3e5d9a08e33d
# bad: [3b66021ecb74da2c35e16958121bd224d5de5264] TST: make tests stricter (#32527)
git bisect bad 3b66021ecb74da2c35e16958121bd224d5de5264
# good: [821aa25c9039e72da9a7b236cf2f9e7d549cbb7b] BUG: Fix __ne__ comparison for Categorical (#32304)
git bisect good 821aa25c9039e72da9a7b236cf2f9e7d549cbb7b
# bad: [09a46a4e465b19fa688f1d58124d266c0bbbebf0] DOC: Add extended summary, update parameter types desc, update return types desc, and add whitespaces after commas in list declarations to DataFrame.first in core/generic.py (#32018)
git bisect bad 09a46a4e465b19fa688f1d58124d266c0bbbebf0
# bad: [777c0f90c6067c636fcd76ce003a8fbfcc311d7b] CLN: remove unreachable _internal_get_values in blocks (#32472)
git bisect bad 777c0f90c6067c636fcd76ce003a8fbfcc311d7b
# bad: [86ed2b654abfe82adeba2bae7c4424377d428d91] PERF: lazify blknos and blklocs (#32261)
git bisect bad 86ed2b654abfe82adeba2bae7c4424377d428d91
# good: [d33b0025db0b2d79abe51343054d4c8bbed104c6] CLN: remove unreachable branch (#32405)
git bisect good d33b0025db0b2d79abe51343054d4c8bbed104c6
# bad: [67aae8028773eae231662e47ec2c46124ad4229e] CLN: avoid values_from_object in NDFrame (#32422)
git bisect bad 67aae8028773eae231662e47ec2c46124ad4229e
# good: [c5f0ebf8d92322445a4413c1bf9bd08e226583f0] TYP/cln: generic._make_*_function (#32363)
git bisect good c5f0ebf8d92322445a4413c1bf9bd08e226583f0
# good: [0d04683baaf65f6023fa83ab0d985726fb3c98b0] TST: Split and simplify test_value_counts_unique_nunique (#32281)
git bisect good 0d04683baaf65f6023fa83ab0d985726fb3c98b0
# first bad commit: [67aae8028773eae231662e47ec2c46124ad4229e] CLN: avoid values_from_object in NDFrame (#32422)

setup to reproduce

Ran bisection with this shell script, first good/bad commits are 1.0.5 and 1.1.0 releases respectively:

set -eu
python3 setup.py build_ext --inplace --force
python3 un.py

where un.py is

import pandas

s = pandas.Series([1, 2, 3], dtype="Int64")

print(-s)

@jorisvandenbossche jorisvandenbossche added NA - MaskedArrays Related to pd.NA and nullable extension arrays Regression Functionality that used to work in a prior pandas version and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 2, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.1.2 milestone Sep 2, 2020
@simonjayhawkins
Copy link
Member

simonjayhawkins commented Sep 7, 2020

moving off 1.1.2 milestone, xref #36081 (comment)

@simonjayhawkins simonjayhawkins modified the milestones: 1.1.2, 1.1.3 Sep 7, 2020
@simonjayhawkins
Copy link
Member

Bisection identified 67aae80 as the first bad commit. (PR #32422)

Thanks @kokes cc @jbrockmendel

@jbrockmendel
Copy link
Member

Yikes, returning object dtype in the old version is not great. This is just waiting for someone to implement IntegerArray.__neg__

@mila
Copy link
Author

mila commented Sep 14, 2020

Thank you @dsaxton and @jreback! You are doing amazing work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NA - MaskedArrays Related to pd.NA and nullable extension arrays Regression Functionality that used to work in a prior pandas version
Projects
None yet
5 participants