-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
TYP: NDFrame.pipe, GroupBy.pipe etc. #39093
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @topper-123 generally lgtm
pandas/core/generic.py
Outdated
@@ -123,6 +123,7 @@ | |||
|
|||
if TYPE_CHECKING: | |||
from pandas._libs.tslibs import BaseOffset | |||
from pandas._typing import T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imports from _typing are already guarded.
pandas/core/groupby/groupby.py
Outdated
@@ -78,6 +80,10 @@ class providing the base-class of operations. | |||
from pandas.core.sorting import get_group_index_sorter | |||
from pandas.core.util.numba_ import NUMBA_FUNC_CACHE | |||
|
|||
if TYPE_CHECKING: | |||
from pandas._typing import T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
pandas/core/resample.py
Outdated
@@ -43,6 +45,9 @@ | |||
from pandas.tseries.frequencies import is_subperiod, is_superperiod | |||
from pandas.tseries.offsets import DateOffset, Day, Nano, Tick | |||
|
|||
if TYPE_CHECKING: | |||
from pandas._typing import T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
Updated. |
I think this is ok to merge? |
I think so. We may want to have an alias for this, but as the type is not yet complete I think we should leave that to later. I say incomplete since we will replace the but in the spirit of gradual typing, this gets the return type sorted. |
.pipe takes very generic callables, so I don’t think it’s possible to type more. Can you give an example what you’re thinking? In python 3.10 there’s something coming that may improve typing for .pipe, but that’s far in the future for Pandas... |
if func is a tuple, it is indeed not possible to bind to a keyword argument, but if func is not a tuple and args is not specified, then the function should take just 1 positional argument which is the object? so one of the overloads would be
where S is a TypeVar and args not specified (args may need to be None, I can't remember off the top of my head) Indeed, this is out of scope for now and I have approved the changes as is. |
Ok. I think it’s ok to wait with that... |
yeah, since we maybe pulling in some type stubs, #28142 (comment), I suspect that we can't yet inline those stubs where the types are not compatible with Python 3.7 (without typing_extensions) and I suspect the overloads will be in stub file instead of inline ( and may be able to adopt PEP 612 sooner.) |
Thanks @topper-123 |
Type up
pipe
function and methods. This allows type checkers to understand the return value type from pipes, which is nice.