Skip to content
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

Panel attribute naming conflict if item is named 'a' #3440

Closed
karmel opened this issue Apr 23, 2013 · 3 comments · Fixed by #4459
Closed

Panel attribute naming conflict if item is named 'a' #3440

karmel opened this issue Apr 23, 2013 · 3 comments · Fixed by #4459
Labels
Bug Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code
Milestone

Comments

@karmel
Copy link
Contributor

karmel commented Apr 23, 2013

Including an item named 'a' breaks the expected attribute-retrieval behavior for Panels

import numpy as np
from pandas import DataFrame, Panel

df0 = DataFrame(np.zeros([3,4]))
df1 = DataFrame(np.ones([3,4]))

p = Panel({'a':df0, 'b':df1})

p.b
Out[6]: 
   0  1  2  3
0  1  1  1  1
1  1  1  1  1
2  1  1  1  1


p.a
Out[7]: 'minor_axis'

The expected behavior can be recovered by using anything other than 'a' itself:

p = Panel({'a_':df0, 'b':df1})
p.a_
Out[9]: 
   0  1  2  3
0  0  0  0  0
1  0  0  0  0
2  0  0  0  0

I'm guessing this is related to the fact that many Panel methods use a in iterating through the axes:

passed_axes = [kwargs.get(a) for a in self._AXIS_ORDERS]

Though it's not clear immediately which is the offending use, or if changing all of these is worth it for the recovery of the a namespace...

@jreback
Copy link
Contributor

jreback commented Apr 23, 2013

i is also aliased. I think because am setting up the axes using these as variables in a list comprehension, they get set as class variables (weird I think), this is going to change a bit anyhow (it will be a function instead of done directly in the class and hence won't be a problem)

@ghost
Copy link

ghost commented Apr 24, 2013

I think that's a wart, i know I reach for 'a'/'b'/'c' as col names when I'm throwing up a test frame.

@cpcloud
Copy link
Member

cpcloud commented May 10, 2013

man python's scoping for loops is annoying sometimes. kind of an edge case though i think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants