@@ -2860,6 +2860,12 @@ def check(result, expected=None):
2860
2860
expected = DataFrame ([[1 ,1 ,1 ,5 ,'bah' ,3 ],[1 ,1 ,2 ,5 ,'bah' ,3 ],[2 ,1 ,3 ,5 ,'bah' ,3 ]],columns = ['foo' ,'bar' ,'foo' ,'hello' ,'string' ,'foo2' ])
2861
2861
check (df ,expected )
2862
2862
2863
+ # set (non-dup)
2864
+ df ['foo2' ] = 4
2865
+ expected = DataFrame ([[1 ,1 ,1 ,5 ,'bah' ,4 ],[1 ,1 ,2 ,5 ,'bah' ,4 ],[2 ,1 ,3 ,5 ,'bah' ,4 ]],columns = ['foo' ,'bar' ,'foo' ,'hello' ,'string' ,'foo2' ])
2866
+ check (df ,expected )
2867
+ df ['foo2' ] = 3
2868
+
2863
2869
# delete (non dup)
2864
2870
del df ['bar' ]
2865
2871
expected = DataFrame ([[1 ,1 ,5 ,'bah' ,3 ],[1 ,2 ,5 ,'bah' ,3 ],[2 ,3 ,5 ,'bah' ,3 ]],columns = ['foo' ,'foo' ,'hello' ,'string' ,'foo2' ])
@@ -2912,6 +2918,33 @@ def check(result, expected=None):
2912
2918
expected = DataFrame ([[1 ,5 ,7. ],[1 ,5 ,7. ],[1 ,5 ,7. ]],columns = ['bar' ,'hello' ,'foo2' ])
2913
2919
check (df ,expected )
2914
2920
2921
+ # reindex
2922
+ df = DataFrame ([[1 ,5 ,7. ],[1 ,5 ,7. ],[1 ,5 ,7. ]],columns = ['bar' ,'a' ,'a' ])
2923
+ expected = DataFrame ([[1 ],[1 ],[1 ]],columns = ['bar' ])
2924
+ result = df .reindex (columns = ['bar' ])
2925
+ check (result ,expected )
2926
+
2927
+ result1 = DataFrame ([[1 ],[1 ],[1 ]],columns = ['bar' ]).reindex (columns = ['bar' ,'foo' ])
2928
+ result2 = df .reindex (columns = ['bar' ,'foo' ])
2929
+ check (result2 ,result1 )
2930
+
2931
+ # drop
2932
+ df = DataFrame ([[1 ,5 ,7. ],[1 ,5 ,7. ],[1 ,5 ,7. ]],columns = ['bar' ,'a' ,'a' ])
2933
+ df = df .drop (['a' ],axis = 1 )
2934
+ expected = DataFrame ([[1 ],[1 ],[1 ]],columns = ['bar' ])
2935
+ check (df ,expected )
2936
+
2937
+ def test_insert_benchmark (self ):
2938
+ # from the vb_suite/frame_methods/frame_insert_columns
2939
+ N = 10
2940
+ K = 5
2941
+ df = DataFrame (index = range (N ))
2942
+ new_col = np .random .randn (N )
2943
+ for i in range (K ):
2944
+ df [i ] = new_col
2945
+ expected = DataFrame (np .repeat (new_col ,K ).reshape (N ,K ),index = range (N ))
2946
+ assert_frame_equal (df ,expected )
2947
+
2915
2948
def test_constructor_single_value (self ):
2916
2949
2917
2950
# expecting single value upcasting here
0 commit comments