Skip to content

Conversation

@jreback
Copy link
Contributor

@jreback jreback commented May 14, 2013

closes #3590

This is a numpy oddity that treats them differently.

In [131]: p = DataFrame({ 'first' : [3,4,5,8], 'second' : [0,0,0,3] })

In [132]: p % 0
Out[132]: 
   first  second
0    NaN     NaN
1    NaN     NaN
2    NaN     NaN
3    NaN     NaN

In [133]: p % p
Out[133]: 
   first  second
0      0     NaN
1      0     NaN
2      0     NaN
3      0       0

In [134]: p / p
Out[134]: 
   first    second
0      1       inf
1      1       inf
2      1       inf
3      1  1.000000

In [135]: p / 0
Out[135]: 
   first  second
0    inf     inf
1    inf     inf
2    inf     inf
3    inf     inf

Numpy does this (on integers), floats are as like above

In [3]: x
Out[3]: 
array([[3, 0],
       [4, 0],
       [5, 0],
       [8, 3]])

In [4]: x % 0
Out[4]: 
array([[0, 0],
       [0, 0],
       [0, 0],
       [0, 0]])

In [5]: x % x
Out[5]: 
array([[0, 0],
       [0, 0],
       [0, 0],
       [0, 0]])

In [6]: x / x
Out[6]: 
array([[1, 0],
       [1, 0],
       [1, 0],
       [1, 1]])

In [7]: x / 0
Out[7]: 
array([[0, 0],
       [0, 0],
       [0, 0],
       [0, 0]])

@cpcloud
Copy link
Member

cpcloud commented May 14, 2013

@jreback Darn u beat me 2 it :) This is nice, thanks.

…nteger dtypes as float dtypes (GH3590_).

      This is a numpy oddity that treats them differently.

ENH:  Add modulo operator to Series,DataFrame

TST: py3 compat for division
jreback added a commit that referenced this pull request May 14, 2013
BUG:  Fix integer modulo and division to make integer and float dtypes work similarly for invalid values
@jreback jreback merged commit a14cbd0 into pandas-dev:master May 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pandas mod 0 should not give 0

2 participants