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

argmin/argmax, idxmin/idxmax and datetime64 #2982

Closed
lodagro opened this issue Mar 6, 2013 · 9 comments
Closed

argmin/argmax, idxmin/idxmax and datetime64 #2982

lodagro opened this issue Mar 6, 2013 · 9 comments

Comments

@lodagro
Copy link
Contributor

lodagro commented Mar 6, 2013

In [65]: s
Out[65]: 
a   2013-01-02 00:00:00
b   2013-01-03 00:00:00
c   2013-01-04 00:00:00
d   2013-01-05 00:00:00
e                   NaT
dtype: datetime64[ns]

In [66]: s.argmin()
Out[66]: 4

In [67]: s.idxmin()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
...
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule 'safe'

In [68]: s.argmax()
Out[68]: 3

In [69]: s.idxmax()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
...
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule 'safe'
@lodagro lodagro mentioned this issue Mar 6, 2013
@jreback
Copy link
Contributor

jreback commented Mar 6, 2013

yep....I had change a few things...

@jreback
Copy link
Contributor

jreback commented Mar 7, 2013

thanks for the bug report...fixed in the pr above (and it fixes the failing test on 32-bit in argsort)

....in your example, s.argmin() is WRONG (because its calling the numpy argmin), argmax works (because NaT is a really big negative int). Not sure if should open an issue on this. (would essentially have them do self.index.get_loc(self.idxmin()). worth adding this feature?

@jreback
Copy link
Contributor

jreback commented Mar 9, 2013

I think u can close this

and if u want to open an issue about argmin/max

@lodagro
Copy link
Contributor Author

lodagro commented Mar 9, 2013

idxmax/idxmin are fine now! So ill close this one, as you proposed. Concerning argmin/argmax, ill leave it up to you to decide if those needs to be adressed/overloaded.

In [76]: s
Out[76]: 
a   2013-01-02 00:00:00
b   2013-01-03 00:00:00
c   2013-01-04 00:00:00
d   2013-01-05 00:00:00
e                   NaT
dtype: datetime64[ns]

In [77]: s.idxmin()
Out[77]: 'a'

In [78]: s.idxmax()
Out[78]: 'd'

Thanks!

@lodagro lodagro closed this as completed Mar 9, 2013
@lrq3000
Copy link

lrq3000 commented May 8, 2013

I'm getting the same issue with Pandas v0.11 stable on a DataFrame with dtype object (but it only contains float64 values), and also argmax() seems to have been deleted, it's not available anymore for DafaFrame.

/EDIT: Just casted the DataFrame into a float64 and it works again. But it's weird that idxmax() fails with object dtype with the error above, maybe another conditional check may be added to avoid failing like this?

@jreback
Copy link
Contributor

jreback commented May 8, 2013

you cannot use dtype of object (well you can), but it won't work well with datetimelike, use datetime64[ns], pls post what you are doing and i'll help you out

@lrq3000
Copy link

lrq3000 commented May 13, 2013

Thank you jreback but it's ok, my DataFrame is in fact only composed of floats (or strings which are only composed of numbers but then it's ok) and thus recasting into floats solved the problem, but it was weird because Pandas automatically casted my DataFrame as an object when there are only floats inside, that's why I was a bit surprised.

@jreback
Copy link
Contributor

jreback commented May 13, 2013

@lrq3000 glad that it worked, but as a general rule, object type is not very efficicient, that is why its very importatnt to use native dtypes.

@gerritholl
Copy link

Related: numpy/numpy#5610

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

4 participants