From eddd146d90328d96c7d345007e430a3c8c290d3c Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 8 Dec 2025 03:54:13 +0000 Subject: [PATCH 1/2] Fix unmeged commits --- .../tests/frame/methods/test_combine_first.py | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/pandas/tests/frame/methods/test_combine_first.py b/pandas/tests/frame/methods/test_combine_first.py index d4006eb4f942f..a3750bd776ae0 100644 --- a/pandas/tests/frame/methods/test_combine_first.py +++ b/pandas/tests/frame/methods/test_combine_first.py @@ -16,6 +16,14 @@ import pandas._testing as tm +@pytest.fixture +def reordered_frame(float_frame): + head, tail = float_frame[:5], float_frame[5:] + combined = head.combine_first(tail) + reordered_frame = float_frame.reindex(combined.index) + return reordered_frame + + class TestDataFrameCombineFirst: def test_combine_first_mixed(self): a = Series(["a", "b"], index=range(2)) @@ -30,17 +38,18 @@ def test_combine_first_mixed(self): combined = f.combine_first(g) tm.assert_frame_equal(combined, exp) - def test_combine_first(self, float_frame): - # disjoint + def test_combine_first_disjoint(self, float_frame): head, tail = float_frame[:5], float_frame[5:] - combined = head.combine_first(tail) reordered_frame = float_frame.reindex(combined.index) + tm.assert_frame_equal(combined, reordered_frame) tm.assert_index_equal(combined.columns, float_frame.columns) tm.assert_series_equal(combined["A"], reordered_frame["A"]) + tm.assert_series_equal(combined["A"].reindex(head.index), head["A"]) + tm.assert_series_equal(combined["A"].reindex(tail.index), tail["A"]) - # same index + def test_combine_first_same_index(self, float_frame): fcopy = float_frame.copy() fcopy["A"] = 1 del fcopy["C"] @@ -56,36 +65,31 @@ def test_combine_first(self, float_frame): tm.assert_series_equal(combined["C"], fcopy2["C"]) tm.assert_series_equal(combined["D"], fcopy["D"]) - # overlap - head, tail = reordered_frame[:10].copy(), reordered_frame + def test_combine_first_overlap(self, reordered_frame): + head, tail = reordered_frame[:10].copy(), reordered_frame.copy() head["A"] = 1 - combined = head.combine_first(tail) assert (combined["A"][:10] == 1).all() - # reverse overlap + def test_combine_first_reverse_overlap(self, reordered_frame): + head, tail = reordered_frame[:10].copy(), reordered_frame.copy() tail.iloc[:10, tail.columns.get_loc("A")] = 0 combined = tail.combine_first(head) assert (combined["A"][:10] == 0).all() - # no overlap - f = float_frame[:10] - g = float_frame[10:] - combined = f.combine_first(g) - tm.assert_series_equal(combined["A"].reindex(f.index), f["A"]) - tm.assert_series_equal(combined["A"].reindex(g.index), g["A"]) - - # corner cases + def test_combine_first_with_empty(self, float_frame): comb = float_frame.combine_first(DataFrame()) tm.assert_frame_equal(comb, float_frame) comb = DataFrame().combine_first(float_frame) tm.assert_frame_equal(comb, float_frame.sort_index()) + def test_combine_first_with_new_index(self, float_frame): comb = float_frame.combine_first(DataFrame(index=["faz", "boo"])) assert "faz" in comb.index - # #2525 + def test_combine_first_column_union(self): + # GH#2525 df = DataFrame({"a": [1]}, index=[datetime(2012, 1, 1)]) df2 = DataFrame(columns=["b"]) result = df.combine_first(df2) From 66d00be220fe949b9ed74c8a9380f42125aa77c6 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 10 Dec 2025 05:25:35 +0000 Subject: [PATCH 2/2] remove test fixture --- .../tests/frame/methods/test_combine_first.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pandas/tests/frame/methods/test_combine_first.py b/pandas/tests/frame/methods/test_combine_first.py index a3750bd776ae0..da4a240ed8691 100644 --- a/pandas/tests/frame/methods/test_combine_first.py +++ b/pandas/tests/frame/methods/test_combine_first.py @@ -16,14 +16,6 @@ import pandas._testing as tm -@pytest.fixture -def reordered_frame(float_frame): - head, tail = float_frame[:5], float_frame[5:] - combined = head.combine_first(tail) - reordered_frame = float_frame.reindex(combined.index) - return reordered_frame - - class TestDataFrameCombineFirst: def test_combine_first_mixed(self): a = Series(["a", "b"], index=range(2)) @@ -46,6 +38,7 @@ def test_combine_first_disjoint(self, float_frame): tm.assert_frame_equal(combined, reordered_frame) tm.assert_index_equal(combined.columns, float_frame.columns) tm.assert_series_equal(combined["A"], reordered_frame["A"]) + tm.assert_series_equal(combined["A"].reindex(head.index), head["A"]) tm.assert_series_equal(combined["A"].reindex(tail.index), tail["A"]) @@ -65,14 +58,19 @@ def test_combine_first_same_index(self, float_frame): tm.assert_series_equal(combined["C"], fcopy2["C"]) tm.assert_series_equal(combined["D"], fcopy["D"]) - def test_combine_first_overlap(self, reordered_frame): + def test_combine_first_overlap(self, float_frame): + combined = float_frame[:5].combine_first(float_frame[5:]) + reordered_frame = float_frame.reindex(combined.index) head, tail = reordered_frame[:10].copy(), reordered_frame.copy() head["A"] = 1 combined = head.combine_first(tail) assert (combined["A"][:10] == 1).all() - def test_combine_first_reverse_overlap(self, reordered_frame): - head, tail = reordered_frame[:10].copy(), reordered_frame.copy() + def test_combine_first_reverse_overlap(self, float_frame): + combined = float_frame[:5].combine_first(float_frame[5:]) + reordered_frame = float_frame.reindex(combined.index) + head, tail = reordered_frame[:10].copy(), reordered_frame + tail.iloc[:10, tail.columns.get_loc("A")] = 0 combined = tail.combine_first(head) assert (combined["A"][:10] == 0).all()