Skip to content

Commit 58230c9

Browse files
committed
Fix corner case when self is empty and future.infer_string is True
1 parent da59cdf commit 58230c9

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

pandas/core/frame.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8672,6 +8672,9 @@ def combine(
86728672
"""
86738673
other_idxlen = len(other.index) # save for compare
86748674

8675+
# preserve column order
8676+
new_columns = self.columns.union(other.columns, sort=False)
8677+
86758678
this, other = self.align(other)
86768679
new_index = this.index
86778680

@@ -8681,8 +8684,6 @@ def combine(
86818684
if self.empty and len(other) == other_idxlen:
86828685
return other.copy()
86838686

8684-
# sorts if possible; otherwise align above ensures that these are set-equal
8685-
new_columns = this.columns.union(other.columns)
86868687
do_fill = fill_value is not None
86878688
result = {}
86888689
for col in new_columns:
@@ -8806,10 +8807,7 @@ def combiner(x: Series, y: Series):
88068807
)
88078808
combined = combined.astype(other.dtypes)
88088809
else:
8809-
# preserve column order
8810-
new_columns = self.columns.union(other.columns, sort=False)
88118810
combined = self.combine(other, combiner, overwrite=False)
8812-
combined = combined.reindex(columns=new_columns)
88138811

88148812
dtypes = {
88158813
col: find_common_type([self.dtypes[col], other.dtypes[col]])

0 commit comments

Comments
 (0)