From 42ab8b3405fd8e1a3819cf5092c81387bf96d5a5 Mon Sep 17 00:00:00 2001 From: Nwabueze Ugoh <126014542+brentomagic@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:54:03 +0100 Subject: [PATCH] added docstring for all() (#277) --- narwhals/expression.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/narwhals/expression.py b/narwhals/expression.py index df1ed0f47..b4c1ed242 100644 --- a/narwhals/expression.py +++ b/narwhals/expression.py @@ -2340,7 +2340,39 @@ def col(*names: str | Iterable[str]) -> Expr: def all() -> Expr: """ - Instantiate an expression representing all columns, similar to `polars.all`. + Instantiate an expression representing all columns. + + Examples: + >>> import polars as pl + >>> import pandas as pd + >>> import narwhals as nw + >>> df_pd = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) + >>> df_pl = pl.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) + + Let's define a dataframe-agnostic function: + + >>> @nw.narwhalify + ... def func(df): + ... return df.select(nw.all() * 2) + + We can then pass either pandas or Polars to `func`: + + >>> func(df_pd) + a b + 0 2 8 + 1 4 10 + 2 6 12 + >>> func(df_pl) + shape: (3, 2) + ┌─────┬─────┐ + │ a ┆ b │ + │ --- ┆ --- │ + │ i64 ┆ i64 │ + ╞═════╪═════╡ + │ 2 ┆ 8 │ + │ 4 ┆ 10 │ + │ 6 ┆ 12 │ + └─────┴─────┘ """ return Expr(lambda plx: plx.all())