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

Series idxmin() TypeError?Need change type to 'float' #41696

Closed
rICHi97 opened this issue May 28, 2021 · 4 comments
Closed

Series idxmin() TypeError?Need change type to 'float' #41696

rICHi97 opened this issue May 28, 2021 · 4 comments

Comments

@rICHi97
Copy link

rICHi97 commented May 28, 2021

i'm using idxmin() on a series, which is like:

    ltc: 
    调度报障工单号
    DD182103227    5
                  ..
    DD082104265    5
    Name: 供电所, Length: 848, dtype: Int64

However, when using:
ltc.idxmin()

i got an error:
TypeError: argmin() takes 1 positional argument but 2 were given

when using:
ltc.astype('float').idxmin()

i got the right answer:
'DD092104104'

But the api doesn't say that idxmin() can only use on float data.Why?

@pablodz
Copy link

pablodz commented May 28, 2021

I tried to replicate the error but can't get it.

INPUT:

import pandas as pd
import numpy as np

df=pd.DataFrame({'col':['DD182103227','DD082104265'],
                'value':[5,4]},dtype=np.int64)
df.set_index('col')

OUTPUT:

             value
col               
DD182103227      5
DD082104265      4

INPUT:

df.info()

OUTPUT:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2 entries, 0 to 1
Data columns (total 2 columns):
 #   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
 0   col     2 non-null      object
 1   value   2 non-null      int64 
dtypes: int64(1), object(1)
memory usage: 160.0+ bytes

INPUT:

df['value'].idxmin()

OUTPUT:

1

INPUT:

df['value'].astype('float').idxmin()

OUTPUT:

1

@rICHi97 rICHi97 closed this as completed May 28, 2021
@rICHi97
Copy link
Author

rICHi97 commented May 28, 2021

@ZurMaD
Thanks for your reply.
There is a difference between your test data and mine:
my data contains missing value, .
Tyr this code:
IN:
test = pd.Series([1, 2, None], dtype='Int64')
OUT:
0 1 1 2 2 <NA> dtype: Int64
IN:
test.idxmin()
OUT:
TypeError: argmin() takes 1 positional argument but 2 were given

Maybe integer dtypes and missing data causes this problem. But idxmin provides a skipna param and default is True, I don't know why it can't handle integer data.

@rICHi97 rICHi97 reopened this May 28, 2021
@pablodz
Copy link

pablodz commented May 28, 2021

Related of #33719 and with a PR in #27801

Uhmm may someone of the main branch take a look? Looks like a BUG as described initially

But with example provided in docs works

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.idxmin.html?highlight=series%20idxmin#pandas.Series.idxmin

Basically fails when dtype='Int64'

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2cb9652
python : 3.9.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.0-17-generic
Version : #18-Ubuntu SMP Thu May 6 20:10:11 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.4
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.1
pip : 20.3.4
setuptools : 52.0.0
Cython : 0.29.23
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.23.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@mzeitlin11
Copy link
Member

This was fixed by #37924 with tests. (Fix is only in master, will be in 1.3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants