Skip to content

Commit

Permalink
fixup dataframe and lazyframe docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jun 10, 2024
1 parent 9017e01 commit 3936902
Showing 1 changed file with 12 additions and 80 deletions.
92 changes: 12 additions & 80 deletions narwhals/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -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__(
Expand Down

0 comments on commit 3936902

Please sign in to comment.