Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type BufferSize = Int
- data NamedColumns
- data CsvDatastream' batches (named :: NamedColumns) = CsvDatastream' {}
- type CsvDatastream batches = CsvDatastream' batches Unnamed
- type CsvDatastreamNamed batches = CsvDatastream' batches Named
- csvDatastream :: forall (isNamed :: NamedColumns) batches. FilePath -> CsvDatastream' batches isNamed
- tsvDatastream :: forall (isNamed :: NamedColumns) batches. FilePath -> CsvDatastream' batches isNamed
- class FromField a where
- parseField :: Field -> Parser a
- class FromRecord a where
- parseRecord :: Record -> Parser a
- class FromNamedRecord a where
- parseNamedRecord :: NamedRecord -> Parser a
Documentation
type BufferSize = Int Source #
data NamedColumns Source #
data CsvDatastream' batches (named :: NamedColumns) Source #
A CSV datastream. The datastream instance of this type streams
samples of batches
from a CSV file at the specified file path. Batches
are yielded in constant memory, but if shuffling is enabled, then there
will be at most
records stored in memory.BufferSize
CsvDatastream' | |
|
Instances
(MonadBaseControl IO m, MonadSafe m, FromRecord batch) => Datastream m () (CsvDatastream batch) (Vector batch) Source # | |
Defined in Torch.Data.CsvDatastream streamSamples :: CsvDatastream batch -> () -> ListT m (Vector batch) Source # | |
(MonadBaseControl IO m, MonadSafe m, FromNamedRecord batch) => Datastream m () (CsvDatastreamNamed batch) (Vector batch) Source # | |
Defined in Torch.Data.CsvDatastream streamSamples :: CsvDatastreamNamed batch -> () -> ListT m (Vector batch) Source # |
type CsvDatastream batches = CsvDatastream' batches Unnamed Source #
A specialized version of CsvDatastream'. Use this type if you want to decode a CSV file with records defined by the order of the columns.
type CsvDatastreamNamed batches = CsvDatastream' batches Named Source #
A specialized version of CsvDatastream'. Use this type if you want to decode
a CSV file with records that have
instance. This decodes each field
of the record by the corresponding column with the given header name.FromNamedRecord
csvDatastream :: forall (isNamed :: NamedColumns) batches. FilePath -> CsvDatastream' batches isNamed Source #
Produce a CsvDatastream' from the given file with default options, and comma separated columns.
tsvDatastream :: forall (isNamed :: NamedColumns) batches. FilePath -> CsvDatastream' batches isNamed Source #
Produce a CsvDatastream' from the given file with default options, and tab separated columns.
Reexports
class FromField a where Source #
A type that can be converted from a single CSV field, with the possibility of failure.
When writing an instance, use empty
, mzero
, or fail
to make a
conversion fail, e.g. if a Field
can't be converted to the given
type.
Example type and instance:
{-# LANGUAGE OverloadedStrings #-} data Color = Red | Green | Blue instance FromField Color where parseField s | s == "R" = pure Red | s == "G" = pure Green | s == "B" = pure Blue | otherwise = mzero
parseField :: Field -> Parser a Source #
Instances
FromField Int16 | Accepts a signed decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField Int32 | Accepts a signed decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField Int64 | Accepts a signed decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField Int8 | Accepts a signed decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField Word16 | Accepts an unsigned decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField Word32 | Accepts an unsigned decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField Word64 | Accepts an unsigned decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField Word8 | Accepts an unsigned decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField ByteString | |
Defined in Data.Csv.Conversion parseField :: Field -> Parser ByteString Source # | |
FromField ByteString | |
Defined in Data.Csv.Conversion parseField :: Field -> Parser ByteString Source # | |
FromField ShortByteString | |
Defined in Data.Csv.Conversion parseField :: Field -> Parser ShortByteString Source # | |
FromField Scientific | Accepts the same syntax as Since: cassava-0.5.1.0 |
Defined in Data.Csv.Conversion parseField :: Field -> Parser Scientific Source # | |
FromField Text | Assumes UTF-8 encoding. Fails on invalid byte sequences. |
Defined in Data.Csv.Conversion | |
FromField Text | Assumes UTF-8 encoding. Fails on invalid byte sequences. |
Defined in Data.Csv.Conversion | |
FromField ShortText | Assumes UTF-8 encoding. Fails on invalid byte sequences. Since: cassava-0.5.0.0 |
Defined in Data.Csv.Conversion | |
FromField Integer | Accepts a signed decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField Natural | Accepts an unsigned decimal number. Ignores whitespace. Since: cassava-0.5.1.0 |
Defined in Data.Csv.Conversion | |
FromField () | Ignores the |
Defined in Data.Csv.Conversion parseField :: Field -> Parser () Source # | |
FromField Char | Assumes UTF-8 encoding. |
Defined in Data.Csv.Conversion | |
FromField Double | Accepts same syntax as |
Defined in Data.Csv.Conversion | |
FromField Float | Accepts same syntax as |
Defined in Data.Csv.Conversion | |
FromField Int | Accepts a signed decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField Word | Accepts an unsigned decimal number. Ignores whitespace. |
Defined in Data.Csv.Conversion | |
FromField a => FromField (Identity a) | Since: cassava-0.5.2.0 |
Defined in Data.Csv.Conversion | |
FromField a => FromField (Maybe a) | |
Defined in Data.Csv.Conversion | |
FromField [Char] | Assumes UTF-8 encoding. Fails on invalid byte sequences. |
Defined in Data.Csv.Conversion | |
FromField a => FromField (Either Field a) | |
Defined in Data.Csv.Conversion | |
FromField a => FromField (Const a b) | Since: cassava-0.5.2.0 |
Defined in Data.Csv.Conversion |
class FromRecord a where Source #
A type that can be converted from a single CSV record, with the possibility of failure.
When writing an instance, use empty
, mzero
, or fail
to make a
conversion fail, e.g. if a Record
has the wrong number of
columns.
Given this example data:
John,56 Jane,55
here's an example type and instance:
data Person = Person { name :: !Text, age :: !Int } instance FromRecord Person where parseRecord v | length v == 2 = Person <$> v .! 0 <*> v .! 1 | otherwise = mzero
Nothing
parseRecord :: Record -> Parser a Source #
Instances
class FromNamedRecord a where Source #
A type that can be converted from a single CSV record, with the possibility of failure.
When writing an instance, use empty
, mzero
, or fail
to make a
conversion fail, e.g. if a Record
has the wrong number of
columns.
Given this example data:
name,age John,56 Jane,55
here's an example type and instance:
{-# LANGUAGE OverloadedStrings #-} data Person = Person { name :: !Text, age :: !Int } instance FromNamedRecord Person where parseNamedRecord m = Person <$> m .: "name" <*> m .: "age"
Note the use of the OverloadedStrings
language extension which
enables ByteString
values to be written as string literals.
Nothing
parseNamedRecord :: NamedRecord -> Parser a Source #
Instances
(FromField a, FromField b, Ord a) => FromNamedRecord (Map a b) | |
Defined in Data.Csv.Conversion parseNamedRecord :: NamedRecord -> Parser (Map a b) Source # | |
(Eq a, FromField a, FromField b, Hashable a) => FromNamedRecord (HashMap a b) | |
Defined in Data.Csv.Conversion parseNamedRecord :: NamedRecord -> Parser (HashMap a b) Source # |