| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
DataFrame.Typed.IO.CSV
Description
Typed CSV reading.
The schema is the whole specification of the read: it names the columns to
fetch and gives their types, so these readers touch only the columns cols
declares and never infer a type the schema already knows.
type Customer = '[ '("customer_id", Int), '("customer_name", Text)]
customers <- readCsv @Customer "customers.csv" -- reads 2 columns, whatever
-- else the file holds
Synopsis
- readCsv :: forall (cols :: [(Symbol, Type)]). (KnownSchema cols, RuntimeSchema cols) => FilePath -> IO (TypedDataFrame cols)
- readCsvWithError :: forall (cols :: [(Symbol, Type)]). (KnownSchema cols, RuntimeSchema cols) => FilePath -> IO (Either Text (TypedDataFrame cols))
- readTsv :: forall (cols :: [(Symbol, Type)]). (KnownSchema cols, RuntimeSchema cols) => FilePath -> IO (TypedDataFrame cols)
- readCsvWithOpts :: forall (cols :: [(Symbol, Type)]). (KnownSchema cols, RuntimeSchema cols) => ReadOptions -> FilePath -> IO (TypedDataFrame cols)
- writeCsv :: forall (cols :: [(Symbol, Type)]). FilePath -> TypedDataFrame cols -> IO ()
- writeTsv :: forall (cols :: [(Symbol, Type)]). FilePath -> TypedDataFrame cols -> IO ()
Documentation
readCsv :: forall (cols :: [(Symbol, Type)]). (KnownSchema cols, RuntimeSchema cols) => FilePath -> IO (TypedDataFrame cols) Source #
Read a CSV file into a typed DataFrame, throwing on schema mismatch.
Reads only the columns cols names, typed as cols says.
Example
ghci> type Customer = '[ '("id", Int), '("name", Text)]
ghci> customers <- readCsv @Customer "customers.csv"
readCsvWithError :: forall (cols :: [(Symbol, Type)]). (KnownSchema cols, RuntimeSchema cols) => FilePath -> IO (Either Text (TypedDataFrame cols)) Source #
Read a CSV file, returning a descriptive error on schema mismatch or a missing column instead of throwing.
Example
ghci> readCsvWithError @Customer "customers.csv" Right (TDF ...)
readTsv :: forall (cols :: [(Symbol, Type)]). (KnownSchema cols, RuntimeSchema cols) => FilePath -> IO (TypedDataFrame cols) Source #
Read a tab-separated file into a typed DataFrame, throwing on mismatch.
Example
ghci> customers <- readTsv @Customer "customers.tsv"
readCsvWithOpts :: forall (cols :: [(Symbol, Type)]). (KnownSchema cols, RuntimeSchema cols) => ReadOptions -> FilePath -> IO (TypedDataFrame cols) Source #
Read a CSV file with custom options, throwing on schema mismatch. The
schema still supplies the column selection and types; an explicit
readColumns takes precedence, and is then checked by the freeze.
Example
ghci> customers <- readCsvWithOpts @Customer defaultReadOptions{safeRead = MaybeRead} "customers.csv"