|
20 | 20 | )
|
21 | 21 | from pandas import compat
|
22 | 22 |
|
23 |
| -from numpy import random, nan |
| 23 | +from numpy import random, nan, inf |
24 | 24 | from numpy.random import randn
|
25 | 25 | import numpy as np
|
26 | 26 | import numpy.ma as ma
|
@@ -5138,23 +5138,26 @@ def test_modulo(self):
|
5138 | 5138 |
|
5139 | 5139 | def test_div(self):
|
5140 | 5140 |
|
5141 |
| - # integer div, but deal with the 0's |
| 5141 | + # integer div, but deal with the 0's (GH 9144) |
5142 | 5142 | p = DataFrame({ 'first' : [3,4,5,8], 'second' : [0,0,0,3] })
|
5143 | 5143 | result = p / p
|
5144 | 5144 |
|
5145 |
| - ### this is technically wrong as the integer portion is coerced to float ### |
5146 |
| - expected = DataFrame({ 'first' : Series([1,1,1,1],dtype='float64'), 'second' : Series([np.inf,np.inf,np.inf,1]) }) |
| 5145 | + expected = DataFrame({'first': Series([1.0, 1.0, 1.0, 1.0]), |
| 5146 | + 'second': Series([nan, nan, nan, 1])}) |
5147 | 5147 | assert_frame_equal(result,expected)
|
5148 | 5148 |
|
5149 |
| - result2 = DataFrame(p.values.astype('float64')/p.values,index=p.index,columns=p.columns).fillna(np.inf) |
| 5149 | + result2 = DataFrame(p.values.astype('float') / p.values, index=p.index, |
| 5150 | + columns=p.columns) |
5150 | 5151 | assert_frame_equal(result2,expected)
|
5151 | 5152 |
|
5152 | 5153 | result = p / 0
|
5153 |
| - expected = DataFrame(np.inf,index=p.index,columns=p.columns) |
| 5154 | + expected = DataFrame(inf, index=p.index, columns=p.columns) |
| 5155 | + expected.iloc[0:3, 1] = nan |
5154 | 5156 | assert_frame_equal(result,expected)
|
5155 | 5157 |
|
5156 | 5158 | # numpy has a slightly different (wrong) treatement
|
5157 |
| - result2 = DataFrame(p.values.astype('float64')/0,index=p.index,columns=p.columns).fillna(np.inf) |
| 5159 | + result2 = DataFrame(p.values.astype('float64') / 0, index=p.index, |
| 5160 | + columns=p.columns) |
5158 | 5161 | assert_frame_equal(result2,expected)
|
5159 | 5162 |
|
5160 | 5163 | p = DataFrame(np.random.randn(10, 5))
|
@@ -5604,7 +5607,7 @@ def test_arith_flex_series(self):
|
5604 | 5607 |
|
5605 | 5608 | # broadcasting issue in GH7325
|
5606 | 5609 | df = DataFrame(np.arange(3*2).reshape((3,2)),dtype='int64')
|
5607 |
| - expected = DataFrame([[np.inf,np.inf],[1.0,1.5],[1.0,1.25]]) |
| 5610 | + expected = DataFrame([[nan, inf], [1.0, 1.5], [1.0, 1.25]]) |
5608 | 5611 | result = df.div(df[0],axis='index')
|
5609 | 5612 | assert_frame_equal(result,expected)
|
5610 | 5613 |
|
|
0 commit comments