diff --git a/narwhals/expr.py b/narwhals/expr.py index 6eedbafa4..97c2e2d36 100644 --- a/narwhals/expr.py +++ b/narwhals/expr.py @@ -367,9 +367,11 @@ def mean(self) -> Self: Examples: >>> import polars as pl >>> import pandas as pd + >>> import pyarrow as pa >>> import narwhals as nw >>> df_pd = pd.DataFrame({"a": [-1, 0, 1], "b": [2, 4, 6]}) >>> df_pl = pl.DataFrame({"a": [-1, 0, 1], "b": [2, 4, 6]}) + >>> df_pa = pa.table({"a": [-1, 0, 1], "b": [2, 4, 6]}) Let's define a dataframe-agnostic function: @@ -377,7 +379,7 @@ def mean(self) -> Self: ... def func(df): ... return df.select(nw.col("a", "b").mean()) - We can then pass either pandas or Polars to `func`: + We can pass any supported library such as Pandas, Polars, or PyArrow to `func`: >>> func(df_pd) a b @@ -391,6 +393,13 @@ def mean(self) -> Self: ╞═════╪═════╡ │ 0.0 ┆ 4.0 │ └─────┴─────┘ + >>> func(df_pa) + pyarrow.Table + a: double + b: double + ---- + a: [[0]] + b: [[4]] """ return self.__class__(lambda plx: self._call(plx).mean()) @@ -4054,9 +4063,11 @@ def mean(*columns: str) -> Expr: Examples: >>> import pandas as pd >>> import polars as pl + >>> import pyarrow as pa >>> import narwhals as nw >>> df_pl = pl.DataFrame({"a": [1, 8, 3]}) >>> df_pd = pd.DataFrame({"a": [1, 8, 3]}) + >>> df_pa = pa.table({"a": [1, 8, 3]}) We define a dataframe agnostic function: @@ -4064,7 +4075,7 @@ def mean(*columns: str) -> Expr: ... def func(df): ... return df.select(nw.mean("a")) - We can then pass either pandas or Polars to `func`: + We can pass any supported library such as Pandas, Polars, or PyArrow to `func`: >>> func(df_pd) a @@ -4078,6 +4089,11 @@ def mean(*columns: str) -> Expr: ╞═════╡ │ 4.0 │ └─────┘ + >>> func(df_pa) + pyarrow.Table + a: double + ---- + a: [[4]] """ return Expr(lambda plx: plx.mean(*columns)) diff --git a/narwhals/stable/v1/__init__.py b/narwhals/stable/v1/__init__.py index 75da2a42c..7bcd6146e 100644 --- a/narwhals/stable/v1/__init__.py +++ b/narwhals/stable/v1/__init__.py @@ -1254,9 +1254,11 @@ def mean(*columns: str) -> Expr: Examples: >>> import pandas as pd >>> import polars as pl + >>> import pyarrow as pa >>> import narwhals.stable.v1 as nw >>> df_pl = pl.DataFrame({"a": [1, 8, 3]}) >>> df_pd = pd.DataFrame({"a": [1, 8, 3]}) + >>> df_pa = pa.table({"a": [1, 8, 3]}) We define a dataframe agnostic function: @@ -1264,7 +1266,7 @@ def mean(*columns: str) -> Expr: ... def func(df): ... return df.select(nw.mean("a")) - We can then pass either pandas or Polars to `func`: + We can pass any supported library such as Pandas, Polars, or PyArrow to `func`: >>> func(df_pd) a @@ -1278,6 +1280,11 @@ def mean(*columns: str) -> Expr: ╞═════╡ │ 4.0 │ └─────┘ + >>> func(df_pa) + pyarrow.Table + a: double + ---- + a: [[4]] """ return _stableify(nw.mean(*columns))