-
Notifications
You must be signed in to change notification settings - Fork 50
feat: add DataFrame.pipe() method #421
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
377b888
feat: add DataFrame.pipe() method
TrevorBergeron d93de42
make pipe test compatible with legacy sql
TrevorBergeron 43a406e
add examples to pipe docstring
TrevorBergeron 68c3170
add series.pipe test
TrevorBergeron a7e39b0
Merge branch 'main' into pipe
TrevorBergeron e76f60c
fix docstring render issues
TrevorBergeron ee28c5a
Merge branch 'main' into pipe
TrevorBergeron 0d3efe7
Merge remote-tracking branch 'github/main' into pipe
TrevorBergeron 8815167
fix vendored imports
TrevorBergeron e048843
Merge branch 'main' into pipe
TrevorBergeron 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Contains code from https://github.com/pandas-dev/pandas/blob/main/pandas/core/common.py | ||
from __future__ import annotations | ||
|
||
from typing import Callable, TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from bigframes_vendored.pandas.pandas._typing import T | ||
|
||
|
||
def pipe( | ||
obj, func: Callable[..., T] | tuple[Callable[..., T], str], *args, **kwargs | ||
) -> T: | ||
""" | ||
Apply a function ``func`` to object ``obj`` either by passing obj as the | ||
first argument to the function or, in the case that the func is a tuple, | ||
interpret the first element of the tuple as a function and pass the obj to | ||
that function as a keyword argument whose key is the value of the second | ||
element of the tuple. | ||
|
||
Args: | ||
func (callable or tuple of (callable, str)): | ||
Function to apply to this object or, alternatively, a | ||
``(callable, data_keyword)`` tuple where ``data_keyword`` is a | ||
string indicating the keyword of ``callable`` that expects the | ||
object. | ||
args (iterable, optional): | ||
Positional arguments passed into ``func``. | ||
kwargs (dict, optional): | ||
A dictionary of keyword arguments passed into ``func``. | ||
|
||
Returns: | ||
object: the return type of ``func``. | ||
""" | ||
shobsi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if isinstance(func, tuple): | ||
func, target = func | ||
if target in kwargs: | ||
msg = f"{target} is both the pipe target and a keyword argument" | ||
raise ValueError(msg) | ||
kwargs[target] = obj | ||
return func(*args, **kwargs) | ||
else: | ||
return func(obj, *args, **kwargs) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.