Skip to content

Index.name is not validatied to be Hashable #29069

Closed
@TomAugspurger

Description

@TomAugspurger

We require that Series.name be hashable. We don't do the same for Index.name. Should we?

In [4]: pd.Index([], name=[])
Out[4]: Index([], dtype='object', name=[])
In [5]: pd.Series([], name=[])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-2c73ddde103e> in <module>
----> 1 pd.Series([], name=[])

~/sandbox/pandas/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    326         generic.NDFrame.__init__(self, data, fastpath=True)
    327
--> 328         self.name = name
    329         self._set_axis(0, index, fastpath=True)
    330

~/sandbox/pandas/pandas/core/generic.py in __setattr__(self, name, value)
   5257             object.__setattr__(self, name, value)
   5258         elif name in self._metadata:
-> 5259             object.__setattr__(self, name, value)
   5260         else:
   5261             try:

~/sandbox/pandas/pandas/core/series.py in name(self, value)
    468     def name(self, value):
    469         if value is not None and not is_hashable(value):
--> 470             raise TypeError("Series.name must be a hashable type")
    471         object.__setattr__(self, "_name", value)
    472

TypeError: Series.name must be a hashable type

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexRelated to the Index class or subclasses

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions