Skip to content

Commit c03a0a3

Browse files
committed
Make dataframe work with 9.12.2
1 parent 7dceb9f commit c03a0a3

File tree

6 files changed

+37
-55
lines changed

6 files changed

+37
-55
lines changed

dataframe.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ maintainer: mschavinda@gmail.com
1414

1515
copyright: (c) 2024-2024 Michael Chavinda
1616
category: Data
17-
tested-with: GHC ==9.8.3 || ==9.6.6 || == 9.4.8 || ==9.10.1 || ==9.12.1
17+
tested-with: GHC ==9.8.3 || ==9.6.6 || == 9.4.8 || ==9.10.1 || ==9.12.1 || ==9.12.2
1818
extra-doc-files: CHANGELOG.md README.md
1919

2020
source-repository head

src/DataFrame/Internal/DataFrame.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE TypeApplications #-}
66
{-# LANGUAGE GADTs #-}
77
{-# LANGUAGE StrictData #-}
8+
{-# LANGUAGE FlexibleContexts #-}
89
module DataFrame.Internal.DataFrame where
910

1011
import qualified Data.Map as M
@@ -45,6 +46,7 @@ asText :: DataFrame -> Bool -> T.Text
4546
asText d properMarkdown =
4647
let header = "index" : map fst (sortBy (compare `on` snd) $ M.toList (columnIndices d))
4748
types = V.toList $ V.filter (/= "") $ V.map getType (columns d)
49+
getType :: Maybe Column -> T.Text
4850
getType Nothing = ""
4951
getType (Just (BoxedColumn (column :: V.Vector a))) = T.pack $ show (typeRep @a)
5052
getType (Just (UnboxedColumn (column :: VU.Vector a))) = T.pack $ show (typeRep @a)
@@ -53,6 +55,7 @@ asText d properMarkdown =
5355
getType (Just (GroupedUnboxedColumn (column :: V.Vector a))) = T.pack $ show (typeRep @a)
5456
-- Separate out cases dynamically so we don't end up making round trip string
5557
-- copies.
58+
get :: Maybe Column -> V.Vector T.Text
5659
get (Just (BoxedColumn (column :: V.Vector a))) = case testEquality (typeRep @a) (typeRep @T.Text) of
5760
Just Refl -> column
5861
Nothing -> case testEquality (typeRep @a) (typeRep @String) of

src/DataFrame/Internal/Row.hs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE ExistentialQuantification #-}
3+
{-# LANGUAGE ExplicitNamespaces #-}
4+
{-# LANGUAGE GADTs #-}
5+
{-# LANGUAGE InstanceSigs #-}
26
module DataFrame.Internal.Row where
37

48
import qualified Data.List as L
@@ -17,6 +21,33 @@ import DataFrame.Internal.Column
1721
import DataFrame.Internal.DataFrame
1822
import DataFrame.Internal.Types
1923
import Data.Function (on)
24+
import Data.Maybe (fromMaybe)
25+
import Data.Typeable (Typeable, type (:~:) (..))
26+
import Data.Word ( Word8, Word16, Word32, Word64 )
27+
import Type.Reflection (TypeRep, typeOf, typeRep)
28+
import Data.Type.Equality (TestEquality(..))
29+
30+
data RowValue where
31+
Value :: (Columnable' a) => a -> RowValue
32+
33+
instance Eq RowValue where
34+
(==) :: RowValue -> RowValue -> Bool
35+
(Value a) == (Value b) = fromMaybe False $ do
36+
Refl <- testEquality (typeOf a) (typeOf b)
37+
return $ a == b
38+
39+
instance Ord RowValue where
40+
(<=) :: RowValue -> RowValue -> Bool
41+
(Value a) <= (Value b) = fromMaybe False $ do
42+
Refl <- testEquality (typeOf a) (typeOf b)
43+
return $ a <= b
44+
45+
instance Show RowValue where
46+
show :: RowValue -> String
47+
show (Value a) = show a
48+
49+
toRowValue :: forall a . (Columnable' a) => a -> RowValue
50+
toRowValue = Value
2051

2152
type Row = V.Vector RowValue
2253

src/DataFrame/Internal/Types.hs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,4 @@ import Data.Word ( Word8, Word16, Word32, Word64 )
1919
import Type.Reflection (TypeRep, typeOf, typeRep)
2020
import Data.Type.Equality (TestEquality(..))
2121

22-
-- We need an "Object" type as an intermediate representation
23-
-- for rows. Useful for things like sorting and function application.
2422
type Columnable' a = (Typeable a, Show a, Ord a, Eq a)
25-
26-
data RowValue where
27-
Value :: (Columnable' a) => a -> RowValue
28-
29-
instance Eq RowValue where
30-
(==) :: RowValue -> RowValue -> Bool
31-
(Value a) == (Value b) = fromMaybe False $ do
32-
Refl <- testEquality (typeOf a) (typeOf b)
33-
return $ a == b
34-
35-
instance Ord RowValue where
36-
(<=) :: RowValue -> RowValue -> Bool
37-
(Value a) <= (Value b) = fromMaybe False $ do
38-
Refl <- testEquality (typeOf a) (typeOf b)
39-
return $ a <= b
40-
41-
instance Show RowValue where
42-
show :: RowValue -> String
43-
show (Value a) = show a
44-
45-
toRowValue :: forall a . (Columnable' a) => a -> RowValue
46-
toRowValue = Value
47-
48-
-- Convenience functions for types.
49-
unboxableTypes :: TypeRepList '[Int, Int8, Int16, Int32, Int64,
50-
Word, Word8, Word16, Word32, Word64,
51-
Char, Double, Float, Bool]
52-
unboxableTypes = Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep Nil)))))))))))))
53-
54-
numericTypes :: TypeRepList '[Int, Int8, Int16, Int32, Int64, Double, Float]
55-
numericTypes = Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep Nil))))))
56-
57-
data TypeRepList (xs :: [Type]) where
58-
Nil :: TypeRepList '[]
59-
Cons :: Typeable x => TypeRep x -> TypeRepList xs -> TypeRepList (x ': xs)
60-
61-
matchesAnyType :: forall a xs. (Typeable a) => TypeRepList xs -> TypeRep a -> Bool
62-
matchesAnyType Nil _ = False
63-
matchesAnyType (Cons ty tys) rep =
64-
case testEquality ty rep of
65-
Just Refl -> True
66-
Nothing -> matchesAnyType tys rep
67-
68-
testUnboxable :: forall a . Typeable a => TypeRep a -> Bool
69-
testUnboxable x = matchesAnyType unboxableTypes (typeRep @a)
70-
71-
testNumeric :: forall a . Typeable a => TypeRep a -> Bool
72-
testNumeric x = matchesAnyType numericTypes (typeRep @a)

src/DataFrame/Operations/Subset.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import DataFrame.Errors (DataFrameException(..))
2121
import DataFrame.Internal.Column
2222
import DataFrame.Internal.DataFrame (DataFrame(..), getColumn, empty)
2323
import DataFrame.Internal.Expression
24-
import DataFrame.Internal.Row (mkRowFromArgs)
25-
import DataFrame.Internal.Types (RowValue, toRowValue)
24+
import DataFrame.Internal.Row (mkRowFromArgs, RowValue, toRowValue)
2625
import DataFrame.Operations.Core
2726
import DataFrame.Operations.Transformations (apply)
2827
import Data.Function ((&))

src/DataFrame/Operations/Transformations.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import DataFrame.Errors (DataFrameException(..))
1717
import DataFrame.Internal.Column (Column(..), columnTypeString, itransform, ifoldrColumn, TypedColumn (TColumn), Columnable, transform, unwrapTypedColumn)
1818
import DataFrame.Internal.DataFrame (DataFrame(..), getColumn)
1919
import DataFrame.Internal.Expression
20-
import DataFrame.Internal.Row (mkRowFromArgs)
21-
import DataFrame.Internal.Types (RowValue, toRowValue)
20+
import DataFrame.Internal.Row (mkRowFromArgs, RowValue, toRowValue)
2221
import DataFrame.Operations.Core
2322
import Data.Maybe
2423
import Type.Reflection (typeRep, typeOf)

0 commit comments

Comments
 (0)