Skip to content

idxmax() not available on groupby anymore #5786

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

Closed
jorisvandenbossche opened this issue Dec 28, 2013 · 6 comments · Fixed by #5787
Closed

idxmax() not available on groupby anymore #5786

jorisvandenbossche opened this issue Dec 28, 2013 · 6 comments · Fixed by #5787

Comments

@jorisvandenbossche
Copy link
Member

Just saw an example in this SO question, the use of idxmax() on a groupby object:

df.groupby(...).idxmax()

This worked in 0.12, but not anymore in 0.13 as it is not in the whitelist.

@jreback
Copy link
Contributor

jreback commented Dec 28, 2013

you can add to whitelist
no depreciation warning anymore because u also need to maintain a blacklist which makes maintaining this even harder

FYI

you can always do

df.groupby(...).apply(lambda x: x.idxmax())

@jorisvandenbossche
Copy link
Member Author

@jreback I know, but for idxmax I think this is usefull enough to have to shortcut available. Plus, this will break existing code (as the example on SO shows that it is used).

And I was just about to open an new issue about this, because it seems the apply also does not work the same as in 0.12. With example from this SO (http://stackoverflow.com/questions/20819702/hourly-frequency-count-with-python/20820166#20820166), and with 0.13rc, this:

df.groupby(df.index.date).apply(lambda x: x.idxmax())

generates a

ValueError: Shape of passed values is (1, 3), indices imply (1, 3)

while in 0.12 it does work.

It has to do I think with difference between SeriesGroupby and DataFrameGroupby with one column, as df.groupby(df.index.date)['value'].apply(lambda x: x.idxmax()) does work in master, but in 0.12 both ways work.

@jreback
Copy link
Contributor

jreback commented Dec 28, 2013

ok go ahead and do a or for adding idxmax/min to whitelist (and in the test for same)

I'll look at the apply issue

@jreback
Copy link
Contributor

jreback commented Dec 28, 2013

can u open the apply as a separate issue with a small example
thanks (so close this one with a pr for adding idxmax/min to whitelist)

@jorisvandenbossche
Copy link
Member Author

@jreback opened new issue #5788

@jreback
Copy link
Contributor

jreback commented Dec 28, 2013

thanks for pr and issues!

jreback added a commit that referenced this issue Dec 28, 2013
Add idxmax/idxmin to groupby dispatch whitelist (#5786)
yarikoptic added a commit to neurodebian/pandas that referenced this issue Jan 5, 2014
Version 0.13.0

* tag 'v0.13.0': (817 commits)
  RLS: 0.13.0 final
  COMPAT: back compat for HDFStore with a Term
  DOC: fix minor doc build warnings
  TST: aggregate_item_by_item test failure (GH5782)
  DOC: minor doc updates
  BUG: remove convert_numeric=True from groupbys      perform soft-conversion of numeric dtypes instead
  BUG: resolved GH5788 under numpy < 1.7 because vstack is odd with M8[ns]
  INT: allow internal errors in block construction to bubble up
  BUG: dont' coerce reductions in a groupby always to datetimes; only when we have      actual Timestamps in the data (GH5788,GH5789)
  Add idxmax/idxmin to groupby dispatch whitelist (pandas-dev#5786)
  TST: ensure_clean needs to import nose to skipTest()
  BLD: print_versions get uname() via cross-platform API
  TST: ensure_clean skips test when fs doesn't support unicode (sparc)
  Update comparison_with_r.rst
  BUG: big endian timedelta fix (GH5779)
  TST: closes (GH5778), failing tests on non-little endian for stata (sparc)
  DOC: Mention rpy2 breakage in release notes
  BUG: setitem for iloc/loc with a slice on a Series (GH5771)
  BUG: regression in read_csv parser handling of usecols GH5766
  TST: corner_case for read_csv with usecols GH5766
  ...
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

Successfully merging a pull request may close this issue.

2 participants