Closed
Description
import pandas as PD
s1=PD.Series((1,4,9,16), name=dict(a=1,b=2))
s2=s1*2
s2.name=dict(c=5,d=7)
s1
0 1
1 4
2 9
3 16
Name: {'a': 1, 'b': 2}, dtype: int32
df = PD.concat((s1,s2), axis=1) # this should raise ValueError as the resulting df is broken
df.shape # ok, this works...
(4, 2)
df # But this doesn't.
<repr(<pandas.core.frame.DataFrame at 0x35af770>) failed: TypeError: unhashable type: 'dict'>
df.columns # This is not a proper index...
Index([{'a': 1, 'b': 2}, {'c': 5, 'd': 7}], dtype='object')
Comments:
- There may be other ways aside from concat that lead to broken df's if a Series.name attribute is unhashable.
- If Series.name is a dict, one could try to convert it into a namedtuple. That's hashable.