Skip to content

Commit cd54349

Browse files
committed
move dispatch_missing to core.missing
1 parent 06df02a commit cd54349

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

pandas/core/indexes/base.py

+1-32
Original file line numberDiff line numberDiff line change
@@ -4045,7 +4045,7 @@ def _evaluate_numeric_binop(self, other):
40454045
with np.errstate(all='ignore'):
40464046
result = op(values, other)
40474047

4048-
result = dispatch_missing(op, values, other, result)
4048+
result = missing.dispatch_missing(op, values, other, result)
40494049
return constructor(result, **attrs)
40504050

40514051
return _evaluate_numeric_binop
@@ -4169,37 +4169,6 @@ def invalid_op(self, other=None):
41694169
Index._add_comparison_methods()
41704170

41714171

4172-
def dispatch_missing(op, left, right, result):
4173-
"""
4174-
Fill nulls caused by division by zero, casting to a diffferent dtype
4175-
if necessary.
4176-
4177-
Parameters
4178-
----------
4179-
op : function (operator.add, operator.div, ...)
4180-
left : object, usually Index
4181-
right : object
4182-
result : ndarray
4183-
4184-
Returns
4185-
-------
4186-
result : ndarray
4187-
"""
4188-
opstr = '__{opname}__'.format(opname=op.__name__).replace('____', '__')
4189-
if op in [operator.truediv, operator.floordiv,
4190-
getattr(operator, 'div', None)]:
4191-
result = missing.mask_zero_div_zero(left, right, result)
4192-
elif op is operator.mod:
4193-
result = missing.fill_zeros(result, left, right,
4194-
opstr, np.nan)
4195-
elif op is divmod:
4196-
res0 = missing.mask_zero_div_zero(left, right, result[0])
4197-
res1 = missing.fill_zeros(result[1], left, right,
4198-
opstr, np.nan)
4199-
result = (res0, res1)
4200-
return result
4201-
4202-
42034172
def _ensure_index_from_sequences(sequences, names=None):
42044173
"""Construct an index from sequences of data.
42054174

pandas/core/missing.py

+30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Routines for filling missing data
33
"""
4+
import operator
45

56
import numpy as np
67
from distutils.version import LooseVersion
@@ -683,6 +684,35 @@ def mask_zero_div_zero(x, y, result):
683684
return result
684685

685686

687+
def dispatch_missing(op, left, right, result):
688+
"""
689+
Fill nulls caused by division by zero, casting to a diffferent dtype
690+
if necessary.
691+
692+
Parameters
693+
----------
694+
op : function (operator.add, operator.div, ...)
695+
left : object (Index for non-reversed ops)
696+
right : object (Index fof reversed ops)
697+
result : ndarray
698+
699+
Returns
700+
-------
701+
result : ndarray
702+
"""
703+
opstr = '__{opname}__'.format(opname=op.__name__).replace('____', '__')
704+
if op in [operator.truediv, operator.floordiv,
705+
getattr(operator, 'div', None)]:
706+
result = mask_zero_div_zero(left, right, result)
707+
elif op is operator.mod:
708+
result = fill_zeros(result, left, right, opstr, np.nan)
709+
elif op is divmod:
710+
res0 = mask_zero_div_zero(left, right, result[0])
711+
res1 = fill_zeros(result[1], left, right, opstr, np.nan)
712+
result = (res0, res1)
713+
return result
714+
715+
686716
def _interp_limit(invalid, fw_limit, bw_limit):
687717
"""Get idx of values that won't be filled b/c they exceed the limits.
688718

0 commit comments

Comments
 (0)