REF: avoid internals in merge code by jbrockmendel · Pull Request #48082 · pandas-dev/pandas (original) (raw)
I can't reproduce this without geopandas, but the issue boils down to that merge now calls pd.concat (and thus _constructor / __finalize__) before adding suffices for duplicated column names.
So maybe this might be sufficient:
--- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -763,9 +763,12 @@ class _MergeOperation: right.index = join_index
from pandas import concatleft.columns = llabelsright.columns = rlabel result = concat([left, right], axis=1, copy=copy)
result.columns = llabels.append(rlabels) return result
One reproducer with geopandas is:
import geopandas
df1 = geopandas.GeoDataFrame({"key": [1, 2, 3]}, geometry=geopandas.points_from_xy([1, 2, 3], [1, 2, 3]))
df2 = geopandas.GeoDataFrame({"key": [2, 3, 4]}, geometry=geopandas.points_from_xy([1, 2, 3], [1, 2, 3]))
df1.merge(df2, on="key")