Repository: pandas-dev/pandas

Issue:
RuntimeWarning in DataFrame.div with fill_value=0
Typically we silence these

```python
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
```


Discussion:

Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -108,6 +108,7 @@
     sanitize_index,
     to_arrays,
 )
+from pandas.core.ops.missing import dispatch_fill_zeros
 from pandas.core.series import Series
 
 from pandas.io.formats import console, format as fmt
@@ -5305,7 +5306,9 @@ def _arith_op(left, right):
             # iterate over columns
             return ops.dispatch_to_series(this, other, _arith_op)
         else:
-            result = _arith_op(this.values, other.values)
+            with np.errstate(all="ignore"):
+                result = _arith_op(this.values, other.values)
+            result = dispatch_fill_zeros(func, this.values, other.values, result)
             return self._constructor(
                 result, index=new_index, columns=new_columns, copy=False
             )


Test patch:
diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py
--- a/pandas/tests/arithmetic/test_numeric.py
+++ b/pandas/tests/arithmetic/test_numeric.py
@@ -1227,3 +1227,36 @@ def test_addsub_arithmetic(self, dtype, delta):
         tm.assert_index_equal(index + index, 2 * index)
         tm.assert_index_equal(index - index, 0 * index)
         assert not (index - index).empty
+
+
+def test_fill_value_inf_masking():
+    # GH #27464 make sure we mask 0/1 with Inf and not NaN
+    df = pd.DataFrame({"A": [0, 1, 2], "B": [1.1, None, 1.1]})
+
+    other = pd.DataFrame({"A": [1.1, 1.2, 1.3]}, index=[0, 2, 3])
+
+    result = df.rfloordiv(other, fill_value=1)
+
+    expected = pd.DataFrame(
+        {"A": [np.inf, 1.0, 0.0, 1.0], "B": [0.0, np.nan, 0.0, np.nan]}
+    )
+    tm.assert_frame_equal(result, expected)
+
+
+def test_dataframe_div_silenced():
+    # GH#26793
+    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")
+    )
+    with tm.assert_produces_warning(None):
+        pdf1.div(pdf2, fill_value=0)