Skip to content

BUG: join: ValueError: Indexes have overlapping values #46396

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

Closed
2 of 3 tasks
anmyachev opened this issue Mar 16, 2022 · 4 comments · Fixed by #46630
Closed
2 of 3 tasks

BUG: join: ValueError: Indexes have overlapping values #46396

anmyachev opened this issue Mar 16, 2022 · 4 comments · Fixed by #46630
Assignees
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@anmyachev
Copy link
Contributor

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

test = pandas.DataFrame({"col1": [1,2]})
test.join(test, lsuffix="b")  # OK
test.join([test], lsuffix="b")  # failed
# *** ValueError: Indexes have overlapping values: Index(['col1'], dtype='object')

Issue Description

Unexpected behavior.

Expected Behavior

The result of calling join function in the cases above should lead to the same result.

Installed Versions

INSTALLED VERSIONS

commit : 06d2301
python : 3.8.12.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United States.1252

pandas : 1.4.1
numpy : 1.22.2
pytz : 2021.3
dateutil : 2.8.2
pip : 22.0.3
setuptools : 59.8.0
Cython : None
pytest : 7.0.0
hypothesis : None
sphinx : 4.4.0
blosc : None
feather : 0.4.1
xlsxwriter : None
lxml.etree : 4.7.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.0.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : 2022.01.0
gcsfs : None
matplotlib : 3.2.2
numba : None
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.9
pandas_gbq : 0.17.0
pyarrow : 6.0.1
pyreadstat : None
pyxlsb : None
s3fs : 2022.01.0
scipy : 1.8.0
sqlalchemy : 1.4.31
tables : 3.7.0
tabulate : None
xarray : 0.21.1
xlrd : 2.0.1
xlwt : None
zstandard : None

@anmyachev anmyachev added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 16, 2022
@sappersapper
Copy link

sappersapper commented Mar 22, 2022

It seems the merge() in 'else:' branch does not take into account the 'suffixes' parameters.

pandas/pandas/core/frame.py

Lines 9466 to 9468 in 6033ed4

joined = merge(
joined, frame, how=how, left_index=True, right_index=True
)

Just add a conversion of the input 'other' at the beginning of _join_compat() ?

if isinstance(other, list) and len(other) == 1:
    other = other[0]

or add 'suffixes' parameters to merge() in 'else:' branch ?

How to deal with test.join([test, test], lsuffix="b") ?

@bwozniak27
Copy link
Contributor

take

@bwozniak27
Copy link
Contributor

Should this operation be allowed? In the comment for Join():

Notes
-----
Parameters on, lsuffix, and rsuffix are not supported when
passing a list of DataFrame objects.

Since the suffixes are added for the sake of differentiating the columns when merged, how would that work with an DataFrame array of size > 1? In this case, there would still be columns of the same name. I see two reasonable solutions.

  1. We allow them to do this, and for each when adding the suffix, attach a counter onto it (ex. "1" or "_1")
test.join([test, test], lsuffix="b")
   col1b_1  col1b_2  col1b_3  col1
0       1       3            5    7
1       2       4            6    8
  1. We make a more explicit error when a user attempts to use either of the suffix parameters. Currently there is not check for them, only a check for the on parameter.

I am a student in college and am new to open source contributing, so I was wondering if I could get some assistance. Thanks so much.
@anmyachev @sappersapper

@anmyachev
Copy link
Contributor Author

Hello @bwozniak27! I'm glad you are interested in this issue.

I like the second option. For example, I didn’t read these lines in the documentation :)
As for the first option, I'm not sure, but in the case of a list of one element, it would be possible to make the behavior similar to the case when a simple dataframe is passed (as @sappersapper suggested).

@jreback jreback added this to the 1.5 milestone Apr 7, 2022
@jreback jreback added Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants