Skip to content

Panel partial index is transposed when minor_index is MultiIndex #11369

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
benmoran opened this issue Oct 19, 2015 · 3 comments
Closed

Panel partial index is transposed when minor_index is MultiIndex #11369

benmoran opened this issue Oct 19, 2015 · 3 comments
Labels
Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex Needs Discussion Requires discussion from core team before further action

Comments

@benmoran
Copy link

I can index a Panel to get a data frame, e.g. by major_axis:

>>> p = pd.Panel(np.arange(8).reshape(2,2,2),items=('A1','B1'),major_axis=('A2','B2'),minor_axis=('A3','B3'))
>>> p.loc[:,'A2',:]

    A1  B1
A3   0   4
B3   1   5

But if I do the same index when the minor_axis is a MultiIndex the resulting data frame is unexpectedly transposed:

mi = pd.MultiIndex((['A3','B3'],['a','b']), [(0,0),(1,1)])
p = pd.Panel(np.arange(8).reshape(2,2,2),items=('A1','B1'),major_axis=('A2','B2'),minor_axis=mi)
p.loc[:,'A2',:]

   A3   
    b  b
A1  0  1
B1  4  5

Actually I think the second behaviour is closer to what I expect - the items axis becomes dimension 0 of the DataFrame. But whichever is used, we should have stability, especially if 1-item MultiIndex objects automatically become Index objects.

@jreback
Copy link
Contributor

jreback commented Oct 19, 2015

so these hit 2 slightly different paths, and the one 2nd one has a 'fix' for this issue: #7516 and in the code here

I remember making this change and it seems reasonable.

If you'd like to read the other issue and see what is most logical would be helpful.

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex Needs Discussion Requires discussion from core team before further action labels Oct 19, 2015
@benmoran
Copy link
Author

@jreback sorry, I'm not sure what I'm looking at in the other issue you referenced?

This is the behaviour that seems "most logical" to me:

  • most important is that whatever type my indices happen to be doesn't affect the transposition order of the output
  • secondly, I'd expect that removing a dimension doesn't change the order of the other dimensions

I think the latter is what Numpy does, so "np.random.randn(3,4,5)[:,1,:].shape" gives (3,5) and not (5,3).

@jreback
Copy link
Contributor

jreback commented Jul 10, 2017

closing as Panels are deprecated

@jreback jreback closed this as completed Jul 10, 2017
@jreback jreback modified the milestone: won't fix Jul 11, 2017
@TomAugspurger TomAugspurger modified the milestones: won't fix, No action Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

4 participants