1616import pandas ._testing as tm
1717
1818
19- @pytest .fixture
20- def reordered_frame (float_frame ):
21- head , tail = float_frame [:5 ], float_frame [5 :]
22- combined = head .combine_first (tail )
23- reordered_frame = float_frame .reindex (combined .index )
24- return reordered_frame
25-
26-
2719class TestDataFrameCombineFirst :
2820 def test_combine_first_mixed (self ):
2921 a = Series (["a" , "b" ], index = range (2 ))
@@ -46,6 +38,7 @@ def test_combine_first_disjoint(self, float_frame):
4638 tm .assert_frame_equal (combined , reordered_frame )
4739 tm .assert_index_equal (combined .columns , float_frame .columns )
4840 tm .assert_series_equal (combined ["A" ], reordered_frame ["A" ])
41+
4942 tm .assert_series_equal (combined ["A" ].reindex (head .index ), head ["A" ])
5043 tm .assert_series_equal (combined ["A" ].reindex (tail .index ), tail ["A" ])
5144
@@ -65,14 +58,19 @@ def test_combine_first_same_index(self, float_frame):
6558 tm .assert_series_equal (combined ["C" ], fcopy2 ["C" ])
6659 tm .assert_series_equal (combined ["D" ], fcopy ["D" ])
6760
68- def test_combine_first_overlap (self , reordered_frame ):
61+ def test_combine_first_overlap (self , float_frame ):
62+ combined = float_frame [:5 ].combine_first (float_frame [5 :])
63+ reordered_frame = float_frame .reindex (combined .index )
6964 head , tail = reordered_frame [:10 ].copy (), reordered_frame .copy ()
7065 head ["A" ] = 1
7166 combined = head .combine_first (tail )
7267 assert (combined ["A" ][:10 ] == 1 ).all ()
7368
74- def test_combine_first_reverse_overlap (self , reordered_frame ):
75- head , tail = reordered_frame [:10 ].copy (), reordered_frame .copy ()
69+ def test_combine_first_reverse_overlap (self , float_frame ):
70+ combined = float_frame [:5 ].combine_first (float_frame [5 :])
71+ reordered_frame = float_frame .reindex (combined .index )
72+ head , tail = reordered_frame [:10 ].copy (), reordered_frame
73+
7674 tail .iloc [:10 , tail .columns .get_loc ("A" )] = 0
7775 combined = tail .combine_first (head )
7876 assert (combined ["A" ][:10 ] == 0 ).all ()
0 commit comments