Skip to content

Commit 45344f2

Browse files
authored
fix writeCsv for OptionalColumn (#134)
`writeCsv` was outputting optional (non-Text) values as text including Just/Nothing in the file. You can see this behaviour doing a read/write/read cycle.
1 parent 528d6e3 commit 45344f2

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/DataFrame/IO/CSV.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,9 @@ getRowAsText df i = V.ifoldr go [] (columns df)
428428
++ "the other columns at index "
429429
++ show i
430430
go k (OptionalColumn (c :: V.Vector (Maybe a))) acc = case c V.!? i of
431-
Just e -> textRep : acc
432-
where
433-
textRep = case testEquality (typeRep @a) (typeRep @T.Text) of
434-
Just Refl -> fromMaybe "Nothing" e
435-
Nothing -> (T.pack . show) e
431+
Just e -> case testEquality (typeRep @a) (typeRep @T.Text) of
432+
Just Refl -> fromMaybe T.empty e : acc
433+
Nothing -> maybe T.empty (T.pack . show) e : acc
436434
Nothing ->
437435
error $
438436
"Column "

src/DataFrame/Lazy/IO/CSV.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,9 @@ getRowAsText df i = V.ifoldr go [] (columns df)
383383
++ "the other columns at index "
384384
++ show i
385385
go k (OptionalColumn (c :: V.Vector (Maybe a))) acc = case c V.!? i of
386-
Just e -> textRep : acc
387-
where
388-
textRep = case testEquality (typeRep @a) (typeRep @T.Text) of
389-
Just Refl -> fromMaybe "Nothing" e
390-
Nothing -> (T.pack . show) e
386+
Just e -> case testEquality (typeRep @a) (typeRep @T.Text) of
387+
Just Refl -> fromMaybe T.empty e : acc
388+
Nothing -> maybe T.empty (T.pack . show) e : acc
391389
Nothing ->
392390
error $
393391
"Column "

0 commit comments

Comments
 (0)