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

BUG: Merge between partial index and index fails if result is empty #33814

Closed
2 of 3 tasks
Rufflewind opened this issue Apr 26, 2020 · 0 comments · Fixed by #34414
Closed
2 of 3 tasks

BUG: Merge between partial index and index fails if result is empty #33814

Rufflewind opened this issue Apr 26, 2020 · 0 comments · Fixed by #34414
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@Rufflewind
Copy link
Contributor

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

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

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas
pandas.merge(
    pandas.DataFrame({'a': [1], 'i': [2]}).set_index(['a', 'i']),
    pandas.DataFrame({'i': [1]}).set_index(['i']),
    left_on=['i'],
    right_index=True,
)

Problem description

This merge fails with the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/pandas/core/reshape/merge.py", line 88, in merge
    return op.get_result()
  File "/usr/lib/python3.8/site-packages/pandas/core/reshape/merge.py", line 668, in get_result
    self._maybe_add_join_keys(result, left_indexer, right_indexer)
  File "/usr/lib/python3.8/site-packages/pandas/core/reshape/merge.py", line 824, in _maybe_add_join_keys
    key_col.name = name
AttributeError: 'numpy.ndarray' object has no attribute 'name'

Thing is, it works fine if I change i in the left DataFrame from [2] to [1]. It only fails if there's no overlap between the join keys.

This behavior is problematic because the failure depends on the outcome of the merge, so it's difficult to avoid.

Expected Output

I expect this to not fail and just return an empty result.

Output of pd.show_versions()

>>> pandas.show_versions()

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.8.2.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.6.2-arch1-2
machine          : x86_64
processor        : 
byteorder        : little
LC_ALL           : None
LANG             : en_FYL.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.0.3
numpy            : 1.18.2
pytz             : 2019.3
dateutil         : 2.8.1
pip              : 20.0.2
setuptools       : 46.1.3
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : 4.5.0
html5lib         : 1.0.1
pymysql          : None
psycopg2         : None
jinja2           : 2.11.1
IPython          : 7.13.0
pandas_datareader: None
bs4              : 4.8.2
bottleneck       : None
fastparquet      : None
gcsfs            : None
lxml.etree       : 4.5.0
matplotlib       : 3.2.1
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pytables         : None
pytest           : None
pyxlsb           : None
s3fs             : None
scipy            : 1.4.1
sqlalchemy       : 1.3.15
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
xlsxwriter       : None
numba            : None
@Rufflewind Rufflewind added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 26, 2020
@TomAugspurger TomAugspurger added Bug and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 4, 2020
@jreback jreback added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Sep 4, 2020
@jreback jreback added this to the 1.2 milestone Sep 4, 2020
@jreback jreback modified the milestones: 1.2, Contributions Welcome Nov 19, 2020
@jreback jreback modified the milestones: Contributions Welcome, 1.3 Jan 3, 2021
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.

3 participants