Pandas version checks
-
[x] I have checked that this issue has not already been reported.
-
[x] I have confirmed this bug exists on the latest version of pandas.
-
[x] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
>>> import pandas as pd
>>> ind=pd.Index([["str", "rts"]])
>>> ind
Index([['str', 'rts']], dtype='object')
Issue Description
It seems that Index
accepts a list of list of strings, but that's not hashable, and docs say that we only accept hashable values in an Index.
Expected Behavior
This should be rejected during construction.
Installed Versions
Comment From: UzmaYounas794
In the Index constructor ( new in pandas/core/indexes/base.py), we can validate each element by checking if it’s hashable using hash(item). This is where the Index is first constructed from user input.
Comment From: mroeschke
Index
has always been special at accepting non-Python-hashable values since I think the khash indexing engine is able to hash more Python objects than just hash
. Although it's an antipattern to store nested objects like this in an Index
not sure if we should ban it
Comment From: Dr-Irv
Except at https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.html#pandas.Index we say "An Index instance can only contain hashable objects."
Comment From: jbrockmendel
xref #20285