Skip to content

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

Closed
@karmel

Description

@karmel

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugInternalsRelated to non-user accessible pandas implementationRefactorInternal refactoring of code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions