From 39369024b16476c399d496116be7c6bea648d3d7 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:53:17 +0100 Subject: [PATCH] fixup dataframe and lazyframe docstrings --- narwhals/dataframe.py | 92 ++++++------------------------------------- 1 file changed, 12 insertions(+), 80 deletions(-) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 75fa82254..d94eb9d6d 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -183,49 +183,13 @@ def join( class DataFrame(BaseFrame): - r""" - Two-dimensional data structure representing data as a table with rows and columns. - - Arguments: - df: A pandas-like dataframe (Pandas, cuDF or Modin), a Polars dataframe, - a narwhals DataFrame or a narwhals LazyFrame. - - is_polars: if set to `True`, assume the dataframe to be of Polars type. - - 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_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 │ - │ --- ┆ --- │ - │ i64 ┆ i64 │ - ╞═════╪═════╡ - │ 1 ┆ 3 │ - │ 2 ┆ 4 │ - └─────┴─────┘ + """ + Narwhals DataFrame, backed by a native dataframe. - >>> func(df_pd) - a b - 0 1 3 - 1 2 4 + The native dataframe might be pandas.DataFrame, polars.DataFrame, ... + This class is not meant to be instantiated directly - instead, use + `narwhals.from_native`. """ def __init__( @@ -1485,45 +1449,13 @@ def null_count(self: Self) -> DataFrame: class LazyFrame(BaseFrame): - r""" - Representation of a Lazy computation graph/query against a DataFrame. - - This allows for whole-query optimisation in addition to parallelism, and - is the preferred (and highest-performance) mode of operation for narwhals. - - Arguments: - df: A pandas-like dataframe (Pandas, cuDF or Modin), a Polars dataframe, - a Polars lazyframe, a narwhals DataFrame or a narwhals LazyFrame. - - is_polars: if set to `True`, assume the dataframe to be of Polars type. - - Note: - Initialising `LazyFrame(...)` directly is equivalent to `DataFrame(...).lazy()`. - - Examples: - Constructing a LazyFrame directly from a dictionary: - - >>> import polars as pl - >>> import narwhals as nw - >>> data = {"a": [1, 2], "b": [3, 4]} - >>> lf_pl = pl.LazyFrame(data) - >>> lf = nw.LazyFrame(lf_pl) - >>> dframe = lf.collect() - >>> dframe - ┌───────────────────────────────────────────────┐ - | Narwhals DataFrame | - | Use `narwhals.to_native` to see native output | - └───────────────────────────────────────────────┘ - >>> nw.to_native(dframe) - shape: (2, 2) - ┌─────┬─────┐ - │ a ┆ b │ - │ --- ┆ --- │ - │ i64 ┆ i64 │ - ╞═════╪═════╡ - │ 1 ┆ 3 │ - │ 2 ┆ 4 │ - └─────┴─────┘ + """ + Narwhals DataFrame, backed by a native dataframe. + + The native dataframe might be pandas.DataFrame, polars.LazyFrame, ... + + This class is not meant to be instantiated directly - instead, use + `narwhals.from_native`. """ def __init__(