Skip to content

Commit

Permalink
docs(python): Doc example for read_csv (pola-rs#13161)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcNuebel authored Jan 8, 2024
1 parent 67507ff commit 972cfeb
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions py-polars/polars/io/csv/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 972cfeb

Please sign in to comment.