Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
TomAugspurger opened this issue Jun 21, 2019 · 4 comments

Comments

@TomAugspurger
Copy link
Contributor

commented Jun 21, 2019

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'
@TomAugspurger

This comment has been minimized.

Copy link
Contributor Author

commented Jun 21, 2019

This sends us down the bad path:

if (y == 0).any():

Haven't looked into it. Don't plan to look further right now.

@jbrockmendel

This comment has been minimized.

Copy link
Member

commented Jun 29, 2019

I've got a patch for the immediate issue by just checking for divmod in fill_zeros and operating element-wise, but it surfaces another question about what we expect this to operation to return.

a = pd.Series([1, 1])
b = pd.Series([0, 2])

result = divmod(a, b)
expected = a // b, a % b

result[0] matches expected[0], but result[1] and expected[1] are:

>>> res1[1]
0    inf
1    1.0
dtype: float64
>>> expected[1]
0    NaN
1    1.0
dtype: float64
@jreback

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2019

see what numpy does for float args

jbrockmendel added a commit to jbrockmendel/pandas that referenced this issue Jun 29, 2019

@jbrockmendel jbrockmendel referenced this issue Jun 29, 2019

Closed

BUG: Fix Series divmod #26987 #27130

4 of 4 tasks complete
@jbrockmendel

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

Looks like #23293 made it so this doesn't raise, but does use incorrect fill value. Will fix in a variant of #27130.

jbrockmendel added a commit to jbrockmendel/pandas that referenced this issue Jul 5, 2019

@jbrockmendel jbrockmendel referenced this issue Jul 5, 2019

Merged

BUG: Fix divmod fill value, closes #26987 #27239

4 of 4 tasks complete

@jreback jreback added this to the 0.25.0 milestone Jul 5, 2019

jreback added a commit that referenced this issue Jul 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.