From f82c0f22e09a739d3775b354f852739f6bb5a990 Mon Sep 17 00:00:00 2001 From: Mfon Ekpo <58835748+mfonekpo@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:55:16 +0100 Subject: [PATCH] updated docstrings for class DataFrame (#270) --- narwhals/dataframe.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 2ff62c4c1..2677eda6c 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -195,17 +195,22 @@ class DataFrame(BaseFrame): Examples: Constructing a DataFrame from a dictionary: + >>> import pandas as pd >>> import polars as pl >>> import narwhals as nw >>> data = {"a": [1, 2], "b": [3, 4]} >>> df_pl = pl.DataFrame(data) - >>> df = nw.DataFrame(df_pl) - >>> df - ┌───────────────────────────────────────────────┐ - | Narwhals DataFrame | - | Use `narwhals.to_native` to see native output | - └───────────────────────────────────────────────┘ - >>> nw.to_native(df) + >>> df_pd = pd.DataFrame(data) + + we define a library-agnostic function: + + >>> def func(df_any): + ... df = nw.from_native(df_any) + ... return nw.to_native(df) + + You can pass either pandas or Polars to the function `func`: + + >>> func(df_pl) shape: (2, 2) ┌─────┬─────┐ │ a ┆ b │ @@ -215,6 +220,12 @@ class DataFrame(BaseFrame): │ 1 ┆ 3 │ │ 2 ┆ 4 │ └─────┴─────┘ + + >>> func(df_pd) + a b + 0 1 3 + 1 2 4 + """ def __init__(