@@ -833,14 +833,15 @@ def test_append_preserve_index_name(self):
833
833
834
834
@pytest .mark .parametrize ("df_columns" , [
835
835
pd .RangeIndex (3 ),
836
+ pd .Index ([1 , 2 , 3 ]),
837
+ pd .Index (list ('abc' )),
836
838
pd .CategoricalIndex ('A B C' .split ()),
837
839
pd .CategoricalIndex ('A B C' .split (), ordered = True ),
838
840
pd .MultiIndex .from_arrays (['A B C' .split (), 'D E F' .split ()]),
839
841
pd .IntervalIndex .from_breaks ([0 , 1 , 2 , 3 ]),
840
842
pd .DatetimeIndex ([dt .datetime (2013 , 1 , 3 , 0 , 0 ),
841
843
dt .datetime (2013 , 1 , 3 , 6 , 10 ),
842
844
dt .datetime (2013 , 1 , 3 , 7 , 12 )]),
843
- pd .Index ([1 , 2 , 3 ]),
844
845
], ids = lambda x : str (x .dtype ))
845
846
def test_append_same_columns_type (self , df_columns ):
846
847
# GH18359
@@ -870,16 +871,16 @@ def test_append_same_columns_type(self, df_columns):
870
871
pd .RangeIndex (3 ),
871
872
pd .Index ([4 , 5 , 6 ]),
872
873
pd .Index ([7.5 , 8.5 , 9.5 ]),
873
- pd .CategoricalIndex ('A B C' .split ()),
874
- # pd.CategoricalIndex('A B C'.split(), ordered=True),
874
+ pd .Index (list ('abc' )),
875
+ pd .CategoricalIndex ('A B C' .split (), ordered = True ),
876
+ # pd.CategoricalIndex('A B C'.split()),
875
877
pd .DatetimeIndex ([dt .datetime (2013 , 1 , 3 , 0 , 0 ),
876
878
dt .datetime (2013 , 1 , 3 , 6 , 10 ),
877
879
dt .datetime (2013 , 1 , 3 , 7 , 12 )]),
878
880
], r = 2 ), ids = lambda x : str (x .dtype ))
879
881
def test_append_different_columns_types (self , df_columns , series_index ):
880
882
# GH18359
881
- # see also tests 'test_append_multi_index_raises' and
882
- # 'test_append_interval_index_raises' below
883
+ # see also test 'test_append_different_columns_types_raises' below
883
884
884
885
df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]], columns = df_columns )
885
886
ser = pd .Series ([7 , 8 , 9 ], index = series_index , name = 2 )
@@ -894,60 +895,43 @@ def test_append_different_columns_types(self, df_columns, series_index):
894
895
columns = combined_columns )
895
896
assert_frame_equal (result , expected )
896
897
897
- @pytest .mark .parametrize ("other_type" , [
898
- pd .RangeIndex (3 ),
899
- pd .CategoricalIndex ('A B C' .split ()),
900
- pd .CategoricalIndex ('A B C' .split (), ordered = True ),
898
+ @pytest .mark .parametrize ("this_type" , [
901
899
pd .IntervalIndex .from_breaks ([0 , 1 , 2 , 3 ]),
902
- pd .DatetimeIndex ([dt .datetime (2013 , 1 , 3 , 0 , 0 ),
903
- dt .datetime (2013 , 1 , 3 , 6 , 10 ),
904
- dt .datetime (2013 , 1 , 3 , 7 , 12 )]),
905
- pd .Index ([4 , 5 , 6 ]),
906
- ], ids = lambda x : str (x .dtype ))
907
- def test_append_multi_index_raises (self , other_type ):
908
- # GH18359
909
- # .append will raise if MultiIndex appends or is appended to a
910
- # different index type
911
-
912
- mi = pd .MultiIndex .from_arrays (['A B C' .split (), 'D E F' .split ()])
913
-
914
- df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]], columns = mi )
915
- ser = pd .Series ([7 , 8 , 9 ], index = other_type , name = 2 )
916
- if isinstance (other_type , pd .IntervalIndex ):
917
- pytest .raises (ValueError , df .append , ser )
918
- else :
919
- pytest .raises (TypeError , df .append , ser )
920
-
921
- df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]], columns = other_type )
922
- ser = pd .Series ([7 , 8 , 9 ], index = mi , name = 2 )
923
- with pytest .raises (TypeError ):
924
- df .append (ser )
925
-
900
+ pd .MultiIndex .from_arrays (['A B C' .split (), 'D E F' .split ()]),
901
+ ])
926
902
@pytest .mark .parametrize ("other_type" , [
927
903
pd .RangeIndex (3 ),
904
+ pd .Index ([4 , 5 , 6 ]),
905
+ pd .Index (list ("abc" )),
928
906
pd .CategoricalIndex ('A B C' .split ()),
929
907
pd .CategoricalIndex ('A B C' .split (), ordered = True ),
908
+ pd .IntervalIndex .from_breaks ([0 , 1 , 2 , 3 ]),
930
909
pd .MultiIndex .from_arrays (['A B C' .split (), 'D E F' .split ()]),
931
910
pd .DatetimeIndex ([dt .datetime (2013 , 1 , 3 , 0 , 0 ),
932
911
dt .datetime (2013 , 1 , 3 , 6 , 10 ),
933
912
dt .datetime (2013 , 1 , 3 , 7 , 12 )]),
934
- pd .Index ([4 , 5 , 6 ]),
935
913
], ids = lambda x : str (x .dtype ))
936
- def test_append_interval_index_raises (self , other_type ):
914
+ def test_append_different_columns_types_raises (self ,
915
+ this_type , other_type ):
937
916
# GH18359
938
- # .append will raise if IntervalIndex appends or is appended to a
939
- # different index type
917
+ # .append will raise if IntervalIndex/MultiIndex appends or is
918
+ # appended to a different index type
919
+ #
920
+ # see also test 'test_append_different_columns_types' above for
921
+ # appending without raising.
940
922
941
- ii = pd .IntervalIndex .from_breaks ([0 , 1 , 2 , 3 ])
923
+ if type (this_type ) is type (other_type ):
924
+ # don't test same type
925
+ return
942
926
943
- df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]], columns = ii )
927
+ df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]], columns = this_type )
944
928
ser = pd .Series ([7 , 8 , 9 ], index = other_type , name = 2 )
945
929
with pytest .raises (TypeError ):
946
930
df .append (ser )
947
931
948
932
df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]], columns = other_type )
949
- ser = pd .Series ([7 , 8 , 9 ], index = ii , name = 2 )
950
- with pytest .raises (ValueError ):
933
+ ser = pd .Series ([7 , 8 , 9 ], index = this_type , name = 2 )
934
+ with pytest .raises (TypeError ):
951
935
df .append (ser )
952
936
953
937
def test_append_dtype_coerce (self ):
0 commit comments