-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DataFrame.merge() doesn't check if new suffixed column names clash with existing column names #22818
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
Comments
confirmation that I can replicate this issue on master. |
What should we do here? I think raising an error is not a good option here, because the suffixes are generated on the fly and should work independent from existing column names. Should we add an additional suffix to the new column or should we use another letter (like |
The suffixes are the defaults for the suffixes parameter for pd.merge, pandas/pandas/core/reshape/merge.py Lines 59 to 73 in 08a0cb0
raising on duplicates probably makes more sense and alerts the user to pass appropriate suffixes for the problem in hand, instead of relying on the defaults. maybe, to avoid breaking changes, we could add an additional |
Uh oh!
There was an error while loading. Please reload this page.
Code Sample
Problem description
Merging 4 DataFrames with same column names; using default suffix settings and no drops / renames in between merges (e.g. doing all 3 merges on one line).
The third merge creates duplicate column names because suffixes are appended which have already been used.
Expected Output
When adding suffixes, the method should check whether the new column names ('column_0_x', 'column_1_y', etc.) already exist in the DataFrame. This could either raise an error / warning, or add another suffix in format 'column_0_x_x'.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Darwin
OS-release: 17.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8
pandas: 0.23.4
pytest: 3.8.0
pip: 10.0.1
setuptools: 40.2.0
Cython: 0.28.5
numpy: 1.15.1
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: 1.7.9
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 2.2.3
openpyxl: 2.5.6
xlrd: 1.1.0
xlwt: 1.2.0
xlsxwriter: 1.1.0
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.11
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: