-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make DataFrame.any_rowwise top-level, rename to _horizontal (#324)
- Loading branch information
1 parent
2623018
commit 27d5fc4
Showing
5 changed files
with
176 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
28 changes: 28 additions & 0 deletions
28
spec/API_specification/examples/06_horizontal_functions.py
This file contains 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,28 @@ | ||
"""Example of how to use a horizontal function. | ||
Horizontal functions are functions that take multiple columns as input and return a | ||
single column as output. | ||
Examples include: | ||
- `any_horizontal` | ||
- `all_horizontal` | ||
These can be accessed by first using ``__dataframe_namespace__`` to get the | ||
namespace object, and then calling the function on the namespace object and passing | ||
an iterable of ``Column``s as input. | ||
""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from dataframe_api.typing import SupportsDataFrameAPI | ||
|
||
|
||
def main(df_raw: SupportsDataFrameAPI) -> SupportsDataFrameAPI: | ||
df = df_raw.__dataframe_consortium_standard__(api_version="2023-11.beta") | ||
ns = df.__dataframe_namespace__() | ||
df = df.filter( | ||
ns.any_horizontal(*[df.col(col_name) > 0 for col_name in df.column_names]), | ||
) | ||
return df.dataframe |