I'm getting an error if using a subclass of pd.Index which contains non-primitive values. I'm using pandas 0.13.1.
A quick demonstration:
import pandas as pd
class MyIndex(pd.Index): pass
# MyIndex = pd.Index <-- if not subclassing, no problem
o1 = object(); o2 = object() # <-- if using primitives, no problem
j = MyIndex([ o1, o2 ])
i = pd.Index(j)
j2 = MyIndex([ o2 ])
i2 = pd.Index(j2)
try:
print pd.Series([ 4,5 ], index = j)[j2] # <-- RuntimeError: maximum recursion depth exceeded while calling a Python object
except RuntimeError, e:
print e
print pd.Series([ 4,5 ], index = j)[i2] # <-- works as expected
print pd.Series([ 4,5 ], index = i)[j2] # <-- works as expected
Questions:
- Is this a bug or am I doing something wrong?
- What is the best way to fix/bypass this error, while still (a) using a subclass of
pd.Index(my subclass includes an extended interface), and (b) contains non-primitive values (objects of a user-defined class).