Skip to content

BUG: Bug in binary operations with a rhs of a Series not aligning (GH6681) #6682

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

Merged
merged 1 commit into from
Mar 21, 2014

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Mar 21, 2014

closes #6681

In [11]:         index=MultiIndex.from_product([list('abc'),
                                       ['one','two','three'],
                                       [1,2,3]],
                                      names=['first','second','third'])

In [12]:         df = DataFrame(np.arange(27*3).reshape(27,3),
                       index=index,
                       columns=['value1','value2','value3']).sortlevel()

In [13]: df
Out[13]: 
                    value1  value2  value3
first second third                        
a     one    1           0       1       2
             2           3       4       5
             3           6       7       8
      three  1          18      19      20
             2          21      22      23
             3          24      25      26
      two    1           9      10      11
             2          12      13      14
             3          15      16      17
b     one    1          27      28      29
             2          30      31      32
             3          33      34      35
      three  1          45      46      47
             2          48      49      50
             3          51      52      53
      two    1          36      37      38
             2          39      40      41
             3          42      43      44
c     one    1          54      55      56
             2          57      58      59
             3          60      61      62
      three  1          72      73      74
             2          75      76      77
             3          78      79      80
      two    1          63      64      65
             2          66      67      68
             3          69      70      71

[27 rows x 3 columns]

In [15]: x = Series([ 1.0, 10.0], ['two','three'])

In [16]: x
Out[16]: 
two       1
three    10
dtype: float64

Passing a level now aligns by that level

In [14]: df.mul(x,level='second',axis=0)
Out[14]: 
                    value1  value2  value3
first second third                        
a     one    1         NaN     NaN     NaN
             2         NaN     NaN     NaN
             3         NaN     NaN     NaN
      three  1         180     190     200
             2         210     220     230
             3         240     250     260
      two    1           9      10      11
             2          12      13      14
             3          15      16      17
b     one    1         NaN     NaN     NaN
             2         NaN     NaN     NaN
             3         NaN     NaN     NaN
      three  1         450     460     470
             2         480     490     500
             3         510     520     530
      two    1          36      37      38
             2          39      40      41
             3          42      43      44
c     one    1         NaN     NaN     NaN
             2         NaN     NaN     NaN
             3         NaN     NaN     NaN
      three  1         720     730     740
             2         750     760     770
             3         780     790     800
      two    1          63      64      65
             2          66      67      68
             3          69      70      71

[27 rows x 3 columns]

@jreback jreback added this to the 0.14.0 milestone Mar 21, 2014
jreback added a commit that referenced this pull request Mar 21, 2014
BUG: Bug in binary operations with a rhs of a Series not aligning (GH6681)
@jreback jreback merged commit 66cf19a into pandas-dev:master Mar 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug MultiIndex Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: align on level for binary ops
1 participant