@@ -89,116 +89,6 @@ def test_df_add_flex_filled_mixed_dtypes(self):
89
89
tm .assert_frame_equal (result , expected )
90
90
91
91
92
- class TestFrameMulDiv (object ):
93
- """Tests for DataFrame multiplication and division"""
94
- # ------------------------------------------------------------------
95
- # Mod By Zero
96
-
97
- def test_df_mod_zero_df (self ):
98
- # GH#3590, modulo as ints
99
- df = pd .DataFrame ({'first' : [3 , 4 , 5 , 8 ], 'second' : [0 , 0 , 0 , 3 ]})
100
-
101
- # this is technically wrong, as the integer portion is coerced to float
102
- # ###
103
- first = pd .Series ([0 , 0 , 0 , 0 ], dtype = 'float64' )
104
- second = pd .Series ([np .nan , np .nan , np .nan , 0 ])
105
- expected = pd .DataFrame ({'first' : first , 'second' : second })
106
- result = df % df
107
- tm .assert_frame_equal (result , expected )
108
-
109
- def test_df_mod_zero_array (self ):
110
- # GH#3590, modulo as ints
111
- df = pd .DataFrame ({'first' : [3 , 4 , 5 , 8 ], 'second' : [0 , 0 , 0 , 3 ]})
112
-
113
- # this is technically wrong, as the integer portion is coerced to float
114
- # ###
115
- first = pd .Series ([0 , 0 , 0 , 0 ], dtype = 'float64' )
116
- second = pd .Series ([np .nan , np .nan , np .nan , 0 ])
117
- expected = pd .DataFrame ({'first' : first , 'second' : second })
118
-
119
- # numpy has a slightly different (wrong) treatment
120
- with np .errstate (all = 'ignore' ):
121
- arr = df .values % df .values
122
- result2 = pd .DataFrame (arr , index = df .index ,
123
- columns = df .columns , dtype = 'float64' )
124
- result2 .iloc [0 :3 , 1 ] = np .nan
125
- tm .assert_frame_equal (result2 , expected )
126
-
127
- def test_df_mod_zero_int (self ):
128
- # GH#3590, modulo as ints
129
- df = pd .DataFrame ({'first' : [3 , 4 , 5 , 8 ], 'second' : [0 , 0 , 0 , 3 ]})
130
-
131
- result = df % 0
132
- expected = pd .DataFrame (np .nan , index = df .index , columns = df .columns )
133
- tm .assert_frame_equal (result , expected )
134
-
135
- # numpy has a slightly different (wrong) treatment
136
- with np .errstate (all = 'ignore' ):
137
- arr = df .values .astype ('float64' ) % 0
138
- result2 = pd .DataFrame (arr , index = df .index , columns = df .columns )
139
- tm .assert_frame_equal (result2 , expected )
140
-
141
- def test_df_mod_zero_series_does_not_commute (self ):
142
- # GH#3590, modulo as ints
143
- # not commutative with series
144
- df = pd .DataFrame (np .random .randn (10 , 5 ))
145
- ser = df [0 ]
146
- res = ser % df
147
- res2 = df % ser
148
- assert not res .fillna (0 ).equals (res2 .fillna (0 ))
149
-
150
- # ------------------------------------------------------------------
151
- # Division By Zero
152
-
153
- def test_df_div_zero_df (self ):
154
- # integer div, but deal with the 0's (GH#9144)
155
- df = pd .DataFrame ({'first' : [3 , 4 , 5 , 8 ], 'second' : [0 , 0 , 0 , 3 ]})
156
- result = df / df
157
-
158
- first = pd .Series ([1.0 , 1.0 , 1.0 , 1.0 ])
159
- second = pd .Series ([np .nan , np .nan , np .nan , 1 ])
160
- expected = pd .DataFrame ({'first' : first , 'second' : second })
161
- tm .assert_frame_equal (result , expected )
162
-
163
- def test_df_div_zero_array (self ):
164
- # integer div, but deal with the 0's (GH#9144)
165
- df = pd .DataFrame ({'first' : [3 , 4 , 5 , 8 ], 'second' : [0 , 0 , 0 , 3 ]})
166
-
167
- first = pd .Series ([1.0 , 1.0 , 1.0 , 1.0 ])
168
- second = pd .Series ([np .nan , np .nan , np .nan , 1 ])
169
- expected = pd .DataFrame ({'first' : first , 'second' : second })
170
-
171
- with np .errstate (all = 'ignore' ):
172
- arr = df .values .astype ('float' ) / df .values
173
- result = pd .DataFrame (arr , index = df .index ,
174
- columns = df .columns )
175
- tm .assert_frame_equal (result , expected )
176
-
177
- def test_df_div_zero_int (self ):
178
- # integer div, but deal with the 0's (GH#9144)
179
- df = pd .DataFrame ({'first' : [3 , 4 , 5 , 8 ], 'second' : [0 , 0 , 0 , 3 ]})
180
-
181
- result = df / 0
182
- expected = pd .DataFrame (np .inf , index = df .index , columns = df .columns )
183
- expected .iloc [0 :3 , 1 ] = np .nan
184
- tm .assert_frame_equal (result , expected )
185
-
186
- # numpy has a slightly different (wrong) treatment
187
- with np .errstate (all = 'ignore' ):
188
- arr = df .values .astype ('float64' ) / 0
189
- result2 = pd .DataFrame (arr , index = df .index ,
190
- columns = df .columns )
191
- tm .assert_frame_equal (result2 , expected )
192
-
193
- def test_df_div_zero_series_does_not_commute (self ):
194
- # integer div, but deal with the 0's (GH#9144)
195
- df = pd .DataFrame (np .random .randn (10 , 5 ))
196
- ser = df [0 ]
197
- res = ser / df
198
- res2 = df / ser
199
- assert not res .fillna (0 ).equals (res2 .fillna (0 ))
200
-
201
-
202
92
class TestFrameArithmetic (object ):
203
93
204
94
@pytest .mark .xfail (reason = 'GH#7996 datetime64 units not converted to nano' ,
0 commit comments