@@ -39,15 +39,7 @@ def sort_with_none(request):
39
39
return request .param
40
40
41
41
42
- class ConcatenateBase :
43
-
44
- def setup_method (self , method ):
45
- self .frame = DataFrame (tm .getSeriesData ())
46
- self .mixed_frame = self .frame .copy ()
47
- self .mixed_frame ['foo' ] = 'bar'
48
-
49
-
50
- class TestConcatAppendCommon (ConcatenateBase ):
42
+ class TestConcatAppendCommon :
51
43
52
44
"""
53
45
Test common dtype coercion rules between concat and append.
@@ -731,17 +723,20 @@ def test_concat_categorical_empty(self):
731
723
tm .assert_series_equal (s2 .append (s1 , ignore_index = True ), exp )
732
724
733
725
734
- class TestAppend (ConcatenateBase ):
726
+ class TestAppend :
727
+
728
+ def test_append (self , sort , float_frame ):
729
+ mixed_frame = float_frame .copy ()
730
+ mixed_frame ['foo' ] = 'bar'
735
731
736
- def test_append (self , sort ):
737
- begin_index = self .frame .index [:5 ]
738
- end_index = self .frame .index [5 :]
732
+ begin_index = float_frame .index [:5 ]
733
+ end_index = float_frame .index [5 :]
739
734
740
- begin_frame = self . frame .reindex (begin_index )
741
- end_frame = self . frame .reindex (end_index )
735
+ begin_frame = float_frame .reindex (begin_index )
736
+ end_frame = float_frame .reindex (end_index )
742
737
743
738
appended = begin_frame .append (end_frame )
744
- tm .assert_almost_equal (appended ['A' ], self . frame ['A' ])
739
+ tm .assert_almost_equal (appended ['A' ], float_frame ['A' ])
745
740
746
741
del end_frame ['A' ]
747
742
partial_appended = begin_frame .append (end_frame , sort = sort )
@@ -751,35 +746,35 @@ def test_append(self, sort):
751
746
assert 'A' in partial_appended
752
747
753
748
# mixed type handling
754
- appended = self . mixed_frame [:5 ].append (self . mixed_frame [5 :])
755
- tm .assert_frame_equal (appended , self . mixed_frame )
749
+ appended = mixed_frame [:5 ].append (mixed_frame [5 :])
750
+ tm .assert_frame_equal (appended , mixed_frame )
756
751
757
752
# what to test here
758
- mixed_appended = self .mixed_frame [:5 ].append (self .frame [5 :], sort = sort )
759
- mixed_appended2 = self .frame [:5 ].append (self .mixed_frame [5 :],
760
- sort = sort )
753
+ mixed_appended = mixed_frame [:5 ].append (float_frame [5 :], sort = sort )
754
+ mixed_appended2 = float_frame [:5 ].append (mixed_frame [5 :], sort = sort )
761
755
762
756
# all equal except 'foo' column
763
757
tm .assert_frame_equal (
764
758
mixed_appended .reindex (columns = ['A' , 'B' , 'C' , 'D' ]),
765
759
mixed_appended2 .reindex (columns = ['A' , 'B' , 'C' , 'D' ]))
766
760
767
- # append empty
761
+ def test_append_empty ( self , float_frame ):
768
762
empty = DataFrame ()
769
763
770
- appended = self . frame .append (empty )
771
- tm .assert_frame_equal (self . frame , appended )
772
- assert appended is not self . frame
764
+ appended = float_frame .append (empty )
765
+ tm .assert_frame_equal (float_frame , appended )
766
+ assert appended is not float_frame
773
767
774
- appended = empty .append (self . frame )
775
- tm .assert_frame_equal (self . frame , appended )
776
- assert appended is not self . frame
768
+ appended = empty .append (float_frame )
769
+ tm .assert_frame_equal (float_frame , appended )
770
+ assert appended is not float_frame
777
771
778
- # Overlap
772
+ def test_append_overlap_raises ( self , float_frame ):
779
773
msg = "Indexes have overlapping values"
780
774
with pytest .raises (ValueError , match = msg ):
781
- self . frame . append (self . frame , verify_integrity = True )
775
+ float_frame . append (float_frame , verify_integrity = True )
782
776
777
+ def test_append_new_columns (self ):
783
778
# see gh-6129: new columns
784
779
df = DataFrame ({'a' : {'x' : 1 , 'y' : 2 }, 'b' : {'x' : 3 , 'y' : 4 }})
785
780
row = Series ([5 , 6 , 7 ], index = ['a' , 'b' , 'c' ], name = 'z' )
@@ -851,17 +846,17 @@ def test_append_different_columns(self, sort):
851
846
assert isna (appended ['strings' ][0 :4 ]).all ()
852
847
assert isna (appended ['bools' ][5 :]).all ()
853
848
854
- def test_append_many (self , sort ):
855
- chunks = [self . frame [:5 ], self . frame [5 :10 ],
856
- self . frame [10 :15 ], self . frame [15 :]]
849
+ def test_append_many (self , sort , float_frame ):
850
+ chunks = [float_frame [:5 ], float_frame [5 :10 ],
851
+ float_frame [10 :15 ], float_frame [15 :]]
857
852
858
853
result = chunks [0 ].append (chunks [1 :])
859
- tm .assert_frame_equal (result , self . frame )
854
+ tm .assert_frame_equal (result , float_frame )
860
855
861
856
chunks [- 1 ] = chunks [- 1 ].copy ()
862
857
chunks [- 1 ]['foo' ] = 'bar'
863
858
result = chunks [0 ].append (chunks [1 :], sort = sort )
864
- tm .assert_frame_equal (result .loc [:, self . frame . columns ], self . frame )
859
+ tm .assert_frame_equal (result .loc [:, float_frame . columns ], float_frame )
865
860
assert (result ['foo' ][15 :] == 'bar' ).all ()
866
861
assert result ['foo' ][:15 ].isna ().all ()
867
862
@@ -1042,7 +1037,7 @@ def test_append_empty_frame_to_series_with_dateutil_tz(self):
1042
1037
assert_frame_equal (result , expected )
1043
1038
1044
1039
1045
- class TestConcatenate ( ConcatenateBase ) :
1040
+ class TestConcatenate :
1046
1041
1047
1042
def test_concat_copy (self ):
1048
1043
df = DataFrame (np .random .randn (4 , 3 ))
0 commit comments