From 9d90734efea3ee4298150a91aff9b31cab55c42f Mon Sep 17 00:00:00 2001 From: Franco Masotti Date: Thu, 4 Apr 2024 16:39:40 +0200 Subject: [PATCH 1/6] Add docstring - Add `narwhals.dataframe.LazyFrame.collect` docstring --- narwhals/dataframe.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index a70a49b21..0300da3c5 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -1028,6 +1028,47 @@ def __init__( raise TypeError(msg) def collect(self) -> DataFrame: + r""" + Materialize this LazyFrame into a DataFrame. + + + Returns: + DataFrame + + Examples: + >>> import polars as pl + >>> import narwhals as nw + >>> lf_pl = pl.LazyFrame( + ... { + ... "a": ["a", "b", "a", "b", "b", "c"], + ... "b": [1, 2, 3, 4, 5, 6], + ... "c": [6, 5, 4, 3, 2, 1], + ... } + ... ) + >>> lf = nw.LazyFrame(lf_pl) + >>> lf + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> df = lf.group_by("a").agg(nw.all().sum()).collect() + >>> df + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(df).sort("a") + shape: (3, 3) + ┌─────┬─────┬─────┐ + │ a ┆ b ┆ c │ + │ --- ┆ --- ┆ --- │ + │ str ┆ i64 ┆ i64 │ + ╞═════╪═════╪═════╡ + │ a ┆ 4 ┆ 10 │ + │ b ┆ 11 ┆ 10 │ + │ c ┆ 6 ┆ 1 │ + └─────┴─────┴─────┘ + """ return DataFrame( self._dataframe.collect(), ) From 3c8e52b17ef5bbc5485ed5219fcbbaeb0e8d0bf8 Mon Sep 17 00:00:00 2001 From: Franco Masotti Date: Thu, 4 Apr 2024 17:04:08 +0200 Subject: [PATCH 2/6] Add docstrings - Add `narwhals.dataframe.LazyFrame.{collect,rename} docstrings --- narwhals/dataframe.py | 77 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 0300da3c5..ec6058b2c 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -1031,7 +1031,6 @@ def collect(self) -> DataFrame: r""" Materialize this LazyFrame into a DataFrame. - Returns: DataFrame @@ -1076,6 +1075,23 @@ def collect(self) -> DataFrame: # inherited @property def schema(self) -> dict[str, DType]: + r""" + Get a dict[column name, DType]. + + Examples: + >>> import polars as pl + >>> import narwhals as nw + >>> lf_pl = pl.LazyFrame( + ... { + ... "foo": [1, 2, 3], + ... "bar": [6.0, 7.0, 8.0], + ... "ham": ["a", "b", "c"], + ... } + ... ) + >>> lf = nw.LazyFrame(lf_pl) + >>> lf.schema # doctest: +SKIP + OrderedDict({'foo': Int64, 'bar': Float64, 'ham': String}) + """ return super().schema @property @@ -1095,6 +1111,65 @@ def select( return super().select(*exprs, **named_exprs) def rename(self, mapping: dict[str, str]) -> Self: + r""" + Rename column names. + + Arguments: + mapping: Key value pairs that map from old name to new name, or a + function that takes the old name as input and returns the + new name. + + Notes: + If existing names are swapped (e.g. 'A' points to 'B' and 'B' + points to 'A'), polars will block projection and predicate + pushdowns at this node. + + Examples: + >>> import polars as pl + >>> import narwhals as nw + >>> lf_pl = pl.LazyFrame( + ... { + ... "foo": [1, 2, 3], + ... "bar": [6, 7, 8], + ... "ham": ["a", "b", "c"], + ... } + ... ) + >>> lf = nw.LazyFrame(lf_pl) + >>> lframe = lf.rename({"foo": "apple"}).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (3, 3) + ┌───────┬─────┬─────┐ + │ apple ┆ bar ┆ ham │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ i64 ┆ str │ + ╞═══════╪═════╪═════╡ + │ 1 ┆ 6 ┆ a │ + │ 2 ┆ 7 ┆ b │ + │ 3 ┆ 8 ┆ c │ + └───────┴─────┴─────┘ + >>> lframe = lf.rename(lambda column_name: "c" + column_name[1:]).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (3, 3) + ┌─────┬─────┬─────┐ + │ coo ┆ car ┆ cam │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ i64 ┆ str │ + ╞═════╪═════╪═════╡ + │ 1 ┆ 6 ┆ a │ + │ 2 ┆ 7 ┆ b │ + │ 3 ┆ 8 ┆ c │ + └─────┴─────┴─────┘ + """ return super().rename(mapping) def head(self, n: int) -> Self: From a5ef70d87de4bed33197dd7b577d3e358e5af671 Mon Sep 17 00:00:00 2001 From: Franco Masotti Date: Thu, 4 Apr 2024 17:39:07 +0200 Subject: [PATCH 3/6] Add docstrings - Add `narwhals.dataframe.LazyFrame.{head,drop}` docstrings --- narwhals/dataframe.py | 137 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index ec6058b2c..836f15804 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -1173,9 +1173,146 @@ def rename(self, mapping: dict[str, str]) -> Self: return super().rename(mapping) def head(self, n: int) -> Self: + r""" + Get the first `n` rows. + + Arguments: + n: Number of rows to return. + + Notes: + Consider using the `fetch` operation if you only want to test + your query. The `fetch` operation will load the first `n` + rows at the scan level, whereas the `head`/`limit` are + applied at the end. + + Examples: + >>> import polars as pl + >>> import narwhals as nw + >>> lf_pl = pl.LazyFrame( + ... { + ... "a": [1, 2, 3, 4, 5, 6], + ... "b": [7, 8, 9, 10, 11, 12], + ... } + ... ) + >>> lf = nw.LazyFrame(lf_pl) + >>> lframe = lf.head(5).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (5, 2) + ┌─────┬─────┐ + │ a ┆ b │ + │ --- ┆ --- │ + │ i64 ┆ i64 │ + ╞═════╪═════╡ + │ 1 ┆ 7 │ + │ 2 ┆ 8 │ + │ 3 ┆ 9 │ + │ 4 ┆ 10 │ + │ 5 ┆ 11 │ + └─────┴─────┘ + >>> lframe = lf.head(2).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (2, 2) + ┌─────┬─────┐ + │ a ┆ b │ + │ --- ┆ --- │ + │ i64 ┆ i64 │ + ╞═════╪═════╡ + │ 1 ┆ 7 │ + │ 2 ┆ 8 │ + └─────┴─────┘ + """ return super().head(n) def drop(self, *columns: str | Iterable[str]) -> Self: + r""" + Remove columns from the LazyFrame. + + Arguments: + *columns: Names of the columns that should be removed from the + dataframe. Accepts column selector input. + + Examples: + Drop a single column by passing the name of that column. + + >>> import polars as pl + >>> import narwhals as nw + >>> lf_pl = pl.LazyFrame( + ... { + ... "foo": [1, 2, 3], + ... "bar": [6.0, 7.0, 8.0], + ... "ham": ["a", "b", "c"], + ... } + ... ) + >>> lf = nw.LazyFrame(lf_pl) + >>> lframe = lf.drop("ham").collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (3, 2) + ┌─────┬─────┐ + │ foo ┆ bar │ + │ --- ┆ --- │ + │ i64 ┆ f64 │ + ╞═════╪═════╡ + │ 1 ┆ 6.0 │ + │ 2 ┆ 7.0 │ + │ 3 ┆ 8.0 │ + └─────┴─────┘ + + Drop multiple columns by passing a selector. + + >>> import polars.selectors as cs + >>> lframe = lf.drop(cs.numeric()).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (3, 1) + ┌─────┐ + │ ham │ + │ --- │ + │ str │ + ╞═════╡ + │ a │ + │ b │ + │ c │ + └─────┘ + + Use positional arguments to drop multiple columns. + + >>> lframe = lf.drop("foo", "ham").collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (3, 1) + ┌─────┐ + │ bar │ + │ --- │ + │ f64 │ + ╞═════╡ + │ 6.0 │ + │ 7.0 │ + │ 8.0 │ + └─────┘ + """ return super().drop(*columns) def unique(self, subset: str | list[str]) -> Self: From c53fdfedc2134e59d4a5b30a27d540150dd3993f Mon Sep 17 00:00:00 2001 From: Franco Masotti Date: Thu, 4 Apr 2024 18:42:22 +0200 Subject: [PATCH 4/6] Add docstrings - Add `narwhals.dataframe.LazyFrame.{unique,filter}` docstrings --- narwhals/dataframe.py | 151 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 836f15804..16e1c0de5 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -1316,9 +1316,160 @@ def drop(self, *columns: str | Iterable[str]) -> Self: return super().drop(*columns) def unique(self, subset: str | list[str]) -> Self: + """ + Drop duplicate rows from this LazyFrame. + + Arguments: + subset: Column name(s) to consider when identifying duplicate rows. + If set to `None`, use all columns. + + Returns: + LazyFrame: LazyFrame with unique rows. + + Examples: + >>> import polars as pl + >>> import narwhals as nw + >>> lf_pl = pl.LazyFrame( + ... { + ... "foo": [1, 2, 3, 1], + ... "bar": ["a", "a", "a", "a"], + ... "ham": ["b", "b", "b", "b"], + ... } + ... ) + >>> lf = nw.LazyFrame(lf_pl) + >>> lframe = lf.unique(None).collect().sort("foo") + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (3, 3) + ┌─────┬─────┬─────┐ + │ foo ┆ bar ┆ ham │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ str ┆ str │ + ╞═════╪═════╪═════╡ + │ 1 ┆ a ┆ b │ + │ 2 ┆ a ┆ b │ + │ 3 ┆ a ┆ b │ + └─────┴─────┴─────┘ + >>> lframe = lf.unique(subset=["bar", "ham"]).collect().sort("foo") + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (1, 3) + ┌─────┬─────┬─────┐ + │ foo ┆ bar ┆ ham │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ str ┆ str │ + ╞═════╪═════╪═════╡ + │ 1 ┆ a ┆ b │ + └─────┴─────┴─────┘ + """ return super().unique(subset) def filter(self, *predicates: IntoExpr | Iterable[IntoExpr]) -> Self: + r""" + Filter the rows in the LazyFrame based on a predicate expression. + + The original order of the remaining rows is preserved. + + Arguments: + *predicates: Expression that evaluates to a boolean Series. + + Examples: + >>> import polars as pl + >>> import narwhals as nw + >>> lf_pl = pl.LazyFrame( + ... { + ... "foo": [1, 2, 3], + ... "bar": [6, 7, 8], + ... "ham": ["a", "b", "c"], + ... } + ... ) + + Filter on one condition: + + >>> lf = nw.LazyFrame(lf_pl) + >>> lframe = lf.filter(nw.col("foo") > 1).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (2, 3) + ┌─────┬─────┬─────┐ + │ foo ┆ bar ┆ ham │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ i64 ┆ str │ + ╞═════╪═════╪═════╡ + │ 2 ┆ 7 ┆ b │ + │ 3 ┆ 8 ┆ c │ + └─────┴─────┴─────┘ + + Filter on multiple conditions: + + >>> lframe = lf.filter((nw.col("foo") < 3) & (nw.col("ham") == "a")).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (1, 3) + ┌─────┬─────┬─────┐ + │ foo ┆ bar ┆ ham │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ i64 ┆ str │ + ╞═════╪═════╪═════╡ + │ 1 ┆ 6 ┆ a │ + └─────┴─────┴─────┘ + + Provide multiple filters using `*args` syntax: + + >>> lframe = lf.filter( + ... nw.col("foo") == 1, + ... nw.col("ham") == "a", + ... ).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (1, 3) + ┌─────┬─────┬─────┐ + │ foo ┆ bar ┆ ham │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ i64 ┆ str │ + ╞═════╪═════╪═════╡ + │ 1 ┆ 6 ┆ a │ + └─────┴─────┴─────┘ + + Filter on an OR condition: + + >>> lframe = lf.filter((nw.col("foo") == 1) | (nw.col("ham") == "c")).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (2, 3) + ┌─────┬─────┬─────┐ + │ foo ┆ bar ┆ ham │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ i64 ┆ str │ + ╞═════╪═════╪═════╡ + │ 1 ┆ 6 ┆ a │ + │ 3 ┆ 8 ┆ c │ + └─────┴─────┴─────┘ + """ return super().filter(*predicates) def group_by(self, *keys: str | Iterable[str]) -> LazyGroupBy: From f7ca4d82c322c37921e56140b741b3196d17c614 Mon Sep 17 00:00:00 2001 From: Franco Masotti Date: Thu, 4 Apr 2024 19:28:47 +0200 Subject: [PATCH 5/6] Add docstrings - Add `narwhals.dataframe.LazyFrame.{group_by,sort,join}` docstrings --- narwhals/dataframe.py | 200 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 16e1c0de5..ddcab6ab9 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -1473,6 +1473,67 @@ def filter(self, *predicates: IntoExpr | Iterable[IntoExpr]) -> Self: return super().filter(*predicates) def group_by(self, *keys: str | Iterable[str]) -> LazyGroupBy: + r""" + Start a group by operation. + + Arguments: + *keys: + Column(s) to group by. Accepts expression input. Strings are + parsed as column names. + + Examples: + Group by one column and call `agg` to compute the grouped sum of + another column. + + >>> import polars as pl + >>> import narwhals as nw + >>> lf_pl = pl.LazyFrame( + ... { + ... "a": ["a", "b", "a", "b", "c"], + ... "b": [1, 2, 1, 3, 3], + ... "c": [5, 4, 3, 2, 1], + ... } + ... ) + >>> lf = nw.LazyFrame(lf_pl) + >>> lframe = lf.group_by("a").agg(nw.col("b").sum()).collect().sort("a") + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (3, 2) + ┌─────┬─────┐ + │ a ┆ b │ + │ --- ┆ --- │ + │ str ┆ i64 │ + ╞═════╪═════╡ + │ a ┆ 2 │ + │ b ┆ 5 │ + │ c ┆ 3 │ + └─────┴─────┘ + + Group by multiple columns by passing a list of column names. + + >>> lframe = lf.group_by(["a", "b"]).agg(nw.max("c")).collect().sort(["a", "b"]) + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (4, 3) + ┌─────┬─────┬─────┐ + │ a ┆ b ┆ c │ + │ --- ┆ --- ┆ --- │ + │ str ┆ i64 ┆ i64 │ + ╞═════╪═════╪═════╡ + │ a ┆ 1 ┆ 5 │ + │ b ┆ 2 ┆ 4 │ + │ b ┆ 3 ┆ 2 │ + │ c ┆ 3 ┆ 1 │ + └─────┴─────┴─────┘ + """ from narwhals.group_by import LazyGroupBy return LazyGroupBy(self, *keys) @@ -1483,6 +1544,91 @@ def sort( *more_by: str, descending: bool | Sequence[bool] = False, ) -> Self: + r""" + Sort the LazyFrame by the given columns. + + Arguments: + by: Column(s) to sort by. Accepts expression input. Strings are + parsed as column names. + + *more_by: Additional columns to sort by, specified as positional + arguments. + + descending: Sort in descending order. When sorting by multiple + columns, can be specified per column by passing a + sequence of booleans. + + Examples: + Pass a single column name to sort by that column. + + >>> import polars as pl + >>> import narwhals as nw + >>> lf_pl = pl.LazyFrame( + ... { + ... "a": [1, 2, None], + ... "b": [6.0, 5.0, 4.0], + ... "c": ["a", "c", "b"], + ... } + ... ) + >>> lf = nw.LazyFrame(lf_pl) + >>> lframe = lf.sort("a").collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (3, 3) + ┌──────┬─────┬─────┐ + │ a ┆ b ┆ c │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ f64 ┆ str │ + ╞══════╪═════╪═════╡ + │ null ┆ 4.0 ┆ b │ + │ 1 ┆ 6.0 ┆ a │ + │ 2 ┆ 5.0 ┆ c │ + └──────┴─────┴─────┘ + + Sort by multiple columns by passing a list of columns. + + >>> lframe = lf.sort(["c", "a"], descending=True).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (3, 3) + ┌──────┬─────┬─────┐ + │ a ┆ b ┆ c │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ f64 ┆ str │ + ╞══════╪═════╪═════╡ + │ 2 ┆ 5.0 ┆ c │ + │ null ┆ 4.0 ┆ b │ + │ 1 ┆ 6.0 ┆ a │ + └──────┴─────┴─────┘ + + Or use positional arguments to sort by multiple columns in the same way. + + >>> lframe = lf.sort("c", "a", descending=[False, True]).collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (3, 3) + ┌──────┬─────┬─────┐ + │ a ┆ b ┆ c │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ f64 ┆ str │ + ╞══════╪═════╪═════╡ + │ 1 ┆ 6.0 ┆ a │ + │ null ┆ 4.0 ┆ b │ + │ 2 ┆ 5.0 ┆ c │ + └──────┴─────┴─────┘ + """ return super().sort(by, *more_by, descending=descending) def join( @@ -1493,4 +1639,58 @@ def join( left_on: str | list[str], right_on: str | list[str], ) -> Self: + r""" + Add a join operation to the Logical Plan. + + Arguments: + other: Lazy DataFrame to join with. + + how: {'inner'} + Join strategy. + + * *inner*: Returns rows that have matching values in both + tables + + left_on: Join column of the left DataFrame. + + right_on: Join column of the right DataFrame. + + Returns: + A new joined LazyFrame + + Examples: + >>> import polars as pl + >>> import narwhals as nw + >>> lf_pl = pl.LazyFrame( + ... { + ... "foo": [1, 2, 3], + ... "bar": [6.0, 7.0, 8.0], + ... "ham": ["a", "b", "c"], + ... } + ... ) + >>> other_lf_pl = pl.LazyFrame( + ... { + ... "apple": ["x", "y", "z"], + ... "ham": ["a", "b", "d"], + ... } + ... ) + >>> lf = nw.LazyFrame(lf_pl) + >>> other_lf = nw.LazyFrame(other_lf_pl) + >>> lframe = lf.join(other_lf, left_on="ham", right_on="ham").collect() + >>> lframe + ┌─────────────────────────────────────────────────┐ + | Narwhals DataFrame | + | Use `narwhals.to_native()` to see native output | + └─────────────────────────────────────────────────┘ + >>> nw.to_native(lframe) + shape: (2, 4) + ┌─────┬─────┬─────┬───────┐ + │ foo ┆ bar ┆ ham ┆ apple │ + │ --- ┆ --- ┆ --- ┆ --- │ + │ i64 ┆ f64 ┆ str ┆ str │ + ╞═════╪═════╪═════╪═══════╡ + │ 1 ┆ 6.0 ┆ a ┆ x │ + │ 2 ┆ 7.0 ┆ b ┆ y │ + └─────┴─────┴─────┴───────┘ + """ return super().join(other, how=how, left_on=left_on, right_on=right_on) From 41a53ab9a82b08da1281ec2ce2f9478611e66a16 Mon Sep 17 00:00:00 2001 From: Franco Masotti Date: Tue, 9 Apr 2024 17:07:46 +0200 Subject: [PATCH 6/6] Cleanup - Cleanup unsupported and unimplemented stuff --- narwhals/dataframe.py | 44 ------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index ddcab6ab9..0196e2b39 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -1152,23 +1152,6 @@ def rename(self, mapping: dict[str, str]) -> Self: │ 2 ┆ 7 ┆ b │ │ 3 ┆ 8 ┆ c │ └───────┴─────┴─────┘ - >>> lframe = lf.rename(lambda column_name: "c" + column_name[1:]).collect() - >>> lframe - ┌─────────────────────────────────────────────────┐ - | Narwhals DataFrame | - | Use `narwhals.to_native()` to see native output | - └─────────────────────────────────────────────────┘ - >>> nw.to_native(lframe) - shape: (3, 3) - ┌─────┬─────┬─────┐ - │ coo ┆ car ┆ cam │ - │ --- ┆ --- ┆ --- │ - │ i64 ┆ i64 ┆ str │ - ╞═════╪═════╪═════╡ - │ 1 ┆ 6 ┆ a │ - │ 2 ┆ 7 ┆ b │ - │ 3 ┆ 8 ┆ c │ - └─────┴─────┴─────┘ """ return super().rename(mapping) @@ -1179,12 +1162,6 @@ def head(self, n: int) -> Self: Arguments: n: Number of rows to return. - Notes: - Consider using the `fetch` operation if you only want to test - your query. The `fetch` operation will load the first `n` - rows at the scan level, whereas the `head`/`limit` are - applied at the end. - Examples: >>> import polars as pl >>> import narwhals as nw @@ -1272,27 +1249,6 @@ def drop(self, *columns: str | Iterable[str]) -> Self: │ 3 ┆ 8.0 │ └─────┴─────┘ - Drop multiple columns by passing a selector. - - >>> import polars.selectors as cs - >>> lframe = lf.drop(cs.numeric()).collect() - >>> lframe - ┌─────────────────────────────────────────────────┐ - | Narwhals DataFrame | - | Use `narwhals.to_native()` to see native output | - └─────────────────────────────────────────────────┘ - >>> nw.to_native(lframe) - shape: (3, 1) - ┌─────┐ - │ ham │ - │ --- │ - │ str │ - ╞═════╡ - │ a │ - │ b │ - │ c │ - └─────┘ - Use positional arguments to drop multiple columns. >>> lframe = lf.drop("foo", "ham").collect()