Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down