@@ -2316,7 +2316,7 @@ def test_convert_objects_no_conversion(self):
2316
2316
mixed2 = mixed1 .convert_objects ()
2317
2317
assert_frame_equal (mixed1 , mixed2 )
2318
2318
2319
- def test_append_series (self ):
2319
+ def test_append_series_dict (self ):
2320
2320
df = DataFrame (np .random .randn (5 , 4 ),
2321
2321
columns = ['foo' , 'bar' , 'baz' , 'qux' ])
2322
2322
@@ -2329,12 +2329,38 @@ def test_append_series(self):
2329
2329
ignore_index = True )
2330
2330
assert_frame_equal (result , expected )
2331
2331
2332
+ # dict
2333
+ result = df .append (series .to_dict (), ignore_index = True )
2334
+ assert_frame_equal (result , expected )
2335
+
2332
2336
result = df .append (series [::- 1 ][:3 ], ignore_index = True )
2333
2337
expected = df .append (DataFrame ({0 : series [::- 1 ][:3 ]}).T ,
2334
2338
ignore_index = True )
2335
2339
assert_frame_equal (result , expected .ix [:, result .columns ])
2336
2340
2337
2341
# can append when name set
2342
+ row = df .ix [4 ]
2343
+ row .name = 5
2344
+ result = df .append (row )
2345
+ expected = df .append (df [- 1 :], ignore_index = True )
2346
+ assert_frame_equal (result , expected )
2347
+
2348
+ def test_append_list_of_series_dicts (self ):
2349
+ df = DataFrame (np .random .randn (5 , 4 ),
2350
+ columns = ['foo' , 'bar' , 'baz' , 'qux' ])
2351
+
2352
+ dicts = [x .to_dict () for idx , x in df .iterrows ()]
2353
+
2354
+ result = df .append (dicts , ignore_index = True )
2355
+ expected = df .append (df , ignore_index = True )
2356
+ assert_frame_equal (result , expected )
2357
+
2358
+ # different columns
2359
+ dicts = [{'foo' : 1 , 'bar' : 2 , 'baz' : 3 , 'peekaboo' : 4 },
2360
+ {'foo' : 5 , 'bar' : 6 , 'baz' : 7 , 'peekaboo' : 8 }]
2361
+ result = df .append (dicts , ignore_index = True )
2362
+ expected = df .append (DataFrame (dicts ), ignore_index = True )
2363
+ assert_frame_equal (result , expected )
2338
2364
2339
2365
def test_asfreq (self ):
2340
2366
offset_monthly = self .tsframe .asfreq (datetools .bmonthEnd )
0 commit comments