Skip to content

Commit

Permalink
Add docstring for Expr.min()
Browse files Browse the repository at this point in the history
  • Loading branch information
shriyakalakata committed May 6, 2024
1 parent 278665f commit 2c7229b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions narwhals/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,38 @@ def sum(self) -> Expr:
return self.__class__(lambda plx: self._call(plx).sum())

def min(self) -> Expr:
"""
Returns the minimum value(s) from a column(s).
Examples:
>>> import pandas as pd
>>> import polars as pl
>>> import narwhals as nw
>>> df_pd = pd.DataFrame({'a': [1, 2], 'b': [4, 3]})
>>> df_pl = pl.DataFrame({'a': [1, 2], 'b': [4, 3]})
Let's define a dataframe-agnostic function:
>>> def func(df_any):
... df = nw.from_native(df_any)
... df = df.select(nw.min('a','b'))
... return nw.to_native(df)
We can then pass either pandas or Polars to `func`:
>>> func(df_pd)
a b
0 1 3
>>> func(df_pl)
shape: (1, 2)
┌─────┬─────┐
│ a ┆ b │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1 ┆ 3 │
└─────┴─────┘
"""

return self.__class__(lambda plx: self._call(plx).min())

def max(self) -> Expr:
Expand Down

0 comments on commit 2c7229b

Please sign in to comment.