Skip to content

merge coerces to left dtype even with how='right' #31951

Open
@MarcoGorelli

Description

@MarcoGorelli

Code Sample, a copy-pastable example if possible

>>> import pandas as pd
>>> df1 = pd.DataFrame({'a': [1]})                                                                                                                                                                           
>>> df2 = pd.DataFrame({'a': [1.0]})                                                                                                                                                                         
>>> df1.merge(df2, on='a')                                                                                                                                                                                   
>>> df1.merge(df2, on='a', how='left')                                                                                                                                                                       
   a
0  1
>>> df1.merge(df2, on='a', how='right')                                                                                                                                                                      
   a
0  1

Problem description

I don't know if this is an issue, it's just something I noticed while working on #31278 . The right value 1.0 gets coerced to the dtype of the left dataframe when using how='left', and I would have expected the left value 1 to get coerced to the dtype of the right dataframe when using how='right'

Expected Output

>>> df1.merge(df2, on='a', how='right')    
     a
0  1.0

Output of pd.show_versions()

I'm on the master branch, here's what `pd.show_versions()` shows: /home/SERILOCAL/m.gorelli/miniconda3/envs/pandas-dev/lib/python3.7/site-packages/fastparquet/dataframe.py:5: FutureWarning: pandas.core.index is deprecated and will be removed in a future version. The public classes are available in the top-level namespace. from pandas.core.index import CategoricalIndex, RangeIndex, Index, MultiIndex

INSTALLED VERSIONS

{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}

{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions