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_ordered fails when left_by is set to more than one column #35269

Closed
2 of 3 tasks
Rufflewind opened this issue Jul 14, 2020 · 1 comment · Fixed by #38089
Closed
2 of 3 tasks

BUG: merge_ordered fails when left_by is set to more than one column #35269

Rufflewind opened this issue Jul 14, 2020 · 1 comment · Fixed by #38089
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 io, pandas
l = pandas.read_csv(io.StringIO('''
G H T 
g h 1   
g h 3  
'''), delim_whitespace=True)
r = pandas.read_csv(io.StringIO('''
T
2
'''), delim_whitespace=True)
pandas.merge_ordered(l, r, on=['T'], left_by=['G', 'H'])

Problem description

This fails:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/pandas/core/reshape/merge.py", line 290, in merge_ordered
    result, _ = _groupby_and_merge(
  File "/usr/lib/python3.8/site-packages/pandas/core/reshape/merge.py", line 162, in _groupby_and_merge
    merged[k] = key
  File "/usr/lib/python3.8/site-packages/pandas/core/frame.py", line 2938, in __setitem__
    self._set_item(key, value)
  File "/usr/lib/python3.8/site-packages/pandas/core/frame.py", line 3000, in _set_item
    value = self._sanitize_column(key, value)
  File "/usr/lib/python3.8/site-packages/pandas/core/frame.py", line 3636, in _sanitize_column
    value = sanitize_index(value, self.index, copy=False)
  File "/usr/lib/python3.8/site-packages/pandas/core/internals/construction.py", line 611, in sanitize_index
    raise ValueError("Length of values does not match length of index")
ValueError: Length of values does not match length of index

Expected Output

Not failing. Should return:

   G  H  T
0  g  h  1
1  g  h  3

For comparison, the above works fine if we use left_by=['G'] and omit the H column entirely.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.8.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.7.7-arch1-1
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_FYL.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.5
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.1
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : 4.9.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.1
matplotlib : 3.2.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.5.0
sqlalchemy : 1.3.18
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 Jul 14, 2020
@TomAugspurger
Copy link
Contributor

@Rufflewind can you simplify the example to remove the CSV stuff? Are you interested in investigating what's going on?

@TomAugspurger TomAugspurger added Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 4, 2020
@jreback jreback added this to the 1.2 milestone Nov 26, 2020
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