ENH: also check type of right DataFrame to determine (sub)class of result DataFrame #44054
Labels
Enhancement
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Subclassing
Subclassing pandas objects
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
For GeoPandas users, this means that the order of the arguments passed matters:
pd.merge(df, gdf, ..)
(ordf.merge(gdf, ..)
) returns a DataFrame whilepd.merge(gdf, df, ...)
(orgdf.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, otherwiseleft
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.
The text was updated successfully, but these errors were encountered: