Skip to content

DataFrame.Groupby.Rolling is missing proper typing #737

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
Dr-Irv opened this issue Jun 28, 2023 · 0 comments · Fixed by #848
Closed

DataFrame.Groupby.Rolling is missing proper typing #737

Dr-Irv opened this issue Jun 28, 2023 · 0 comments · Fixed by #848
Labels
Groupby Window rolling, ewma, expanding

Comments

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jun 28, 2023

Describe the bug

In this line:

def rolling(self, *args, **kwargs): ...

we are not returning a Rolling object with the proper subtype of Series or DataFrame

To Reproduce

from typing_extensions import reveal_type
import pandas as pd

df = pd.DataFrame(
    {"A": [1, 1, 2, 2], "B": [1, 2, 3, 4], "C": [0.362, 0.227, 1.267, -0.562]}
)

d1 = df.groupby("A").rolling(2).sum()

s1 = df.groupby("A")["B"].rolling(2).sum()

s2 = df.groupby("A").rolling(2)["B"].sum()

reveal_type(d1)

reveal_type(s1)

reveal_type(s2)

at runtime produces

Runtime type is 'DataFrame'
Runtime type is 'Series'
Runtime type is 'Series'

but pyright produces

  grbroll.py:14:13 - information: Type of "d1" is "Unknown"
  grbroll.py:16:13 - information: Type of "s1" is "Unknown"
  grbroll.py:18:13 - information: Type of "s2" is "Unknown"

Please complete the following information:

  • OS: Windows 10
  • python version: 3.9
  • version of type checker: pyright 1.1.313
  • version of installed pandas-stubs : 2.0.2.230605

Additional context

This will need some care to make sure that the types are done correctly. May have to move the def rolling from pandas-stubs/core/groupby/groupby.pyi to pandas-stubs/core/groupby/generic.pyi in DataFrameGroupby and SeriesGroupBy.

@Dr-Irv Dr-Irv added Groupby Window rolling, ewma, expanding labels Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant