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

[FEA] Make Groupby.shift work for MultiIndex #15087

Closed
amanlai opened this issue Feb 19, 2024 · 1 comment · Fixed by #15098
Closed

[FEA] Make Groupby.shift work for MultiIndex #15087

amanlai opened this issue Feb 19, 2024 · 1 comment · Fixed by #15098
Labels
bug Something isn't working feature request New feature or request

Comments

@amanlai
Copy link

amanlai commented Feb 19, 2024

Say I have a MultiIndex Series as follows:

s = cudf.Series(range(4), index=cudf.MultiIndex.from_tuples([('a', 1), ('a', 2), ('b', 1), ('b', 2)], names=['f', 's']))

which looks like:

f   s
a  1    0
    2    1
b  1    2
    2    3
dtype: int64

I want to shift this Series down by the first index level:

s.groupby(level=0).shift(1)

but I get an error:

AttributeError: 'RangeIndex' object has no attribute '_names'

This should produce either

f   s
a  1    NaN
    2    0.0
b  1    NaN
    2    2.0
dtype: float64

or

f   s
a  2    0.0
b  2    2.0
dtype: float64

Right now, I can get my desired output by unstacking the Series, shifting it and then stacking it back:

s.to_frame().unstack('f').shift().rename(columns=lambda x: x[1]).stack()

which is very ugly. I would like cudf to extend groupby.shift to MultiIndex.

@amanlai amanlai added the feature request New feature or request label Feb 19, 2024
@shwina shwina added the bug Something isn't working label Feb 20, 2024
@shwina
Copy link
Contributor

shwina commented Feb 20, 2024

Thanks - this seems a bug with our implementation of .shift. Should be a relatively easy fix - we'll try to get to it ASAP!

rapids-bot bot pushed a commit that referenced this issue Feb 21, 2024
closes #15087
closes #11259

(The typing annotation is incorrect, but I guess there needs to be a check somewhere to make `_copy_type_metadata` stricter)

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #15098
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants