Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MarcoGorelli opened this issue Feb 13, 2020 · 5 comments
Open

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

MarcoGorelli opened this issue Feb 13, 2020 · 5 comments
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@MarcoGorelli
Copy link
Member

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}

@Dr-Irv Dr-Irv added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Dtype Conversions Unexpected or buggy dtype conversions labels Sep 27, 2020
@mroeschke mroeschke added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff labels Jul 28, 2021
@mroeschke
Copy link
Member

Looks to work on main. Could use a test

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Bug labels Apr 28, 2023
@NoyHanan
Copy link
Contributor

NoyHanan commented May 5, 2023

take

@NoyHanan
Copy link
Contributor

NoyHanan commented May 5, 2023

Hi @mroeschke
Are you sure that it works on main?
I tried it now and it still outputs the same.

@NoyHanan NoyHanan removed their assignment May 10, 2023
@srkds
Copy link
Contributor

srkds commented May 13, 2023

Hi @mroeschke Are you sure that it works on main? I tried it now and it still outputs the same.

Indeed, I also tried reproducing. The bug is still there.
image

@MarcoGorelli MarcoGorelli added Bug and removed good first issue Needs Tests Unit test(s) needed to prevent regressions labels May 15, 2023
@MarcoGorelli
Copy link
Member Author

yup, thanks for checking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

5 participants