Skip to content

Commit 3d14746

Browse files
committed
TST: GH4312, assignment with iloc/loc and an dtype change
1 parent 9ea0d44 commit 3d14746

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

pandas/tests/test_indexing.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -964,11 +964,12 @@ def test_ix_assign_column_mixed(self):
964964
# GH 3668, mixed frame with series value
965965
df = DataFrame({'x':lrange(10), 'y':lrange(10,20),'z' : 'bar'})
966966
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)
972973

973974
df.ix[df.x % 2 == 0, 'y'] = df.ix[df.x % 2 == 0, 'y'] * 100
974975
assert_frame_equal(df,expected)
@@ -1197,6 +1198,22 @@ def gen_expected(df,mask):
11971198
expected = gen_expected(df,mask)
11981199
assert_frame_equal(result,expected)
11991200

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+
12001217
if __name__ == '__main__':
12011218
import nose
12021219
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

0 commit comments

Comments
 (0)