Skip to content

Commit e28e951

Browse files
authored
Some major changes for expressions. (#33)
* Add interpreter for expression language. * Remove copius reflection and use type families. * Change some examples to use the new derive API * deprecate deriveFrom
1 parent 93229e1 commit e28e951

File tree

16 files changed

+363
-143
lines changed

16 files changed

+363
-143
lines changed

app/Main.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ chipotle = do
101101
print $ D.take 10 f
102102

103103
-- Create a total_price column that is quantity * item_price
104-
let multiply (a :: Int) (b :: Double) = fromIntegral a * b
105-
let withTotalPrice = D.deriveFrom (["quantity", "item_price"], D.func multiply) "total_price" f
104+
let withTotalPrice = D.derive "total_price" (D.lift fromIntegral (D.col @Int "quantity") * D.col @Double"item_price") f
106105

107106
-- sample a filtered subset of the dataframe
108107
putStrLn "Sample dataframe"

dataframe.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ source-repository head
2424
library
2525
exposed-modules: DataFrame
2626
other-modules: DataFrame.Internal.Types,
27+
DataFrame.Internal.Expression,
2728
DataFrame.Internal.Function,
2829
DataFrame.Internal.Parsing,
2930
DataFrame.Internal.Column,
@@ -60,6 +61,7 @@ executable dataframe
6061
main-is: Main.hs
6162
other-modules: DataFrame,
6263
DataFrame.Internal.Types,
64+
DataFrame.Internal.Expression,
6365
DataFrame.Internal.Function,
6466
DataFrame.Internal.Parsing,
6567
DataFrame.Internal.Column,

docs/coming_from_dplyr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ starwars
111111
|> D.selectRange ("name", "mass")
112112
-- mass and height are optionals so we combine them with
113113
-- Haskell's Applicative operators.
114-
|> D.deriveFrom (["mass", "height"], D.func (\w h -> bmi <$> w <*> h)) "bmi"
114+
|> D.derive "bmi" (lift2 (/) (lift fromIntegral (col @Int "mass")) (lift fromIntegral (col@ Int "height")))
115115
|> D.take 10
116116
```
117117

src/DataFrame.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module DataFrame
55
where
66

77
import DataFrame.Internal.Types as D
8+
import DataFrame.Internal.Expression as D
89
import DataFrame.Internal.Function as D
910
import DataFrame.Internal.Parsing as D
1011
import DataFrame.Internal.Column as D

src/DataFrame/Display/Terminal/Plot.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE GADTs #-}
66
{-# LANGUAGE NumericUnderscores #-}
77
{-# LANGUAGE TupleSections #-}
8+
{-# LANGUAGE FlexibleContexts #-}
89
module DataFrame.Display.Terminal.Plot where
910

1011
import qualified Data.List as L
@@ -19,9 +20,8 @@ import Control.Monad ( forM_, forM )
1920
import Data.Bifunctor ( first )
2021
import Data.Char ( ord, chr )
2122
import DataFrame.Display.Terminal.Colours
22-
import DataFrame.Internal.Column (Column(..))
23+
import DataFrame.Internal.Column (Column(..), Columnable)
2324
import DataFrame.Internal.DataFrame (DataFrame(..))
24-
import DataFrame.Internal.Types (Columnable)
2525
import DataFrame.Operations.Core
2626
import Data.Maybe (fromMaybe)
2727
import Data.Typeable (Typeable)

src/DataFrame/Errors.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ data DataFrameException where
2222
-> T.Text -- ^ call point
2323
-> DataFrameException
2424
TypeMismatchException' :: forall a . (Typeable a)
25-
=> TypeRep a -- ^ expected type
26-
-> String -- ^ given type
25+
=> TypeRep a -- ^ given type
26+
-> String -- ^ expected type
2727
-> T.Text -- ^ column name
2828
-> T.Text -- ^ call point
2929
-> DataFrameException

0 commit comments

Comments
 (0)