-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Description
Currently, we use the type of the left object to construct the result of pd.merge:
pandas/pandas/core/reshape/merge.py
Lines 731 to 732 in 445bb9f
| typ = self.left._constructor | |
| result = typ(result_data).__finalize__(self, method=self._merge_type) |
For GeoPandas users, this means that the order of the arguments passed matters: pd.merge(df, gdf, ..) (or df.merge(gdf, ..)) returns a DataFrame while pd.merge(gdf, df, ...) (or gdf.merge(df, ..)) returns a GeoDataFrame. This can be surprising for users.
I think it should be rather easy / safe to also check the type of the right object and use that class (if left is a non-subclassed pandas.DataFrame, otherwise left still has "precedence")
API breaking implications
This can result in a different class type as return value. But for subclasses that are mostly compatible with pandas.DataFrame (and only add functionality), this should not have a big impact.