Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Frozensets are not supported as indices. #41238

Open
2 of 3 tasks
pezize opened this issue Apr 30, 2021 · 0 comments
Open
2 of 3 tasks

BUG: Frozensets are not supported as indices. #41238

pezize opened this issue Apr 30, 2021 · 0 comments
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.).

Comments

@pezize
Copy link

pezize commented Apr 30, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

df = DataFrame.from_dict({'key': [frozenset([1])], 'value': [2]}).set_index('key')

k = frozenset([1])

k in df.index  # True

df.loc[[k]]  # OK
df.loc[k]  # raises: KeyError: "None of [Int64Index([1], dtype='int64', name='key')] are in the [index]"

df.value.loc[[k]]  # OK
df.value.loc[k]  # raises: KeyError: "None of [Int64Index([1], dtype='int64', name='key')] are in the [index]"

Problem description

Frozensets are hashable and could serve as indices. They are only partially supported in the current version:

  • set a frozenset as index: OK,
  • is frozenset in index: OK,
  • index with a collection of frozensets: OK,
  • index with a frozenset: KeyError.

This applies to both Series and DataFrame.

Full support would be nice.

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : 2cb96529396d93b46abab7bbc73a208e708c642e
python           : 3.9.2.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
Version          : 10.0.19041
machine          : AMD64
processor        : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : English_United States.utf8

pandas           : 1.2.4
numpy            : 1.20.1
pytz             : 2021.1
dateutil         : 2.8.1
pip              : 21.0.1
setuptools       : 49.6.0.post20210108
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 2.11.3
IPython          : 7.21.0
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : 0.9.0
fastparquet      : None
gcsfs            : None
matplotlib       : 3.3.4
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : 1.6.2
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : None
@pezize pezize added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 30, 2021
@pezize pezize changed the title BUG: BUG: Frozensets are not supported as DataFrame indices Apr 30, 2021
@pezize pezize changed the title BUG: Frozensets are not supported as DataFrame indices BUG: Frozensets are not supported as indices. Apr 30, 2021
@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 4, 2021
@mroeschke mroeschke added the Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). label Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.).
Projects
None yet
Development

No branches or pull requests

3 participants