haskell-hvr / cassava

A CSV parsing and encoding library optimized for ease of use and high performance
http://hackage.haskell.org/package/cassava
BSD 3-Clause "New" or "Revised" License
222 stars 105 forks source link

Reading NaNs #188

Open idontgetoutmuch opened 3 years ago

idontgetoutmuch commented 3 years ago

I have a file with NaNs and Haskell should cope with NaNs: Prelude.read "NaN" :: Double

But if I use cassava then I get errors

Left "parse error (Failed reading: conversion error: expected Double, got \"NaN\" (Failed reading: takeWhile1)) at \n-20.885,-21.039,3.0853,NaN,4,5\n-20.885,-18.039,3.0853,NaN,4,5\n-20.885,-15.039,3.0853,NaN,4,5\n-20.88 (truncated)"

So I have this

newtype LaxDouble = LaxDouble { laxDouble :: Double }
  deriving Show
instance FromField LaxDouble where
  parseField s = do
    f <- parseField s
    return $ LaxDouble $ Prelude.read f

IMHO reading NaNs should just work(TM)

idontgetoutmuch commented 3 years ago

Apparently a result of using attoparsec - should this be reported there or should we fix the problem here?