From 972cfebdb4fcda80410c770387eccdb313142af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20N=C3=BCbel?= <81705410+MarcNuebel@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:20:41 +0100 Subject: [PATCH 1/2] docs(python): Doc example for `read_csv` (#13161) --- py-polars/polars/io/csv/functions.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/py-polars/polars/io/csv/functions.py b/py-polars/polars/io/csv/functions.py index 105ddbc8f742..b9bff013e476 100644 --- a/py-polars/polars/io/csv/functions.py +++ b/py-polars/polars/io/csv/functions.py @@ -186,6 +186,33 @@ def read_csv( all data will be stored continuously in memory. Set `rechunk=False` if you are benchmarking the csv-reader. A `rechunk` is an expensive operation. + + Examples + -------- + >>> pl.read_csv("data.csv", separator="|") # doctest: +SKIP + + Reproducable example using BytesIO object, parsing dates. + + >>> import io # doctest: +SKIP + >>> source = io.BytesIO( + ... ( + ... "ID,Name,Birthday\n" + ... "1,Alice,1995-07-12\n" + ... "2,Bob,1990-09-20\n" + ... "3,Charlie,2002-03-08" + ... ).encode() + ... ) # doctest: +SKIP + >>> pl.read_csv(source, try_parse_dates=True) # doctest: +SKIP + shape: (3, 3) + ┌─────┬─────────┬────────────┐ + │ ID ┆ Name ┆ Birthday │ + │ --- ┆ --- ┆ --- │ + │ i64 ┆ str ┆ date │ + ╞═════╪═════════╪════════════╡ + │ 1 ┆ Alice ┆ 1995-07-12 │ + │ 2 ┆ Bob ┆ 1990-09-20 │ + │ 3 ┆ Charlie ┆ 2002-03-08 │ + └─────┴─────────┴────────────┘ """ _check_arg_is_1byte("separator", separator, can_be_empty=False) _check_arg_is_1byte("quote_char", quote_char, can_be_empty=True) From 3137a64bc92bd6c65bd0b0d3445b63cc1809a22d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20N=C3=BCbel?= <81705410+MarcNuebel@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:28:07 +0100 Subject: [PATCH 2/2] Fixed typo --- py-polars/polars/io/csv/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py-polars/polars/io/csv/functions.py b/py-polars/polars/io/csv/functions.py index b9bff013e476..849956bed3a3 100644 --- a/py-polars/polars/io/csv/functions.py +++ b/py-polars/polars/io/csv/functions.py @@ -191,7 +191,7 @@ def read_csv( -------- >>> pl.read_csv("data.csv", separator="|") # doctest: +SKIP - Reproducable example using BytesIO object, parsing dates. + Reproducible example using BytesIO object, parsing dates. >>> import io # doctest: +SKIP >>> source = io.BytesIO(