Skip to content

Commit

Permalink
added max method docstring (#227)
Browse files Browse the repository at this point in the history
* added max method docstring

* Apply suggestions from code review

Co-authored-by: Marco Edward Gorelli <[email protected]>

* corrected  docstring for max method

---------

Co-authored-by: Marco Edward Gorelli <[email protected]>
  • Loading branch information
brentomagic and MarcoGorelli authored May 31, 2024
1 parent 83395e9 commit 4a85735
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion narwhals/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2468,7 +2468,43 @@ def min(*columns: str) -> Expr:

def max(*columns: str) -> Expr:
"""
Instantiate an expression representing the maximum of one or more columns, similar to `polars.max`.
Return the maximum value.
Note:
Syntactic sugar for ``nw.col(columns).max()``.
Parameters:
*columns
Name(s) of the columns to use in the aggregation function.
Examples:
>>> import polars as pl
>>> import pandas as pd
>>> import narwhals as nw
>>> df_pd = pd.DataFrame({'a': [1, 2], 'b': [5, 10]})
>>> df_pl = pl.DataFrame({'a': [1, 2], 'b': [5, 10]})
Let's define a dataframe-agnostic function:
>>> def func(df_any):
... df = nw.from_native(df_any)
... df = df.select(nw.max('a'))
... return nw.to_native(df)
We can then pass either pandas or Polars to `func`:
>>> func(df_pd)
a
0 2
>>> func(df_pl)
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ i64 │
╞═════╡
│ 2 │
└─────┘
"""
return Expr(lambda plx: plx.max(*columns))

Expand Down

0 comments on commit 4a85735

Please sign in to comment.