-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: TypeError on Series(dtype='string').value_counts().idxmax() #36566
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
Comments
Confirming this happens on 1.2 master. Output of pd.show_versions()INSTALLED VERSIONScommit : 76eb314 pandas : 1.2.0.dev0+232.g76eb314a0 A similar snippet with In [11]: pd.Series(1, dtype='Int64').value_counts().idxmax()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-0a7f15f3eb23> in <module>
----> 1 pd.Series(1, dtype='Int64').value_counts().idxmax()
/workspaces/pandas-arw2019/pandas/core/series.py in idxmax(self, axis, skipna, *args, **kwargs)
2187 """
2188 skipna = nv.validate_argmax_with_skipna(skipna, args, kwargs)
-> 2189 i = nanops.nanargmax(self._values, skipna=skipna)
2190 if i == -1:
2191 return np.nan
/workspaces/pandas-arw2019/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
/workspaces/pandas-arw2019/pandas/core/nanops.py in nanargmax(values, axis, skipna, mask)
922 """
923 values, mask, _, _, _ = _get_values(values, True, fill_value_typ="-inf", mask=mask)
--> 924 result = values.argmax(axis)
925 result = _maybe_arg_null_out(result, axis, mask, skipna)
926 return result
TypeError: argmax() takes 1 positional argument but 2 were given but if we switch to In [12]: pd.Series(1, dtype='int64').value_counts().idxmax()
Out[12]: 1 |
So we recently added Note, you don't need the In [21]: pd.Series(1, dtype='Int64').idxmax()
...
TypeError: argmax() takes 1 positional argument but 2 were given |
Expected output
Obtain the most frequent string in a series:
>>> pd.Series('a').value_counts().idxmax() 'a'
Problem
Changing the dtype on the second example from
'object'
to'string'
breaks this idiom:The problem is evidently not due to a
'string'
index:Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: