Polars supports the following file formats when reading from Hugging Face:
The examples below show the default settings only. There are various parameters which you can use depending on your use case. View the API reference guide for more information: Parquet, CSV, JSON
Parquet is the preferred file format as it stores the schema with type information within the file. This avoids any ambiguity with parsing and speeds up reading. To read a parquet file in Polars do the following
pl.read_parquet("hf://datasets/roneneldan/TinyStories/data/train-00000-of-00004-2d5a1467fff1081b.parquet")
In order to read in a CSV file you can use the scan_csv
method:
pl.read_csv("hf://datasets/lhoestq/demo1/data/train.csv")
Polars supports reading in new line delimited JSON also known as json lines with the read_ndjson
method:
pl.read_ndjson("hf://datasets/proj-persona/PersonaHub/persona.jsonl")