From dcfc50be5a8f61c4357de5d2ccb86bc1a69bc727 Mon Sep 17 00:00:00 2001 From: y-p Date: Thu, 22 Nov 2012 22:24:37 +0200 Subject: [PATCH 1/2] TST: combining frame with empty frame still unions index --- pandas/tests/test_frame.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index fea84f5a86e36..7f6ee00785501 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -6131,6 +6131,9 @@ def test_combine_first(self): comb = self.empty.combine_first(self.frame) assert_frame_equal(comb, self.frame) + comb = self.frame.combine_first(DataFrame(index=["faz","boo"])) + self.assertTrue("faz" in comb.index) + def test_combine_first_mixed_bug(self): idx = Index(['a','b','c','e']) ser1 = Series([5.0,-9.0,4.0,100.],index=idx) From 7a79b1c919d9354d4d053df7538d59dcbb5a3cad Mon Sep 17 00:00:00 2001 From: y-p Date: Thu, 22 Nov 2012 22:19:42 +0200 Subject: [PATCH 2/2] BUG: combining frame with empty frame still unions index. #2307 --- pandas/core/frame.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f7f296e822e15..c0e0c2a464a1d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3503,15 +3503,18 @@ def combine(self, other, func, fill_value=None): ------- result : DataFrame """ - if other.empty: - return self.copy() - if self.empty: - return other.copy() + other_idxlen = len(other.index) # save for compare this, other = self.align(other, copy=False) new_index = this.index + if other.empty and len(new_index) == len(self.index): + return self.copy() + + if self.empty and len(other) == other_idxlen: + return other.copy() + # sorts if possible new_columns = this.columns.union(other.columns) do_fill = fill_value is not None