question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: 'Series' objects are mutable, thus they cannot be hashed

See original GitHub issue
  • 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

# Your code here
df = pd.DataFrame({"id":[0, 1, 2], "name":["a", None, None]})
df.query("name.isnull()")

# output:
TypeError: 'Series' objects are mutable, thus they cannot be hashed

Problem description

i’m so sad about this error, cause i do this ‘query’ method a lot of times. But today, this error happend suddenly, i really don’t know what happend with my mac. i just installed mars library which relative with pandas, and nothing else. please help me for this problem, so appreciate!!

Expected Output

id name 1 1 None 2 2 None

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None python : 3.7.6.final.0 python-bits : 64 OS : Darwin OS-release : 19.4.0 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : zh_CN.UTF-8 LOCALE : zh_CN.UTF-8

pandas : 1.0.3 numpy : 1.18.1 pytz : 2019.3 dateutil : 2.8.1 pip : 20.1 setuptools : 46.1.3 Cython : None pytest : 5.0.1 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : 4.5.0 html5lib : None pymysql : 0.9.3 psycopg2 : None jinja2 : 2.10.1 IPython : 7.13.0 pandas_datareader: None bs4 : None bottleneck : None fastparquet : None gcsfs : None lxml.etree : 4.5.0 matplotlib : 3.1.2 numexpr : 2.7.1 odfpy : None openpyxl : 3.0.0 pandas_gbq : None pyarrow : 0.17.0 pytables : None pytest : 5.0.1 pyxlsb : None s3fs : None scipy : 1.4.1 sqlalchemy : 1.3.13 tables : None tabulate : 0.8.7 xarray : None xlrd : 1.2.0 xlwt : None xlsxwriter : None numba : 0.48.0

[TypeError: ‘Series’ objects are mutable, thus they cannot be hashed]

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
JohannHansingcommented, Nov 24, 2020

For the poeple wondering why this bug appears for them and not for others (or vice versa):

If you do not have the numexpr package installed, then python will be automatically used as engine. Thus, you do not need to specify engine='python' in the query method.

Consequently, one quick fix would be to uninstall the numexpr package. This may introduce other issues for you but it worked for me as I didn’t really use numexpr for anything.

2reactions
swigicatcommented, Oct 12, 2020

Is there any update on fixing this? Running queries on text data is a very common use-case.

For my case, I want to make a contains query and got this problem immediately. Found out that one needs to specify the NaN handling inside the query as well, otherwise the python engine complains about it. E.g. for a table containing NaNs the two commands below should have the same output –

df = pd.read_csv('test.csv', dtype=str, na_values='')
print(df[df['Column_A'].str.contains('abc', na=False)])
print(df.query("Column_A.str.contains('abc', na=False)", engine='python'))
Read more comments on GitHub >

github_iconTop Results From Across the Web

3 Ways to Solve Series Objects Are Mutable and Cannot be ...
#1 Option to Solve TypeError: Series objects are mutable and cannot be hashed ... So let's NOT use the series object as a...
Read more >
"Series objects are mutable and cannot be hashed" error
Shortly: gene_name[x] is a mutable object so it cannot be hashed. To use an object as a key in a dictionary, python needs...
Read more >
'Series' objects are mutable, thus they cannot be hashed' error ...
it means that in the indicated line you are trying to do something like this : my_string + my_list. a string can only...
Read more >
'Series' Objects Are Mutable, Thus They Cannot Be Hashed ...
This error occurs when you use mutable objects as key for a dictionary. You can even get involved in development by fixing bugs...
Read more >
What's new in 1.3.0 (July 2, 2021) - Pandas
These are bug fixes that might have notable behavior changes. ... raise a custom message such as 'Series' objects are mutable, thus they...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found