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: map nested dict on categorical Series prints a TypeError and ignores it #40892

Open
2 of 3 tasks
adrien-berchet opened this issue Apr 12, 2021 · 2 comments
Open
2 of 3 tasks
Labels
Bug Categorical Categorical Data Type hashing hash_pandas_object Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.).

Comments

@adrien-berchet
Copy link

  • 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.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

tested = pd.Series(["key_1", "key_2"], dtype="category")
tested.map({"key_1": {"a": 1}, "key_2": {"a": 2}})

Problem description

The given code raises an exception but actually ignores it and returns the expected result. I think it would be better to ignore it silently. Note that it seems to happen only with categorical Series.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.map_locations()

TypeError: unhashable type: 'dict'
Exception ignored in: 'pandas._libs.index.IndexEngine._call_map_locations'
Traceback (most recent call last):
  File "pandas/_libs/hashtable_class_helper.pxi", line 4588, in pandas._libs.hashtable.PyObjectHashTable.map_locations
TypeError: unhashable type: 'dict'
Out[10]: 
0    {'a': 1}
1    {'a': 2}
dtype: object

Expected Output

Out[10]: 
0    {'a': 1}
1    {'a': 2}
dtype: object

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2c8480
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-70-generic
Version : #78-Ubuntu SMP Fri Mar 19 13:29:52 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : fr_FR.UTF-8
LOCALE : fr_FR.UTF-8

pandas : 1.2.3
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 20.2.2
setuptools : 49.6.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.22.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.7
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.23
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@adrien-berchet adrien-berchet added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 12, 2021
@attack68
Copy link
Contributor

the same also occurs on master.

@attack68 attack68 added Categorical Categorical Data Type hashing hash_pandas_object and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 12, 2021
@phofl
Copy link
Member

phofl commented Apr 12, 2021

If I execute this in the debugger the code exits

Traceback (most recent call last):
  File "pandas/_libs/hashtable_class_helper.pxi", line 5185, in pandas._libs.hashtable.PyObjectHashTable.map_locations
TypeError: unhashable type: 'dict'

Process finished with exit code 1

@mroeschke mroeschke added the Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). label Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type hashing hash_pandas_object Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.).
Projects
None yet
Development

No branches or pull requests

4 participants