Closed
Description
Summary
Currently on master, groupby.transform
with func
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 raises AttributeError
similar to what's reported in #27472.
Code Sample
# On branch of PR31101
>>> pd.__version__
'1.0.0rc0+162.g56c70234e'
>> df = pd.DataFrame(
... {
... "A": ["foo", "foo", "foo", "foo", "bar", "bar", "baz"],
... "B": [1, 2, np.nan, 3, 3, np.nan, 4],
... }
... )
>>> df
A B
0 foo 1.0
1 foo 2.0
2 foo NaN
3 foo 3.0
4 bar 3.0
5 bar NaN
6 baz 4.0
>>> df.groupby("A").pad() # This is ok
B
0 1.0
1 2.0
2 2.0
3 3.0
4 3.0
5 3.0
6 4.0
>>> df.groupby("A").transform("pad") # This raises AttributeError
Traceback (most recent call last):
...
...
AttributeError: 'Series' object has no attribute 'pad'
>>> df.groupby("A").transform("cumcount")
Traceback (most recent call last):
...
...
AttributeError: 'Series' object has no attribute 'cumcount'
Ideally we want to allow all of the above 3 functions in groupby.transform