Skip to content

Commit d648ef6

Browse files
committed
requested edits
1 parent 1ef3a6c commit d648ef6

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

doc/source/whatsnew/v0.23.0.txt

+10-17
Original file line numberDiff line numberDiff line change
@@ -187,36 +187,29 @@ Previous Behavior:
187187

188188
.. code-block:: ipython
189189

190-
In [6]: index = pd.Index([-1, 0, 1])
190+
In [6]: index = pd.Int64Index([-1, 0, 1])
191191

192192
In [7]: index / 0
193193
Out[7]: Int64Index([0, 0, 0], dtype='int64')
194194

195-
In [8]: index = pd.UInt64Index([0, 1])
195+
# Previous behavior yielded different results depending on the type of zero in the divisor
196+
In [8]: index / 0.0
197+
Out[8]: Float64Index([-inf, nan, inf], dtype='float64')
196198

197-
In [9]: index / np.array([0, 0], dtype=np.uint64)
198-
Out[9]: UInt64Index([0, 0], dtype='uint64')
199+
In [9]: index = pd.UInt64Index([0, 1])
199200

200-
In [10]: pd.RangeIndex(1, 5) / 0
201-
---------------------------------------------------------------------------
202-
ZeroDivisionError Traceback (most recent call last)
203-
<ipython-input-10-4c5e91d516f3> in <module>()
204-
----> 1 pd.RangeIndex(1, 5) / 0
205-
206-
/usr/local/lib/python2.7/site-packages/pandas/core/indexes/range.pyc in _evaluate_numeric_binop(self, other)
207-
592 if step:
208-
593 with np.errstate(all='ignore'):
209-
--> 594 rstep = step(self._step, other)
210-
595
211-
596 # we don't have a representable op
201+
In [10]: index / np.array([0, 0], dtype=np.uint64)
202+
Out[10]: UInt64Index([0, 0], dtype='uint64')
212203

204+
In [11]: pd.RangeIndex(1, 5) / 0
213205
ZeroDivisionError: integer division or modulo by zero
214206

215207
Current Behavior:
216208

217209
.. ipython:: python
218210

219-
index = pd.Index([-1, 0, 1])
211+
index = pd.Int64Index([-1, 0, 1])
212+
# division by zero gives -infinity where negative, +infinity where positive, and NaN for 0 / 0
220213
index / 0
221214

222215
# The result of division by zero should not depend on whether the zero is int or float

pandas/core/missing.py

+1
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ def mask_zero_div_zero(x, y, result, copy=False):
686686
posinf_mask = (zmask & (x > 0)).ravel()
687687

688688
if nan_mask.any() or neginf_mask.any() or posinf_mask.any():
689+
# Fill negative/0 with -inf, positive/0 with +inf, 0/0 with NaN
689690
result = result.astype('float64', copy=copy).ravel()
690691

691692
np.putmask(result, nan_mask, np.nan)

0 commit comments

Comments
 (0)