Skip to content

Commit

Permalink
update reduce docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
dougbrn committed Jun 10, 2024
1 parent d9c2e6e commit 5a7ec3d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/nested_pandas/nestedframe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ def reduce(self, func, *args, **kwargs) -> NestedFrame: # type: ignore[override
----------
func : callable
Function to apply to each nested dataframe. The first arguments to `func` should be which
columns to apply the function to.
columns to apply the function to. See the Notes for recommendations
on writing func outputs.
args : positional arguments
Positional arguments to pass to the function, the first *args should be the names of the
columns to apply the function to.
Expand All @@ -376,20 +377,18 @@ def reduce(self, func, *args, **kwargs) -> NestedFrame: # type: ignore[override
Notes
-----
The recommend return value of func should be a `pd.Series` where the indices are the names of the
output columns in the dataframe returned by `reduce`. Note however that in cases where func
returns a single value there may be a performance benefit to returning the scalar value
rather than a `pd.Series`.
By default, `reduce` will produce a `NestedFrame` with enumerated
column names for each returned value of the function. For more useful
naming, it's recommended to have `func` return a dictionary where each
key is an output column of the dataframe returned by `reduce`.
Example User Function:
```
import pandas as pd
def my_sum(col1, col2):
return pd.Series(
[sum(col1), sum(col2)],
index=["sum_col1", "sum_col2"],
)
'''reduce will return a NestedFrame with two columns'''
return {"sum_col1": sum(col1), "sum_col2": sum(col2)}
```
Expand Down

0 comments on commit 5a7ec3d

Please sign in to comment.