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: idxmin() fails for nullable integer data type (Int64) #33719

Closed
2 of 3 tasks
cklb opened this issue Apr 22, 2020 · 2 comments · Fixed by #37924
Closed
2 of 3 tasks

BUG: idxmin() fails for nullable integer data type (Int64) #33719

cklb opened this issue Apr 22, 2020 · 2 comments · Fixed by #37924
Labels
Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays
Milestone

Comments

@cklb
Copy link

cklb commented Apr 22, 2020

  • 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

import pandas as pd

s = pd.Series([1, 2, 3, 4], dtype="Int64")
s.idxmax()

Problem description

Currently, the idxmax call fails with

  File "~lib/python3.8/site-packages/pandas/core/series.py", line 2110, in idxmax
    i = nanops.nanargmax(com.values_from_object(self), skipna=skipna)
  File "~lib/python3.8/site-packages/pandas/core/nanops.py", line 64, in _f
    raise TypeError(
TypeError: reduction operation 'argmax' not allowed for this dtype

being raised. This may be a duplicate of #32749, although the focus there seems to be generating the exception I already encountered.

Expected Output

Should be 3, I guess.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.8.2.final.0
python-bits : 64
OS : Linux
OS-release : 5.5.13-arch2-1
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8

pandas : 1.0.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : 2.4.4
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.0
numexpr : None
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : 0.8.6
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : None
numba : None
None

@cklb cklb added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 22, 2020
@dsaxton dsaxton added NA - MaskedArrays Related to pd.NA and nullable extension arrays and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 22, 2020
@dsaxton
Copy link
Member

dsaxton commented Apr 22, 2020

Thanks, I would say this is a distinct issue. The error on master is a little different:

[ins] In [1]: ser = pd.Series([1, 2, 3], dtype="Int64")                                                                                                                                                      

[ins] In [2]: ser.idxmax()                                                                                                                                                                                   
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-b02670299a79> in <module>
----> 1 ser.idxmax()

~/pandas/pandas/core/series.py in idxmax(self, axis, skipna, *args, **kwargs)
   2077         """
   2078         skipna = nv.validate_argmax_with_skipna(skipna, args, kwargs)
-> 2079         i = nanops.nanargmax(self._values, skipna=skipna)
   2080         if i == -1:
   2081             return np.nan

~/pandas/pandas/core/nanops.py in _f(*args, **kwargs)
     69             try:
     70                 with np.errstate(invalid="ignore"):
---> 71                     return f(*args, **kwargs)
     72             except ValueError as e:
     73                 # we want to transform an object array

~/pandas/pandas/core/nanops.py in nanargmax(values, axis, skipna, mask)
    906         values, True, fill_value_typ="-inf", mask=mask
    907     )
--> 908     result = values.argmax(axis)
    909     result = _maybe_arg_null_out(result, axis, mask, skipna)
    910     return result

AttributeError: 'IntegerArray' object has no attribute 'argmax'

@jorisvandenbossche
Copy link
Member

This is related to #27801

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants