-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: allow 'pad', 'backfill' and 'cumcount' in groupby.transform #31269
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
Hey! I would like to work on this. Could you guide me? |
@punndcoder28 The relevant PR #31101 has not been merged yet. After that is merged, you can try these three functions on master, and see what you can do. You can also take a look at #27472 to see what has been discussed. |
Ok. I will keep an eye out for PR #31101 and start as soon as it is merged. |
Hey @fujiaxiang. I tried out the functions on master now that PR #31101 got merged. I am getting the |
Are you sure? I just tried again on current master and I got |
This is the code I am executing: >>> df1 = pd.DataFrame(
... {
... "A": ["foo", "foo", "foo", "foo", "bar", "bar", "baz"],
... "B": [1,2,np.nan, 3,3,np.nan,4]
... }
... )
>>> df1.groupby("A").transform("pad")
B
0 2.0
1 2.0
2 2.0
3 2.0
4 1.0
5 1.0
6 2.0
>>> df1.groupby("A").transform("cumcount")
Traceback (most recent call last):
...
AttributeError: ("'Series' object has no attribute 'cumcount'", 'occurred at index B')
>>> df1.groupby("A").transform("backfill")
B
0 3.0
1 3.0
2 3.0
3 3.0
4 1.0
5 1.0
6 2.0 Am I missing something? |
I think you are not on the latest master. You can see that the result you showed for both |
Yes, my mistake. I built from the latest master and I am getting the errors. |
Hey @fujiaxiang . I went through the code but couldn't figure out where to make changes. Since you had worked on a similar issue could you give me some pointers? |
As a general guide you should try looking at the implementation of groupby.transform for other similar methods and mimic those. We already have implementations for these functions somewhere in the code so this shouldn't be too difficult to do. |
@punndcoder28 are you still interested? If not, I will take a look at it myself. |
Yes I am still interested. I am looking that the definitions of similar functions like you had advised. |
Hey @fujiaxiang . I was unable to find the definitions for other similar functions. |
Summary
Currently on master,
groupby.transform
withfunc
equals one of('fillna', 'pad', 'backfill', 'ffill', etc.)
yields wrong results (See #30918).With updates from PR (#31101), the incorrect outputs are fixed. However, when
func
is one of('pad', 'backfill', 'cumcout')
,groupby.transform
then raisesAttributeError
similar to what's reported in #27472.Code Sample
Ideally we want to allow all of the above 3 functions in
groupby.transform
The text was updated successfully, but these errors were encountered: