dataframe-core-2.2.0.0: Core data structures for the dataframe library.
LicenseMIT
Safe HaskellNone
LanguageHaskell2010

DataFrame.Typed.Record

Description

Bridge a Haskell record type to a typed dataframe schema. Instances are typically generated by the deriveSchemaFromType Template Haskell splice (see DataFrame.Typed.TH), but can be written by hand as well, or plugged into the Generic-derived defaults from DataFrame.Typed.Generic.

Synopsis

Class

class HasSchema a where Source #

Bridge a Haskell record type a to a typed-dataframe schema.

The schema is exposed as an associated type family Schema so that instances can pick it up from a Rep computation (see SchemaOf) or from an explicit list emitted by deriveSchemaFromType.

toColumns explodes a list of records into a list of named columns. fromColumns reconstructs the records from a DataFrame, returning Left err if a column is missing or has the wrong type.

Associated Types

type Schema a :: [(Symbol, Type)] Source #

Untyped helpers

fromRecords :: HasSchema a => [a] -> DataFrame Source #

Build an untyped DataFrame from a list of records.

data Order = Order { orderId :: Int64, region :: Text, amount :: Double }
$(deriveSchemaFromType ''Order)

xs :: [Order]
xs = [Order 1 "us" 10.0, Order 2 "eu" 20.0]

df :: DataFrame
df = fromRecords xs

toRecords :: HasSchema a => DataFrame -> Either Text [a] Source #

Parse a list of records out of an untyped DataFrame.

Returns Left err on schema mismatch (missing column, wrong type).

Typed helpers

fromRecordsTyped :: HasSchema a => [a] -> TypedDataFrame (Schema a) Source #

Like fromRecords but returns a TypedDataFrame tagged with the schema.

Helpers used by generated code

requireColumn :: Columnable a => Text -> DataFrame -> Either Text (Vector a) Source #

Extract a column as a boxed vector by name, returning a Text error on missing column or type mismatch.

Used by code generated by deriveSchemaFromType.