Skip to content

Commit 026daae

Browse files
committed
chore: Slight updates to documentation.
1 parent 547fdeb commit 026daae

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

docs/coming_from_other_implementations.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ghci> D.fromList [Just (1 :: Double), Just 3, Just 5, Nothing, Just 6, Just 8]
5959
[Just 1.0, Just 3.0, Just 5.0, Nothing, Just 6.0, Just 8.0]
6060
```
6161

62-
This approach is superior because:
62+
This approach is better because:
6363
- The type system forces you to handle missing values explicitly
6464
- You can't accidentally treat `Nothing` as a number
6565
- Pattern matching ensures you consider all cases
@@ -598,10 +598,10 @@ Example:
598598

599599
```haskell
600600
-- Using lift for a unary function
601-
D.derive "doubled" (F.lift (*2) (F.col @Double "weight"))
601+
D.derive "doubled" (F.lift (*2) weight)
602602

603603
-- Using lift2 for a binary function
604-
D.derive "weight_per_height" (F.lift2 (/) (F.col @Double "weight") (F.col @Double "height"))
604+
D.derive "weight_per_height" (F.lift2 (/) weight height)
605605
```
606606

607607
#### Column Expansion
@@ -620,8 +620,10 @@ We don't provide built-in column expansion, so you write multiple explicit opera
620620

621621
```haskell
622622
df_csv
623-
|> D.derive "weight-5%" ((F.col @Double "weight") * (F.lit 0.95))
624-
|> D.derive "height-5%" ((F.col @Double "height") * (F.lit 0.95))
623+
|> D.deriveMany
624+
[ "weight-5%" .= weight * 0.95
625+
, "height-5%" .= height * 0.95
626+
]
625627
|> D.select ["name", "weight-5%", "height-5%"]
626628
```
627629

@@ -749,7 +751,6 @@ let decade d = let (y, _, _) = toGregorian d
749751

750752
df_csv
751753
|> D.derive "decade" (F.lift decade (F.col @Day "birthdate"))
752-
|> D.select ["decade"]
753754
|> D.groupBy ["decade"]
754755
|> D.aggregate [F.count (F.col @Day "decade") `F.as` "Count"]
755756
```

docs/intro_to_probability_and_data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ghci> df
4848
You can see the dimensions of this data frame by typing:
4949

5050
```haskell
51-
ghci> D.dimension arbuthnot
51+
ghci> D.dimensions arbuthnot
5252

5353
```
5454

docs/quick_start.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
### Example usage
2828

29+
#### GHCi/Jupyter notebooks
2930
Looking through the structure of the columns.
3031

3132
```haskell
@@ -114,3 +115,34 @@ Key features in example:
114115
* Create type-safe references to columns in a dataframe using :exposeColumns
115116
* Type-safe column transformations for faster and safer exploration.
116117
* Fluid, chaining API that makes code easy to reason about.
118+
119+
#### Standalone scripts
120+
121+
We provide a small, monadic DSL for scripts where you want relatively more type safety.
122+
123+
```haskell
124+
{-# LANGUAGE OverloadedStrings #-}
125+
{-# LANGUAGE TemplateHaskell #-}
126+
127+
module Main where
128+
129+
import qualified DataFrame as D
130+
import qualified DataFrame.Functions as F
131+
132+
import DataFrame.Monad
133+
134+
import Data.Text (Text)
135+
import DataFrame.Functions ((.&&), (.>=))
136+
137+
$(F.declareColumnsFromCsvFile "./data/housing.csv")
138+
139+
main :: IO ()
140+
main = do
141+
df <- D.readCsv "./data/housing.csv"
142+
print $ runFrameM df $ do
143+
-- 1) Type safe reference to `median_house_value` and `median_income`
144+
-- 2) creates a type safe reference to the newly created column.
145+
is_expensive <- deriveM "is_expensive" (median_house_value .>= 500000)
146+
luxury <- deriveM "luxury" (is_expensive .&& median_income .>= 8)
147+
filterWhereM luxury
148+
```

src/DataFrame/Monad.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE RankNTypes #-}
55
{-# LANGUAGE ScopedTypeVariables #-}
66
{-# LANGUAGE TupleSections #-}
7+
{-# LANGUAGE InstanceSigs #-}
78

89
module DataFrame.Monad where
910

@@ -20,18 +21,21 @@ import qualified Data.Text as T
2021
newtype FrameM a = FrameM {runFrameM_ :: DataFrame -> (DataFrame, a)}
2122

2223
instance Functor FrameM where
24+
fmap :: (a -> b) -> FrameM a -> FrameM b
2325
fmap f (FrameM g) = FrameM $ \df ->
2426
let (df', x) = g df
2527
in (df', f x)
2628

2729
instance Applicative FrameM where
2830
pure x = FrameM (,x)
31+
(<*>) :: FrameM (a -> b) -> FrameM a -> FrameM b
2932
FrameM ff <*> FrameM fx = FrameM $ \df ->
3033
let (df1, f) = ff df
3134
(df2, x) = fx df1
3235
in (df2, f x)
3336

3437
instance Monad FrameM where
38+
(>>=) :: FrameM a -> (a -> FrameM b) -> FrameM b
3539
FrameM g >>= f = FrameM $ \df ->
3640
let (df1, x) = g df
3741
FrameM h = f x
@@ -40,7 +44,7 @@ instance Monad FrameM where
4044
deriveM :: (Columnable a) => T.Text -> Expr a -> FrameM (Expr a)
4145
deriveM name expr = FrameM $ \df ->
4246
let df' = D.derive name expr df
43-
in (df', expr) -- or (df', F.col @a name)
47+
in (df', expr)
4448

4549
filterWhereM :: Expr Bool -> FrameM ()
4650
filterWhereM p = FrameM $ \df ->

0 commit comments

Comments
 (0)