File tree Expand file tree Collapse file tree 1 file changed +5
-9
lines changed
Expand file tree Collapse file tree 1 file changed +5
-9
lines changed Original file line number Diff line number Diff line change @@ -55,16 +55,12 @@ less than 10 characters. We can't directly use the `~~Validate.col_vals_lt()` va
5555that column because it is meant to be used with a column of numeric values. Let's just give that
5656method what it needs and create a column with string lengths!
5757
58- The target table is a Polars DataFrame so we'll provide a function that uses the Polars API to add
59- in that numeric column:
58+ The target table is a Polars DataFrame so we'll provide a lambda function that uses the Polars API
59+ to add in that numeric column:
6060
6161``` {python}
6262import polars as pl
6363
64- # Define a preprocessing function that gets string lengths from column `b`
65- def add_string_length_column(df):
66- return df.with_columns(string_lengths=pl.col("b").str.len_chars())
67-
6864(
6965 pb.Validate(
7066 data=pb.load_dataset(dataset="small_table", tbl_type="polars"),
@@ -79,8 +75,8 @@ def add_string_length_column(df):
7975 # The string length value to be less than ---
8076 value=10,
8177
82- # The preprocessing function that modifies the table ---
83- pre=add_string_length_column
78+ # Polars expression that modifies the table ---
79+ pre=lambda df: df.with_columns(string_lengths=pl.col("b").str.len_chars())
8480 )
8581 .interrogate()
8682)
@@ -213,7 +209,7 @@ def get_median_columns_c_and_a(df):
213209 columns="c",
214210 value=pb.col("a"),
215211
216- # Using Narwhals to modify the table; generates table with columns `c` and `a` ---
212+ # Custom function to modify the table; generates table with columns `c` and `a` ---
217213 pre=get_median_columns_c_and_a
218214 )
219215 .interrogate()
You can’t perform that action at this time.
0 commit comments