Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dataframe-operations/src/DataFrame/Functions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ zScore :: Expr Double -> Expr Double
zScore c = (c - mean c) / stddev c

pow :: (Columnable a, Num a) => Expr a -> Int -> Expr a
pow expr i = lift2Decorated (^) "pow" (Just "^") True 8 expr (Lit i)
pow expr i = lift2Decorated (^) "pow" (Just "^") False 8 expr (Lit i)
{-# SPECIALIZE pow :: Expr Double -> Int -> Expr Double #-}
{-# SPECIALIZE pow :: Expr Float -> Int -> Expr Float #-}
{-# SPECIALIZE pow :: Expr Int -> Int -> Expr Int #-}
Expand Down Expand Up @@ -645,7 +645,7 @@ daysBetween =
(\d1 d2 -> fromIntegral (diffDays d1 d2))
"daysBetween"
Nothing
True
False
2

bind ::
Expand Down
2 changes: 1 addition & 1 deletion docs/base/haskell_for_data_analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ TIO.putStrLn $ D.toMarkdown withDates

```haskell
-- This requires two Day columns; here we illustrate the pattern:
-- D.derive "days_until" (F.daysBetween today_col deadline_col) df
-- D.derive "days_until" (F.daysBetween deadline_col today_col) df
```

### Opting into stronger type safety
Expand Down
2 changes: 1 addition & 1 deletion docs/haskell_for_data_analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ TIO.putStrLn $ D.toMarkdown withDates

```haskell
-- This requires two Day columns; here we illustrate the pattern:
-- D.derive "days_until" (F.daysBetween today_col deadline_col) df
-- D.derive "days_until" (F.daysBetween deadline_col today_col) df
```


Expand Down
33 changes: 33 additions & 0 deletions tests/Functions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module Functions where

import Data.Time.Calendar (Day, fromGregorian)
import qualified DataFrame as D
import DataFrame.Functions (
sanitize,
Expand Down Expand Up @@ -79,8 +80,40 @@ testSum =
(D.derive "sum" (F.sum (F.col @Int "A")) df)
)

testPow :: Test
testPow =
TestCase
( assertEqual
"pow of a compound base"
[4, 9, 16, 25, 36, 49, 64, 81, 100, 121]
( D.columnAsList @Int
(F.col "sq")
(D.derive "sq" (F.pow (F.col @Int "A" + F.lit 1) 2) df)
)
)

testDaysBetween :: Test
testDaysBetween =
TestCase
( assertEqual
"daysBetween d1 d2 is d1 minus d2 in either argument order"
([-9], [9])
( days (F.col @Day "start") (F.col @Day "end")
, days (F.col @Day "end") (F.col @Day "start")
)
)
where
dates =
D.fromNamedColumns
[ ("start", DI.fromList [fromGregorian 2024 3 1])
, ("end", DI.fromList [fromGregorian 2024 3 10])
]
days a b = D.columnAsList @Int (F.col "d") (D.derive "d" (F.daysBetween a b) dates)

tests :: [Test]
tests =
[ TestLabel "sanitizeIdentifiers" sanitizeIdentifiers
, TestLabel "testSum" testSum
, TestLabel "testPow" testPow
, TestLabel "testDaysBetween" testDaysBetween
]
Loading