Skip to content

Enable use of index level in joins by name #922

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
wesm opened this issue Mar 15, 2012 · 4 comments
Closed

Enable use of index level in joins by name #922

wesm opened this issue Mar 15, 2012 · 4 comments
Labels
Enhancement Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@wesm
Copy link
Member

wesm commented Mar 15, 2012

In [35]: A
Out[35]:
       Aattr3 Aattr1       Aattr2
Aidx1
37       Delta   East         hard
59     Epsilon   East         hard
96        Zeta   East         hard
21       Gamma   West  medium hard
2        Alpha   West         soft
10        Beta   West         soft

In [36]: B
Out[36]:
              Bname  Battr
Bidx1 Bidx2
37    20579     Alan  45.20
59    20693    Betty   4.40
     20706  Charlie   9.95
37    20742   Dougal  16.60
96    20861     Emma   7.40
37    21167   Freddy  20.60
59    20947   Gareth  21.00
96    20536    Helen   9.65
37    21002     Ivan  43.80
21    21491    Jenny   6.90
     20655    Keith  42.40
2     21083  Leonard  23.60
     21391    Mandy  30.40
     21381   Nicola  11.60
10    21416   Oswald  30.30
2     21392    Peter  44.40
     21386  Quentin   5.40

In [15]: A.index.intersection(B.index)
Out[15]: Index([], dtype=object)

In [9]: pandas.merge(A, B, left_index=True, right_on=['Bidx1'])
...
KeyError: 'no item named Bidx1'

In [10]: pandas.merge(A, B, left_index=True, right_on=['Bidx1',
'Bidx2'])
...
/usr/local/lib/python2.7/dist-packages/pandas-0.7.2.dev_be66c27-py2.7-
linux-x86_64.egg/pandas/tools/merge.pyc in
_validate_specification(self)
   278             n = len(self.right_on)
   279             if self.left_index:
--> 280                 assert(len(self.right_on) ==
self.left.index.nlevels)
   281                 self.left_on = [None] * n
   282         assert(len(self.right_on) == len(self.left_on))

AssertionError:

In [18]: pandas.merge(A, B)
...
/usr/local/lib/python2.7/dist-packages/pandas-0.7.2.dev_be66c27-py2.7-
linux-x86_64.egg/pandas/core/groupby.pyc in
get_group_index(label_list, shape)
  1494         return label_list[0]
  1495
-> 1496     n = len(label_list[0])
  1497     group_index = np.zeros(n, dtype=np.int64)
  1498     mask = np.zeros(n, dtype=bool)

IndexError: list index out of range
@wesm
Copy link
Member Author

wesm commented Jul 13, 2012

I guess you need to return to this guy at some point? Looks like it was never merged

@wesm
Copy link
Member Author

wesm commented Jul 13, 2012

(not urgent)

@ghost ghost assigned changhiskhan Jul 13, 2012
@changhiskhan
Copy link
Contributor

Yeah, it actually has a few bugs in it as it stands. I will take care of it post 0.8.1

@jreback
Copy link
Contributor

jreback commented Feb 18, 2014

kind of closed by #6363

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

No branches or pull requests

3 participants