Skip to content

Commit

Permalink
move dispatch_missing to core.missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Jan 24, 2018
1 parent 06df02a commit cd54349
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
33 changes: 1 addition & 32 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4045,7 +4045,7 @@ def _evaluate_numeric_binop(self, other):
with np.errstate(all='ignore'):
result = op(values, other)

result = dispatch_missing(op, values, other, result)
result = missing.dispatch_missing(op, values, other, result)
return constructor(result, **attrs)

return _evaluate_numeric_binop
Expand Down Expand Up @@ -4169,37 +4169,6 @@ def invalid_op(self, other=None):
Index._add_comparison_methods()


def dispatch_missing(op, left, right, result):
"""
Fill nulls caused by division by zero, casting to a diffferent dtype
if necessary.
Parameters
----------
op : function (operator.add, operator.div, ...)
left : object, usually Index
right : object
result : ndarray
Returns
-------
result : ndarray
"""
opstr = '__{opname}__'.format(opname=op.__name__).replace('____', '__')
if op in [operator.truediv, operator.floordiv,
getattr(operator, 'div', None)]:
result = missing.mask_zero_div_zero(left, right, result)
elif op is operator.mod:
result = missing.fill_zeros(result, left, right,
opstr, np.nan)
elif op is divmod:
res0 = missing.mask_zero_div_zero(left, right, result[0])
res1 = missing.fill_zeros(result[1], left, right,
opstr, np.nan)
result = (res0, res1)
return result


def _ensure_index_from_sequences(sequences, names=None):
"""Construct an index from sequences of data.
Expand Down
30 changes: 30 additions & 0 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Routines for filling missing data
"""
import operator

import numpy as np
from distutils.version import LooseVersion
Expand Down Expand Up @@ -683,6 +684,35 @@ def mask_zero_div_zero(x, y, result):
return result


def dispatch_missing(op, left, right, result):
"""
Fill nulls caused by division by zero, casting to a diffferent dtype
if necessary.
Parameters
----------
op : function (operator.add, operator.div, ...)
left : object (Index for non-reversed ops)
right : object (Index fof reversed ops)
result : ndarray
Returns
-------
result : ndarray
"""
opstr = '__{opname}__'.format(opname=op.__name__).replace('____', '__')
if op in [operator.truediv, operator.floordiv,
getattr(operator, 'div', None)]:
result = mask_zero_div_zero(left, right, result)
elif op is operator.mod:
result = fill_zeros(result, left, right, opstr, np.nan)
elif op is divmod:
res0 = mask_zero_div_zero(left, right, result[0])
res1 = fill_zeros(result[1], left, right, opstr, np.nan)
result = (res0, res1)
return result


def _interp_limit(invalid, fw_limit, bw_limit):
"""Get idx of values that won't be filled b/c they exceed the limits.
Expand Down

0 comments on commit cd54349

Please sign in to comment.