From 5c64817f797c572394e7a32be79f91893d819a65 Mon Sep 17 00:00:00 2001 From: Michael Coady Date: Wed, 21 Jan 2026 02:10:10 +0000 Subject: [PATCH 1/2] fix `writeCsv` for `OptionalColumn` writing `Maybe a` values instead of `a` values --- src/DataFrame/IO/CSV.hs | 6 +----- src/DataFrame/Lazy/IO/CSV.hs | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/DataFrame/IO/CSV.hs b/src/DataFrame/IO/CSV.hs index 1a055d2..5386fbb 100644 --- a/src/DataFrame/IO/CSV.hs +++ b/src/DataFrame/IO/CSV.hs @@ -428,11 +428,7 @@ getRowAsText df i = V.ifoldr go [] (columns df) ++ "the other columns at index " ++ show i go k (OptionalColumn (c :: V.Vector (Maybe a))) acc = case c V.!? i of - Just e -> textRep : acc - where - textRep = case testEquality (typeRep @a) (typeRep @T.Text) of - Just Refl -> fromMaybe "Nothing" e - Nothing -> (T.pack . show) e + Just e -> maybe T.empty T.show e : acc Nothing -> error $ "Column " diff --git a/src/DataFrame/Lazy/IO/CSV.hs b/src/DataFrame/Lazy/IO/CSV.hs index a1bc795..ecaacde 100644 --- a/src/DataFrame/Lazy/IO/CSV.hs +++ b/src/DataFrame/Lazy/IO/CSV.hs @@ -383,11 +383,7 @@ getRowAsText df i = V.ifoldr go [] (columns df) ++ "the other columns at index " ++ show i go k (OptionalColumn (c :: V.Vector (Maybe a))) acc = case c V.!? i of - Just e -> textRep : acc - where - textRep = case testEquality (typeRep @a) (typeRep @T.Text) of - Just Refl -> fromMaybe "Nothing" e - Nothing -> (T.pack . show) e + Just e -> maybe T.empty T.show e : acc Nothing -> error $ "Column " From d0f6b5a3fdb7bd1f412aa3da7f987363ba63a421 Mon Sep 17 00:00:00 2001 From: Michael Coady Date: Wed, 21 Jan 2026 10:50:20 +0000 Subject: [PATCH 2/2] replace use of `Text.show` and handle `OptionalColumn` of `Maybe Text` separately --- src/DataFrame/IO/CSV.hs | 4 +++- src/DataFrame/Lazy/IO/CSV.hs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/DataFrame/IO/CSV.hs b/src/DataFrame/IO/CSV.hs index 5386fbb..450cb3c 100644 --- a/src/DataFrame/IO/CSV.hs +++ b/src/DataFrame/IO/CSV.hs @@ -428,7 +428,9 @@ getRowAsText df i = V.ifoldr go [] (columns df) ++ "the other columns at index " ++ show i go k (OptionalColumn (c :: V.Vector (Maybe a))) acc = case c V.!? i of - Just e -> maybe T.empty T.show e : acc + Just e -> case testEquality (typeRep @a) (typeRep @T.Text) of + Just Refl -> fromMaybe T.empty e : acc + Nothing -> maybe T.empty (T.pack . show) e : acc Nothing -> error $ "Column " diff --git a/src/DataFrame/Lazy/IO/CSV.hs b/src/DataFrame/Lazy/IO/CSV.hs index ecaacde..734e7e3 100644 --- a/src/DataFrame/Lazy/IO/CSV.hs +++ b/src/DataFrame/Lazy/IO/CSV.hs @@ -383,7 +383,9 @@ getRowAsText df i = V.ifoldr go [] (columns df) ++ "the other columns at index " ++ show i go k (OptionalColumn (c :: V.Vector (Maybe a))) acc = case c V.!? i of - Just e -> maybe T.empty T.show e : acc + Just e -> case testEquality (typeRep @a) (typeRep @T.Text) of + Just Refl -> fromMaybe T.empty e : acc + Nothing -> maybe T.empty (T.pack . show) e : acc Nothing -> error $ "Column "