Skip to content

Commit

Permalink
requested edits
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Jan 29, 2018
1 parent 1ef3a6c commit d648ef6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
27 changes: 10 additions & 17 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,36 +187,29 @@ Previous Behavior:

.. code-block:: ipython

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

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

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

In [9]: index / np.array([0, 0], dtype=np.uint64)
Out[9]: UInt64Index([0, 0], dtype='uint64')
In [9]: index = pd.UInt64Index([0, 1])

In [10]: pd.RangeIndex(1, 5) / 0
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-10-4c5e91d516f3> in <module>()
----> 1 pd.RangeIndex(1, 5) / 0

/usr/local/lib/python2.7/site-packages/pandas/core/indexes/range.pyc in _evaluate_numeric_binop(self, other)
592 if step:
593 with np.errstate(all='ignore'):
--> 594 rstep = step(self._step, other)
595
596 # we don't have a representable op
In [10]: index / np.array([0, 0], dtype=np.uint64)
Out[10]: UInt64Index([0, 0], dtype='uint64')

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

Current Behavior:

.. ipython:: python

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

# The result of division by zero should not depend on whether the zero is int or float
Expand Down
1 change: 1 addition & 0 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ def mask_zero_div_zero(x, y, result, copy=False):
posinf_mask = (zmask & (x > 0)).ravel()

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

np.putmask(result, nan_mask, np.nan)
Expand Down

0 comments on commit d648ef6

Please sign in to comment.