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: Divide zero by zero returns NaN in a Float64 dtype column which cannot be handled by fillna #40704

Closed
3 tasks done
jaspersival opened this issue Mar 31, 2021 · 2 comments
Closed
3 tasks done
Labels
Bug Duplicate Report Duplicate issue or pull request Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@jaspersival
Copy link

jaspersival commented Mar 31, 2021

  • 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

series1 = pd.Series([0.], dtype=pd.Float64Dtype())
series2 = pd.Series([0.], dtype=pd.Float64Dtype())
series1/series2
0    NaN
dtype: Float64
(series1/series2).fillna(0)
0    NaN
dtype: Float64

Problem description

When dividing a pd.Float64Dtype series by another of the same type, and if there is a zero by zero division taking place, then pandas returns a NaN value for that particular case. If I want to replace this NaN value with something else, I cannot do that.
I can only get it to work if I do:

(series1/series2).astype(float).astype(pd.Float64Dtype()).fillna(0)
0    0.0
dtype: Float64

Expected Output

(series1/series2).fillna(0)
0    0.0
dtype: Float64

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2c8480
python : 3.9.1.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.2.3
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 52.0.0
Cython : None
pytest : 6.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.1
sqlalchemy : 1.4.3
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None

@jaspersival jaspersival added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 31, 2021
@attack68
Copy link
Contributor

lots of discussion on this: #32265 and #30188

@attack68 attack68 added the Duplicate Report Duplicate issue or pull request label Mar 31, 2021
@mzeitlin11
Copy link
Member

And #39926, will close in favor of discussion there and other issues mentioned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants