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/ENH: should idxmax/idxmin work on object types? #4279

Closed
jseabold opened this issue Jul 17, 2013 · 5 comments · Fixed by #54109
Closed

BUG/ENH: should idxmax/idxmin work on object types? #4279

jseabold opened this issue Jul 17, 2013 · 5 comments · Fixed by #54109
Labels
Dtype Conversions Unexpected or buggy dtype conversions Enhancement Reduction Operations sum, mean, min, max, etc.

Comments

@jseabold
Copy link
Contributor

related is #6287

Just happened to come across this. Related to #2982

df = pd.DataFrame([["zimm", 2.5],["biff", 1.],["bid", 12.]])

This is fine (I was surprised it worked for objects)

df.max()

This falls down

df.idxmax()

I'd be fine if there's a strong performance reason not to support this, though it would be nice to not return an error at least. Maybe a stop-gap solution is to only return a solution for numeric types similar to the quantiles method.

@jreback
Copy link
Contributor

jreback commented Jul 20, 2013

yep...related is #4147, should prob work

could prob support a numeric=True keyword to only work on numeric (and dates?) types, otherwise return for all types? (you can of course do this with df._get_numeric_data(), but maybe easier this way)

what do you think?

@jseabold
Copy link
Contributor Author

Yeah, I found _get_numeric_data looking at quantiles. Didn't want to point people to the private method but would make an easy PR.

@jreback
Copy link
Contributor

jreback commented Jul 20, 2013

yep...have the numeric_only flag on quantile....I think that's the best way to go here (add to min,max,idx,idxmax...

@jseabold
Copy link
Contributor Author

Might be nice to also support this for objects at some point. I'm pretty sure there's a deterministic ordering for objects in Python 2/3, maybe using __repr__? Not sure. I remember discussing this for patsy. Can't find the discussion right now though.

@jreback
Copy link
Contributor

jreback commented Jul 20, 2013

yep...see issue #4147, this is actually currently a numpy bug (works for max but not for min, when having nan present)....pretty easy fix....should default then be numeric_only=False? as max...et al do make sense generally here

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Mar 28, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@datapythonista datapythonista modified the milestones: Contributions Welcome, Someday Jul 8, 2018
@jbrockmendel jbrockmendel removed the Indexing Related to indexing on series/frames, not to indexes themselves label Apr 14, 2020
@jbrockmendel jbrockmendel added the Reduction Operations sum, mean, min, max, etc. label Oct 29, 2021
@mroeschke mroeschke removed this from the Someday milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Enhancement Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants