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

Return type of pipe not consistent with types at run time #908

Open
davetapley opened this issue Apr 18, 2024 · 1 comment
Open

Return type of pipe not consistent with types at run time #908

davetapley opened this issue Apr 18, 2024 · 1 comment

Comments

@davetapley
Copy link
Contributor

Describe the bug

Using pipe returns a instance of the type pipe is called on, but the type stubs imply it's the type of the function being applied by pipe.

i.e. if my function returns a DataFrame, but I call pipe on a class which inherits from DataFrame, then at run time I get back the subclass, but the typing implies it's just a vanilla DataFrame.

To Reproduce

Subclass DataFrame per the docs.

Create a pipe function using this signature:

def func(df: DataFrame) -> DataFrame:

Observe that at run time if I use pipe on the subtype, your get back an instance of the subtype, which is nice:

class SubDB(DataFrame):
   ... # required other stuff

sub = SubDF()
sub_f = sub.pipe(func)
type(sub_f) # is SubDF()

But if you hover sub_f in VSCode it's type is DataFrame.

Please complete the following information:

  • OS: Linux
  • OS Version 20.04.6
  • python version 3.11.7
  • version of type checker pyright version 1.1.356, commit 6652c4a8)
  • version of installed pandas-stubs 2.2.1.240316

Additional context

The offending type is the T here, it it should return Self:

def pipe(
self,
func: Callable[Concatenate[Self, P], T],
*args: P.args,
**kwargs: P.kwargs,
) -> T: ...

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 18, 2024

Thanks for the report. PR with tests welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants