Skip to content

Commit

Permalink
Merge pull request #89 from shriyakalakata/min-docstring
Browse files Browse the repository at this point in the history
Add docstring for Expr.min()
  • Loading branch information
MarcoGorelli authored May 6, 2024
2 parents b25d359 + 600e860 commit 7862dc1
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 @@ -352,6 +352,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 7862dc1

Please sign in to comment.