Skip to content
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

BUG: TypeError: bad operand type for unary -: 'FloatingArray' #38749

Closed
2 of 3 tasks
hbaniecki opened this issue Dec 28, 2020 · 6 comments · Fixed by #39916
Closed
2 of 3 tasks

BUG: TypeError: bad operand type for unary -: 'FloatingArray' #38749

hbaniecki opened this issue Dec 28, 2020 · 6 comments · Fixed by #39916
Assignees
Labels
Bug good first issue NA - MaskedArrays Related to pd.NA and nullable extension arrays
Milestone

Comments

@hbaniecki
Copy link

hbaniecki commented Dec 28, 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.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd
x = pd.Series([1, 2, 3], dtype=pd.Float32Dtype())
-x

Problem description

Should it generate an error?

TypeError: bad operand type for unary -: 'FloatingArray'

Expected Output

-1 * x
# like -pd.Series([1, 2, 3])

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 3e89b4c
python : 3.8.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 126 Stepping 5, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_Europe.1252

pandas : 1.2.0
numpy : 1.19.3
pytz : 2020.4
dateutil : 2.8.1
pip : 20.2.2
setuptools : 49.2.1
Cython : 0.29.14
pytest : 6.0.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.0
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : None
tabulate : 0.8.7
xarray : None
xlrd : 1.2.0
xlwt : None
numba : 0.51.1

@hbaniecki hbaniecki added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 28, 2020
@simonjayhawkins
Copy link
Member

cc @jorisvandenbossche

@simonjayhawkins simonjayhawkins added NA - MaskedArrays Related to pd.NA and nullable extension arrays and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 28, 2020
@hbaniecki
Copy link
Author

hbaniecki commented Dec 28, 2020

Also: I use ctrl+f in the patch notes and search for convert_dtypes - there is nothing new. Yet, in API docs we see: Changed in version 1.2: Starting with pandas 1.2, this method also converts float columns to the nullable floating extension type.

hbaniecki added a commit to ModelOriented/DALEX that referenced this issue Dec 28, 2020
Even after the `-1 * x` fix, ALE plots looked like straight lines pandas-dev/pandas#38749
@jorisvandenbossche
Copy link
Member

@hbaniecki thanks for the report. This was fixed for Integer dtype (#36303), but should clearly also fix it for Float dtype

@mroldrobot
Copy link

Hi all,
I faced with a similar issue when trying to perform an elementary operation with Float data type array:

df = pd.DataFrame([1.1,2.1,3.1,4.1], columns=['x'])
df = df.convert_dtypes()
df['x1'] = -df.x

I got:

TypeError: bad operand type for unary -: 'FloatingArray'

for pandas v 1.2.1 and python v 3.7.9

@zitorelova
Copy link
Contributor

I'll have a look at this one.

@zitorelova
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug good first issue NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants