From eb2ccb0467c7476ddb29bab42b3f63989e6faa22 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Sun, 17 Mar 2024 09:50:05 +0000 Subject: [PATCH] update docs --- docs/basics/complete_example.md | 14 ++++++-------- t.py | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/basics/complete_example.md b/docs/basics/complete_example.md index 15de45a03..141e6b1b2 100644 --- a/docs/basics/complete_example.md +++ b/docs/basics/complete_example.md @@ -44,17 +44,15 @@ call `.collect()` on the result if they want to materialise its values. Unlike the `transform` method, `fit` cannot stay lazy, as we need to compute concrete values for the means and standard deviations. -To be able to get `Series` out of our `DataFrame`, we'll need the `DataFrame` to be an -eager one, as Polars doesn't have a concept of lazy `Series`. -To do that, when we instantiate our `narwhals.DataFrame`, we pass `features=['eager']`, -which lets us access eager-only features. +To be able to get `Series` out of our `DataFrame`, we'll need to use `narwhals.DataFrame` (as opposed to +`narwhals.LazyFrame`), as Polars doesn't have a concept of lazy `Series`. ```python import narwhals as nw class StandardScalar: def fit(self, df): - df = nw.DataFrame(df, features=['eager']) + df = nw.DataFrame(df) self._means = {df[col].mean() for col in df.columns} self._std_devs = {df[col].std() for col in df.columns} ``` @@ -67,12 +65,12 @@ import narwhals as nw class StandardScaler: def fit(self, df): - df = nw.DataFrame(df, features=["eager"]) + df = nw.DataFrame(df) self._means = {col: df[col].mean() for col in df.columns} self._std_devs = {col: df[col].std() for col in df.columns} def transform(self, df): - df = nw.DataFrame(df) + df = nw.LazyFrame(df) df = df.with_columns( (nw.col(col) - self._means[col]) / self._std_devs[col] for col in df.columns @@ -81,7 +79,7 @@ class StandardScaler: ``` Next, let's try running it. Notice how, as `transform` doesn't use -`features=['lazy']`, we can pass a `polars.LazyFrame` to it without issues! +any eager-only features, so we can make it completely lazy! === "pandas" ```python exec="true" source="material-block" result="python" session="tute-ex1" diff --git a/t.py b/t.py index 138e998e7..7ab0e9efc 100644 --- a/t.py +++ b/t.py @@ -7,9 +7,9 @@ import narwhals as nw df_raw = pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}) -df = nw.DataFrame(df_raw, features=["lazy"]) +df = nw.LazyFrame(df_raw) df_raw_2 = pd.DataFrame({"a": [1, 3], "c": [7, 9]}) -df2 = nw.DataFrame(df_raw_2, features=["lazy"]) +df2 = nw.LazyFrame(df_raw_2) result = df.sort("a", "b") print(nw.to_native(result))