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.

TypeError on argmax of object dtype (change from 0.20.3)

See original GitHub issue
>>> import pandas as pd
>>> pd.Series([0, 0], dtype='object').argmax()

I was doing action = state_action.idxmax() where state_action was of type ‘pandas.core.series.Series’. When I run in 0.21.0, it gives the following error:

File “/usr/local/lib/python3.5/dist-packages/pandas/core/series.py”, line 1357, in idxmax i = nanops.nanargmax(_values_from_object(self), skipna=skipna) File “/usr/local/lib/python3.5/dist-packages/pandas/core/nanops.py”, line 74, in _f raise TypeError(msg.format(name=f.name.replace(‘nan’, ‘’))) TypeError: reduction operation ‘argmax’ not allowed for this dtype

However, when I downgraded to pandas 0.20.3, it worked just fine. You might wanna look into this. 😃

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

6reactions
DGradycommented, Nov 2, 2017

As a workaround, you can call argmax on the underlying NumPy array:

Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 27 2017, 12:14:30) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.Series(['one', 'two']).values.argmax()
1
0reactions
fleimgrubercommented, Nov 10, 2021

Seeing the same issue as @mar-ses in pandas 1.3.3, i.e. .max() works on pd.Timestamps, but idxmax() does not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting TypeError: reduction operation 'argmax' not allowed ...
TypeError : reduction operation 'argmax' not allowed for this dtype The problem: 1) the type of "mean recall score" is object, you can't...
Read more >
What's new in 1.3.0 (July 2, 2021) - Pandas
Calling hash on non-hashable pandas objects will now raise TypeError with the built-in error message (e.g. unhashable type: 'Series' ).
Read more >
What's New - Xarray
Fixed “unhashable type” error trying to read NetCDF file with variable having ... Fix bug in where() when passing non-xarray objects with keep_attrs=True...
Read more >
Change data type of given numpy array - GeeksforGeeks
In order to change the dtype of the given array object, we will use numpy.astype() function. The function takes an argument which is...
Read more >
scikit-learn user guide
The homogeneous NumPy and SciPy data objects currently expected are most efficient ... At change.org we automate the use of scikit-learn's ...
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