-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: NDFrame.pipe, GroupBy.pipe etc. #39093
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fcd6d36
TYP: type up NDFrame.pipe GroupBy.pipe etc.
topper-123 cde9241
fixup flake8 stuff
topper-123 b5dace1
fixup more stuff
topper-123 1b7fce0
fixup more stuff
topper-123 3dfcef0
don't use TYPE_CHECKING
topper-123 34a83db
flake8 stuff
topper-123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ class providing the base-class of operations. | |
(defined in pandas.core.groupby.generic) | ||
expose these user-facing objects to provide specific functionality. | ||
""" | ||
from __future__ import annotations | ||
|
||
from contextlib import contextmanager | ||
import datetime | ||
|
@@ -14,6 +15,7 @@ class providing the base-class of operations. | |
from textwrap import dedent | ||
import types | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Callable, | ||
Dict, | ||
FrozenSet, | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
|
||
|
||
_common_see_also = """ | ||
See Also | ||
-------- | ||
|
@@ -476,7 +482,7 @@ def f(self): | |
|
||
|
||
@contextmanager | ||
def group_selection_context(groupby: "BaseGroupBy") -> Iterator["BaseGroupBy"]: | ||
def group_selection_context(groupby: BaseGroupBy) -> Iterator[BaseGroupBy]: | ||
""" | ||
Set / reset the group_selection_context. | ||
""" | ||
|
@@ -724,8 +730,8 @@ def _set_group_selection(self) -> None: | |
|
||
@final | ||
def _set_result_index_ordered( | ||
self, result: "OutputFrameOrSeries" | ||
) -> "OutputFrameOrSeries": | ||
self, result: OutputFrameOrSeries | ||
) -> OutputFrameOrSeries: | ||
# set the result index on the passed values object and | ||
# return the new object, xref 8046 | ||
|
||
|
@@ -790,7 +796,12 @@ def __getattr__(self, attr: str): | |
), | ||
) | ||
@Appender(_pipe_template) | ||
def pipe(self, func, *args, **kwargs): | ||
def pipe( | ||
self, | ||
func: Union[Callable[..., T], Tuple[Callable[..., T], str]], | ||
*args, | ||
**kwargs, | ||
) -> T: | ||
return com.pipe(self, func, *args, **kwargs) | ||
|
||
plot = property(GroupByPlot) | ||
|
@@ -3058,7 +3069,7 @@ def get_groupby( | |
by: Optional[_KeysArgType] = None, | ||
axis: int = 0, | ||
level=None, | ||
grouper: "Optional[ops.BaseGrouper]" = None, | ||
grouper: Optional[ops.BaseGrouper] = None, | ||
exclusions=None, | ||
selection=None, | ||
as_index: bool = True, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from __future__ import annotations | ||
|
||
import copy | ||
from datetime import timedelta | ||
from textwrap import dedent | ||
from typing import Dict, Optional, Union, no_type_check | ||
from typing import TYPE_CHECKING, Callable, Dict, Optional, Tuple, Union, no_type_check | ||
|
||
import numpy as np | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
|
||
_shared_docs_kwargs: Dict[str, str] = {} | ||
|
||
|
||
|
@@ -231,7 +236,12 @@ def _assure_grouper(self): | |
2012-08-04 1""", | ||
) | ||
@Appender(_pipe_template) | ||
def pipe(self, func, *args, **kwargs): | ||
def pipe( | ||
self, | ||
func: Union[Callable[..., T], Tuple[Callable[..., T], str]], | ||
*args, | ||
**kwargs, | ||
) -> T: | ||
return super().pipe(func, *args, **kwargs) | ||
|
||
_agg_see_also_doc = dedent( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.