Skip to content

AttributeError with divmod(Series, Series) with 0 in the denominator #26987

Closed
@TomAugspurger

Description

@TomAugspurger

Strange one. This works,

In [39]: a = pd.Series([1, 1])

In [40]: divmod(a, pd.Series([1, 2]));

This raises

In [41]: divmod(a, pd.Series([0, 2]));
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-41-04277abe6f5a> in <module>
----> 1 divmod(a, pd.Series([0, 2]));

~/sandbox/pandas/pandas/core/ops.py in wrapper(left, right)
   1714             rvalues = rvalues.values
   1715
-> 1716         result = safe_na_op(lvalues, rvalues)
   1717         return construct_result(left, result,
   1718                                 index=left.index, name=res_name, dtype=None)

~/sandbox/pandas/pandas/core/ops.py in safe_na_op(lvalues, rvalues)
   1660         try:
   1661             with np.errstate(all='ignore'):
-> 1662                 return na_op(lvalues, rvalues)
   1663         except Exception:
   1664             if is_object_dtype(lvalues):

~/sandbox/pandas/pandas/core/ops.py in na_op(x, y)
   1640             result = masked_arith_op(x, y, op)
   1641
-> 1642         result = missing.fill_zeros(result, x, y, op_name, fill_zeros)
   1643         return result
   1644

~/sandbox/pandas/pandas/core/missing.py in fill_zeros(result, x, y, name, fill)
    544             mask = ((y == 0) & ~np.isnan(result)).ravel()
    545
--> 546             shape = result.shape
    547             result = result.astype('float64', copy=False).ravel()
    548

AttributeError: 'tuple' object has no attribute 'shape'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Numeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions