From 32ee17fbd6faf66de1f5a3eac8dcff959e581f75 Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Tue, 4 Jul 2023 10:17:22 +0100 Subject: [PATCH 1/6] Whatever --- src/Frames/ColumnTypeable.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Frames/ColumnTypeable.hs b/src/Frames/ColumnTypeable.hs index 021aa0b..f44eadd 100644 --- a/src/Frames/ColumnTypeable.hs +++ b/src/Frames/ColumnTypeable.hs @@ -78,7 +78,7 @@ instance Parseable Float where instance Parseable Double where -- Some CSV's export Doubles in a format like '1,000.00', filtering -- out commas lets us parse those sucessfully - parse = fmap Definitely . fromText . T.filter (/= ',') + parse = fmap Definitely . fromText -- . T.filter (/= ',') instance Parseable T.Text where -- | This class relates a universe of possible column types to Haskell From 22265f711cc9df8a375503a542fc07f2f3632f52 Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Sun, 9 Jul 2023 09:47:41 +0100 Subject: [PATCH 2/6] MonadFail --- src/Frames/ColumnTypeable.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Frames/ColumnTypeable.hs b/src/Frames/ColumnTypeable.hs index f44eadd..35a60cf 100644 --- a/src/Frames/ColumnTypeable.hs +++ b/src/Frames/ColumnTypeable.hs @@ -27,8 +27,8 @@ class Parseable a where -- returns 'Just Possibly' if a value can be read, but is likely -- ambiguous (e.g. an empty string); returns 'Just Definitely' if a -- value can be read and is unlikely to be ambiguous." - parse :: MonadPlus m => T.Text -> m (Parsed a) - default parse :: (Readable a, MonadPlus m) + parse :: (MonadPlus m, MonadFail m) => T.Text -> m (Parsed a) + default parse :: (Readable a, MonadPlus m, MonadFail m) => T.Text -> m (Parsed a) parse = fmap Definitely . fromText {-# INLINE parse #-} @@ -56,7 +56,7 @@ discardConfidence (Definitely x) = x -- | Acts just like 'fromText': tries to parse a value from a 'T.Text' -- and discards any estimate of the parse's ambiguity. -parse' :: (MonadPlus m, Parseable a) => T.Text -> m a +parse' :: (MonadPlus m, Parseable a, MonadFail m) => T.Text -> m a parse' = fmap discardConfidence . parse parseIntish :: (Readable a, MonadPlus f) => T.Text -> f (Parsed a) @@ -78,7 +78,7 @@ instance Parseable Float where instance Parseable Double where -- Some CSV's export Doubles in a format like '1,000.00', filtering -- out commas lets us parse those sucessfully - parse = fmap Definitely . fromText -- . T.filter (/= ',') + parse = fmap Definitely . fromText instance Parseable T.Text where -- | This class relates a universe of possible column types to Haskell From 00b8e26134327c622cf4939c07c9ebc2fca721c8 Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Mon, 10 Jul 2023 11:43:54 +0100 Subject: [PATCH 3/6] Anthony Cowley's suggestion --- src/Frames/ColumnUniverse.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Frames/ColumnUniverse.hs b/src/Frames/ColumnUniverse.hs index a660ca4..8dcc7bd 100644 --- a/src/Frames/ColumnUniverse.hs +++ b/src/Frames/ColumnUniverse.hs @@ -67,18 +67,18 @@ parsedTypeRep (ColInfo (t,p)) = orderParsePriorities :: Parsed (Maybe Type) -> Maybe Int orderParsePriorities x = case discardConfidence x of - Nothing -> Just 1 -- categorical variable + Nothing -> Just (1 + 6) -- categorical variable Just t | t == tyText -> Just (0 + uncertainty) | t == tyDbl -> Just (2 + uncertainty) | t == tyInt -> Just (3 + uncertainty) | t == tyBool -> Just (4 + uncertainty) - | otherwise -> Nothing + | otherwise -> Just (5 + uncertainty) -- Unknown type where tyText = ConT (mkName "Text") tyDbl = ConT (mkName "Double") tyInt = ConT (mkName "Int") tyBool = ConT (mkName "Bool") - uncertainty = case x of Definitely _ -> 0; Possibly _ -> 5 + uncertainty = case x of Definitely _ -> 6; Possibly _ -> 0 -- | We use a join semi-lattice on types for representations. The -- bottom of the lattice is effectively an error (we have nothing to From c5dbc5a1bd3a469de6c1888a78dbbbb4df7f670b Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Thu, 20 Jul 2023 08:52:38 +0100 Subject: [PATCH 4/6] A function to rename columns --- src/Frames/Melt.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Frames/Melt.hs b/src/Frames/Melt.hs index 4cfbef8..df252e9 100644 --- a/src/Frames/Melt.hs +++ b/src/Frames/Melt.hs @@ -58,6 +58,19 @@ type family RDeleteAll ss ts where RDeleteAll '[] ts = ts RDeleteAll (s ': ss) ts = RDeleteAll ss (RDelete s ts) +transform :: forall rs as bs . (as ⊆ rs, RDeleteAll as rs ⊆ rs) + => (Record as -> Record bs) -> Record rs -> Record (RDeleteAll as rs ++ bs) +transform f xs = rcast @(RDeleteAll as rs) xs `rappend` f (rcast xs) + +-- | Rename a column +retypeColumn :: forall x y rs . ( V.KnownField x + , V.KnownField y + , V.Snd x ~ V.Snd y + , ElemOf rs x + , RDelete x rs ⊆ rs) + => Record rs -> Record (RDelete x rs V.++ '[y]) +retypeColumn = transform @rs @'[x] @'[y] (\r -> (rgetField @x r &: V.RNil)) + -- | This is 'melt', but the variables are at the front of the record, -- which reads a bit odd. meltRow' :: forall proxy vs ts ss. (vs ⊆ ts, ss ⊆ ts, vs ~ RDeleteAll ss ts, From f901c9005d4f870e1cfdffa1d5937b9b4ed38330 Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Thu, 20 Jul 2023 09:01:56 +0100 Subject: [PATCH 5/6] Undo accidental commit --- src/Frames/ColumnUniverse.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Frames/ColumnUniverse.hs b/src/Frames/ColumnUniverse.hs index 8dcc7bd..a660ca4 100644 --- a/src/Frames/ColumnUniverse.hs +++ b/src/Frames/ColumnUniverse.hs @@ -67,18 +67,18 @@ parsedTypeRep (ColInfo (t,p)) = orderParsePriorities :: Parsed (Maybe Type) -> Maybe Int orderParsePriorities x = case discardConfidence x of - Nothing -> Just (1 + 6) -- categorical variable + Nothing -> Just 1 -- categorical variable Just t | t == tyText -> Just (0 + uncertainty) | t == tyDbl -> Just (2 + uncertainty) | t == tyInt -> Just (3 + uncertainty) | t == tyBool -> Just (4 + uncertainty) - | otherwise -> Just (5 + uncertainty) -- Unknown type + | otherwise -> Nothing where tyText = ConT (mkName "Text") tyDbl = ConT (mkName "Double") tyInt = ConT (mkName "Int") tyBool = ConT (mkName "Bool") - uncertainty = case x of Definitely _ -> 6; Possibly _ -> 0 + uncertainty = case x of Definitely _ -> 0; Possibly _ -> 5 -- | We use a join semi-lattice on types for representations. The -- bottom of the lattice is effectively an error (we have nothing to From 68702b339790da44e3eb4a5f87b3c811e907ab43 Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Thu, 20 Jul 2023 09:03:25 +0100 Subject: [PATCH 6/6] Undo accidental commit --- src/Frames/ColumnTypeable.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Frames/ColumnTypeable.hs b/src/Frames/ColumnTypeable.hs index 35a60cf..021aa0b 100644 --- a/src/Frames/ColumnTypeable.hs +++ b/src/Frames/ColumnTypeable.hs @@ -27,8 +27,8 @@ class Parseable a where -- returns 'Just Possibly' if a value can be read, but is likely -- ambiguous (e.g. an empty string); returns 'Just Definitely' if a -- value can be read and is unlikely to be ambiguous." - parse :: (MonadPlus m, MonadFail m) => T.Text -> m (Parsed a) - default parse :: (Readable a, MonadPlus m, MonadFail m) + parse :: MonadPlus m => T.Text -> m (Parsed a) + default parse :: (Readable a, MonadPlus m) => T.Text -> m (Parsed a) parse = fmap Definitely . fromText {-# INLINE parse #-} @@ -56,7 +56,7 @@ discardConfidence (Definitely x) = x -- | Acts just like 'fromText': tries to parse a value from a 'T.Text' -- and discards any estimate of the parse's ambiguity. -parse' :: (MonadPlus m, Parseable a, MonadFail m) => T.Text -> m a +parse' :: (MonadPlus m, Parseable a) => T.Text -> m a parse' = fmap discardConfidence . parse parseIntish :: (Readable a, MonadPlus f) => T.Text -> f (Parsed a) @@ -78,7 +78,7 @@ instance Parseable Float where instance Parseable Double where -- Some CSV's export Doubles in a format like '1,000.00', filtering -- out commas lets us parse those sucessfully - parse = fmap Definitely . fromText + parse = fmap Definitely . fromText . T.filter (/= ',') instance Parseable T.Text where -- | This class relates a universe of possible column types to Haskell