Skip to content

Commit

Permalink
Strip white space from string when parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mchav committed Jan 18, 2025
1 parent a9986b6 commit 8d2f64d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Data/DataFrame/IO/CSV.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ readSeparated :: Char -> ReadOptions -> String -> IO DataFrame
readSeparated c opts path = do
totalRows <- countRows path
withFile path ReadMode $ \handle -> do
firstRow <- map decodeUtf8Lenient . parseSep c <$> C.hGetLine handle
firstRow <- map (decodeUtf8Lenient . C.strip) . parseSep c <$> C.hGetLine handle
let columnNames = if hasHeader opts
then map (T.filter (/= '\"')) firstRow
else map (T.singleton . intToDigit) [0..(length firstRow - 1)]
Expand All @@ -78,7 +78,7 @@ readSeparated c opts path = do

-- Initialize mutable vectors for each column
let numColumns = length columnNames
dataRow <- map decodeUtf8Lenient . parseSep c <$> C.hGetLine handle
dataRow <- map (decodeUtf8Lenient . C.strip) . parseSep c <$> C.hGetLine handle
let actualRows = if hasHeader opts then totalRows - 1 else totalRows
nullIndices <- VM.unsafeNew numColumns
VM.set nullIndices []
Expand Down
2 changes: 1 addition & 1 deletion src/Data/DataFrame/Internal/Column.hs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ zipColumns (UnboxedColumn column) (UnboxedColumn other) = UnboxedColumn (VU.gene
-- Clean this up.
writeColumn :: Int -> C.ByteString -> Column -> IO (Either T.Text Bool)
writeColumn i value' (MutableBoxedColumn (col :: VBM.IOVector a)) = let
value = decodeUtf8Lenient value'
value = (decodeUtf8Lenient . C.strip) value'
in case testEquality (typeRep @a) (typeRep @T.Text) of
Just Refl -> (if isNullish value
then VBM.unsafeWrite col i "" >> return (Left value)
Expand Down

0 comments on commit 8d2f64d

Please sign in to comment.