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: allow as_index=False for non aggregating groupby methods #4649

Closed
wants to merge 3 commits into from
Closed

BUG: allow as_index=False for non aggregating groupby methods #4649

wants to merge 3 commits into from

Conversation

cpcloud
Copy link
Member

@cpcloud cpcloud commented Aug 23, 2013

closes #4648
closes #3417

@ghost ghost assigned cpcloud Aug 23, 2013
@cpcloud
Copy link
Member Author

cpcloud commented Aug 23, 2013

@jreback merge-able? pretty trivial fix, but want to get your okay on it.

@jreback
Copy link
Contributor

jreback commented Aug 23, 2013

looks fine

FYI I think there might be an open issue related to this (aside from the one u indicates)

might be the same or unrelelated don't know

@hayd
Copy link
Contributor

hayd commented Aug 23, 2013

Does this work with an index which isn't plain (i.e. not just an arange)? Don't think you're testing for that...

@cpcloud
Copy link
Member Author

cpcloud commented Aug 23, 2013

@hayd good call thanks

@jtratner
Copy link
Contributor

Does this resolve #3805?

@hayd
Copy link
Contributor

hayd commented Aug 24, 2013

@cpcloud example I had in mind was something like this (with non-boring index), from your branch:

In [1]: df = pd.DataFrame([[1, 2], [2, 3], [1, 4], [1, 5], [2, 6]], index=list('abcde'))

In [2]: g = df.groupby(0, as_index=False)

In [3]: g.apply(lambda x: x)
Out[3]: 
   0  1
0  1  2
1  2  3
2  1  4
3  1  5
4  2  6

Shouldn't this have index of original DataFrame.

@hayd
Copy link
Contributor

hayd commented Aug 24, 2013

@jtratner nope (just tested)

@cpcloud
Copy link
Member Author

cpcloud commented Aug 24, 2013

ah then i misunderstood what as_index was supposed to do.

@hayd
Copy link
Contributor

hayd commented Aug 24, 2013

So I think the thing from SO was:

In [34]: g = df.groupby(0)

In [35]: g.apply(lambda x: x.head(2))
Out[35]: 
     0  1
0        
1 a  1  2
  c  1  4
2 b  2  3
  e  2  6

In [36]: g = df.groupby(0, as_index=False)

In [37]: g.apply(lambda x: x.head(2))
Out[37]: 
     0  1
0        
1 a  1  2
  c  1  4
2 b  2  3
  e  2  6

And we expect the latter not to include the group info.

   0  1
a  1  2
c  1  4
b  2  3
e  2  6

Now I think about it, we It could be completely misusing apply here...

@hayd hayd mentioned this pull request Aug 25, 2013
@hayd
Copy link
Contributor

hayd commented Aug 25, 2013

@cpcloud Think I have an even more trivial fix...!

@cpcloud
Copy link
Member Author

cpcloud commented Aug 25, 2013

@hayd Welcome to it! Out of town until Tuesday :)

@hayd hayd closed this in #4670 Aug 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants