I have a 2 DataFrame objects that I am trying to merge on a hierarchical index in one (top below) object with two columns in another (bottom below):

frames

However, merging these via the following:

ecmo_by_year = pd.merge(pd.DataFrame(ecmo_count, columns=['ECMO']), runs_sex, 
                    left_index=True, right_on=('YearEcls', 'Sex'))

Yields an incorrect ValueError:

ValueError: len(right_on) must equal the number of levels in the index of "left"

There are two levels in the hierarchical index, and two columns specified to join on the other, so this appears not to be a problem.

Running Pandas 0.16.1 on Python 3.4 (Homebrew) on OS X 10.10.

This code ran just fine on previous versions of Pandas (0.15), so it looks like a bug was introduced.

Comment From: jreback

can you make a copy-pastable example pls.

Comment From: fonnesbeck

The problem here was that the DataFrame in the merge call was empty. Sorry, closing.

Comment From: jorisvandenbossche

BTW, the reason the DataFrame is empty is because of the columns=['ECMO']. By using that, it will select only the columns with that name in the provided data (a reindexing operation), instead of renaming the series you provided (what you wanted to do I think)