Skip to content

Object indexes on the items/info axis of Panel #9142

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
dalejung opened this issue Dec 24, 2014 · 1 comment
Closed

Object indexes on the items/info axis of Panel #9142

dalejung opened this issue Dec 24, 2014 · 1 comment

Comments

@dalejung
Copy link
Contributor

I have objects in the items axis of a Panel, selecting by an object gets me an infinite recursion.

import pandas as pd
import numpy as np

class Key:
    def __init__(self, name, id):
        self.name = name
        self.id = id

    def __repr__(self):
        return "Key(name={name}, id={id})".format(**self.__dict__)

names = ['dale', 'bob', 'frank']        
N = len(names)
items = [Key(name, id) for name, id in zip(names, range(1, N+1))]        

panel = pd.Panel(np.random.randn(N, 10, 10), items=items)
panel.ix[items[0]] # infinite recursion
super(pd.Panel, panel).__getitem__(items[0]) # works

It appears the issue is that the Key object isn't be counted as scalar in the Panel.__getitem__

 253     def __getitem__(self, key):
 254         if isinstance(self._info_axis, MultiIndex):
 255             return self._getitem_multilevel(key)
 256         if lib.isscalar(key):
 257             return super(Panel, self).__getitem__(key)
 258         return self.ix[key]
@dalejung
Copy link
Contributor Author

wow, how'd I miss the issue right before this. #9140

closing since this is a dupe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant