Skip to content

BUG: binary operator methods (eg mul) don't handle integer level #9463

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
jorisvandenbossche opened this issue Feb 11, 2015 · 2 comments · Fixed by #9475
Closed

BUG: binary operator methods (eg mul) don't handle integer level #9463

jorisvandenbossche opened this issue Feb 11, 2015 · 2 comments · Fixed by #9475
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@jorisvandenbossche
Copy link
Member

Suppose I have the following dataframe and series:

In [20]: df = pd.DataFrame(np.ones((3,4)), columns=pd.MultiIndex.from_product([['A', 'B'],['a', 'b']]))

In [21]: s = pd.Series({'a':1, 'b':2})

In [22]: df
Out[22]: 
   A     B   
   a  b  a  b
0  1  1  1  1
1  1  1  1  1
2  1  1  1  1

In [23]: s
Out[23]: 
a    1
b    2
dtype: int64

Trying to multiply this by the columns, and matching on the second level, gives the following error:

In [24]: df.mul(s, axis=1, level=1)
...
  File "C:\Anaconda\lib\site-packages\pandas\core\index.py", line 1786, in _join_multi
    raise ValueError("cannot join with no level specified and no overlapping names")

ValueError: cannot join with no level specified and no overlapping names

In any case, this is a wrong error message, as I did specify a level.
Further, this does work and gives the expected output with a named level instead of a integer level:

In [25]: df2 = df.copy()
    ...: df2.columns.names = ['l0', 'l1']

In [35]: df2.mul(s, axis=1, level='l1') # <-- works

Out[35]: 
l0  A     B   
l1  a  b  a  b
0   1  2  1  2
1   1  2  1  2
2   1  2  1  2

Am I correct that this should also work with integer levels?

@jreback jreback added API Design Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Indexing Related to indexing on series/frames, not to indexes themselves labels Feb 11, 2015
@jreback
Copy link
Contributor

jreback commented Feb 11, 2015

this just looks like a bug, prob _get_level_number is not called (which will properly transform the numbers/levels names)

@jreback jreback added this to the 0.17.0 milestone Feb 11, 2015
@jorisvandenbossche
Copy link
Member Author

I think there is a level=level missing here: https://github.com/pydata/pandas/blob/master/pandas/core/generic.py#L3198. Will try to see if that breaks something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants