@@ -964,11 +964,12 @@ def test_ix_assign_column_mixed(self):
964
964
# GH 3668, mixed frame with series value
965
965
df = DataFrame ({'x' :lrange (10 ), 'y' :lrange (10 ,20 ),'z' : 'bar' })
966
966
expected = df .copy ()
967
- expected .ix [0 , 'y' ] = 1000
968
- expected .ix [2 , 'y' ] = 1200
969
- expected .ix [4 , 'y' ] = 1400
970
- expected .ix [6 , 'y' ] = 1600
971
- expected .ix [8 , 'y' ] = 1800
967
+
968
+ for i in range (5 ):
969
+ indexer = i * 2
970
+ v = 1000 + i * 200
971
+ expected .ix [indexer , 'y' ] = v
972
+ self .assert_ (expected .ix [indexer , 'y' ] == v )
972
973
973
974
df .ix [df .x % 2 == 0 , 'y' ] = df .ix [df .x % 2 == 0 , 'y' ] * 100
974
975
assert_frame_equal (df ,expected )
@@ -1197,6 +1198,22 @@ def gen_expected(df,mask):
1197
1198
expected = gen_expected (df ,mask )
1198
1199
assert_frame_equal (result ,expected )
1199
1200
1201
+ def test_astype_assignment_with_iloc (self ):
1202
+
1203
+ # GH4312
1204
+ df_orig = DataFrame ([['1' ,'2' ,'3' ,'.4' ,5 ,6. ,'foo' ]],columns = list ('ABCDEFG' ))
1205
+
1206
+ df = df_orig .copy ()
1207
+ df .iloc [:,0 :3 ] = df .iloc [:,0 :3 ].astype (int )
1208
+ result = df .get_dtype_counts ().sort_index ()
1209
+ expected = Series ({ 'int64' : 4 , 'float64' : 1 , 'object' : 2 }).sort_index ()
1210
+ assert_series_equal (result ,expected )
1211
+
1212
+ df = df_orig .copy ()
1213
+ df .iloc [:,0 :3 ] = df .iloc [:,0 :3 ].convert_objects (convert_numeric = True )
1214
+ result = df .get_dtype_counts ().sort_index ()
1215
+ expected = Series ({ 'int64' : 4 , 'float64' : 1 , 'object' : 2 }).sort_index ()
1216
+
1200
1217
if __name__ == '__main__' :
1201
1218
import nose
1202
1219
nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
0 commit comments