Skip to content

RuntimeWarning in DataFrame.div with fill_value=0 #26793

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
TomAugspurger opened this issue Jun 11, 2019 · 0 comments · Fixed by #28024
Closed

RuntimeWarning in DataFrame.div with fill_value=0 #26793

TomAugspurger opened this issue Jun 11, 2019 · 0 comments · Fixed by #28024
Labels
Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@TomAugspurger
Copy link
Contributor

Typically we silence these

import pandas as pd
import numpy as np


a = pd.DataFrame({"A": [0, 2], "B": [0, 4]})
b = pd.DataFrame({"A": [0, 2], "C": [0, 4]}, index=[0, 2])

pdf1 = pd.DataFrame({'A': np.arange(10),
                     'B': [np.nan, 1, 2, 3, 4] * 2,
                     'C': [np.nan] * 10,
                     'D': np.arange(10)},
                    index=list('abcdefghij'), columns=list('ABCD'))
pdf2 = pd.DataFrame(np.random.randn(10, 4),
                    index=list('abcdefghjk'), columns=list('ABCX'))
pdf1.div(pdf2, fill_value=0)

ouput

/Users/taugspurger/sandbox/pandas/pandas/core/frame.py:5138: RuntimeWarning: divide by zero encountered in true_divide
  return func(left, right)
/Users/taugspurger/sandbox/pandas/pandas/core/frame.py:5138: RuntimeWarning: invalid value encountered in true_divide
  return func(left, right)
Out[46]:
           A          B    C    D    X
a  -0.000000   0.000000 -0.0  NaN  0.0
b  -1.381770  -0.870061  0.0  inf -0.0
c  -7.686931  -5.446084  0.0  inf  0.0
d  -5.396100   1.323770 -0.0  inf  0.0
e   4.114989  -4.120187 -0.0  inf  0.0
f -15.748104   0.000000  0.0  inf  0.0
g  -7.147032   0.990337 -0.0  inf  0.0
h  -3.421108  -3.465087  0.0  inf  0.0
i        inf        inf  NaN  inf  NaN
j  27.476268  40.169326 -0.0  inf -0.0
k  -0.000000   0.000000  0.0  NaN -0.0
@TomAugspurger TomAugspurger added the Numeric Operations Arithmetic, Comparison, and Logical operations label Jun 11, 2019
@TomAugspurger TomAugspurger added this to the 0.25.1 milestone Aug 20, 2019
TomAugspurger pushed a commit that referenced this issue Aug 20, 2019
galuhsahid pushed a commit to galuhsahid/pandas that referenced this issue Aug 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant