Skip to content

Commit 9edd478

Browse files
y-pwesm
y-p
authored andcommitted
BUG: combining frame with empty frame still unions index. #2307
1 parent 633602e commit 9edd478

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pandas/core/frame.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -3512,15 +3512,18 @@ def combine(self, other, func, fill_value=None):
35123512
-------
35133513
result : DataFrame
35143514
"""
3515-
if other.empty:
3516-
return self.copy()
35173515

3518-
if self.empty:
3519-
return other.copy()
3516+
other_idxlen = len(other.index) # save for compare
35203517

35213518
this, other = self.align(other, copy=False)
35223519
new_index = this.index
35233520

3521+
if other.empty and len(new_index) == len(self.index):
3522+
return self.copy()
3523+
3524+
if self.empty and len(other) == other_idxlen:
3525+
return other.copy()
3526+
35243527
# sorts if possible
35253528
new_columns = this.columns.union(other.columns)
35263529
do_fill = fill_value is not None

0 commit comments

Comments
 (0)