Skip to content

Commit 48aa6cc

Browse files
committed
fix: Formatting.
1 parent 69c50b9 commit 48aa6cc

3 files changed

Lines changed: 74 additions & 25 deletions

File tree

src/DataFrame/Functions.hs

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pow :: (Columnable a, Num a) => Expr a -> Int -> Expr a
226226
pow = (.^^)
227227

228228
relu :: (Columnable a, Num a, Ord a) => Expr a -> Expr a
229-
relu = lift (Prelude.max 0)
229+
relu = liftDecorated (Prelude.max 0) "relu" Nothing
230230

231231
min :: (Columnable a, Ord a) => Expr a -> Expr a -> Expr a
232232
min = lift2Decorated Prelude.min "max" Nothing True 1
@@ -240,19 +240,19 @@ reduce ::
240240
reduce expr start f = Agg (FoldAgg "foldUdf" (Just start) f) expr
241241

242242
toMaybe :: (Columnable a) => Expr a -> Expr (Maybe a)
243-
toMaybe = lift Just
243+
toMaybe = liftDecorated Just "toMaybe" Nothing
244244

245245
fromMaybe :: (Columnable a) => a -> Expr (Maybe a) -> Expr a
246-
fromMaybe d = lift (Maybe.fromMaybe d)
246+
fromMaybe d = liftDecorated (Maybe.fromMaybe d) "fromMaybe" Nothing
247247

248248
isJust :: (Columnable a) => Expr (Maybe a) -> Expr Bool
249-
isJust = lift Maybe.isJust
249+
isJust = liftDecorated Maybe.isJust "isJust" Nothing
250250

251251
isNothing :: (Columnable a) => Expr (Maybe a) -> Expr Bool
252-
isNothing = lift Maybe.isNothing
252+
isNothing = liftDecorated Maybe.isNothing "isNothing" Nothing
253253

254254
fromJust :: (Columnable a) => Expr (Maybe a) -> Expr a
255-
fromJust = lift Maybe.fromJust
255+
fromJust = liftDecorated Maybe.fromJust "fromJust" Nothing
256256

257257
whenPresent ::
258258
forall a b.
@@ -268,7 +268,14 @@ whenBothPresent f = lift2 (\l r -> f <$> l <*> r)
268268
recode ::
269269
forall a b.
270270
(Columnable a, Columnable b) => [(a, b)] -> Expr a -> Expr (Maybe b)
271-
recode mapping = lift (`lookup` mapping)
271+
recode mapping =
272+
Unary
273+
( MkUnaryOp
274+
{ unaryFn = (`lookup` mapping)
275+
, unaryName = "recode " <> T.pack (show mapping)
276+
, unarySymbol = Nothing
277+
}
278+
)
272279

273280
recodeWithCondition ::
274281
forall a b.
@@ -280,28 +287,55 @@ recodeWithCondition fallback ((cond, value) : rest) expr = ifThenElse (cond expr
280287
recodeWithDefault ::
281288
forall a b.
282289
(Columnable a, Columnable b) => b -> [(a, b)] -> Expr a -> Expr b
283-
recodeWithDefault d mapping = lift (Maybe.fromMaybe d . (`lookup` mapping))
290+
recodeWithDefault d mapping =
291+
Unary
292+
( MkUnaryOp
293+
{ unaryFn = Maybe.fromMaybe d . (`lookup` mapping)
294+
, unaryName =
295+
"recodeWithDefault " <> T.pack (show d) <> " " <> T.pack (show mapping)
296+
, unarySymbol = Nothing
297+
}
298+
)
284299

285300
firstOrNothing :: (Columnable a) => Expr [a] -> Expr (Maybe a)
286-
firstOrNothing = lift Maybe.listToMaybe
301+
firstOrNothing = liftDecorated Maybe.listToMaybe "firstOrNothing" Nothing
287302

288303
lastOrNothing :: (Columnable a) => Expr [a] -> Expr (Maybe a)
289-
lastOrNothing = lift (Maybe.listToMaybe . reverse)
304+
lastOrNothing = liftDecorated (Maybe.listToMaybe . reverse) "lastOrNothing" Nothing
290305

291306
splitOn :: T.Text -> Expr T.Text -> Expr [T.Text]
292-
splitOn delim = lift (T.splitOn delim)
307+
splitOn delim = liftDecorated (T.splitOn delim) "splitOn" Nothing
293308

294309
match :: T.Text -> Expr T.Text -> Expr (Maybe T.Text)
295-
match regex = lift ((\r -> if T.null r then Nothing else Just r) . (=~ regex))
310+
match regex =
311+
liftDecorated
312+
((\r -> if T.null r then Nothing else Just r) . (=~ regex))
313+
("match " <> T.pack (show regex))
314+
Nothing
296315

297316
matchAll :: T.Text -> Expr T.Text -> Expr [T.Text]
298-
matchAll regex = lift (getAllTextMatches . (=~ regex))
317+
matchAll regex =
318+
liftDecorated
319+
(getAllTextMatches . (=~ regex))
320+
("matchAll " <> T.pack (show regex))
321+
Nothing
299322

300-
parseDate :: T.Text -> Expr T.Text -> Expr (Maybe Day)
301-
parseDate format = lift (parseTimeM True defaultTimeLocale (T.unpack format) . T.unpack)
323+
parseDate ::
324+
(ParseTime t, Columnable t) => T.Text -> Expr T.Text -> Expr (Maybe t)
325+
parseDate format =
326+
liftDecorated
327+
(parseTimeM True defaultTimeLocale (T.unpack format) . T.unpack)
328+
("parseDate " <> format)
329+
Nothing
302330

303331
daysBetween :: Expr Day -> Expr Day -> Expr Int
304-
daysBetween d1 d2 = lift fromIntegral (lift2 diffDays d1 d2)
332+
daysBetween =
333+
lift2Decorated
334+
(\d1 d2 -> fromIntegral (diffDays d1 d2))
335+
"daysBetween"
336+
Nothing
337+
True
338+
2
305339

306340
bind ::
307341
forall a b m.

src/DataFrame/Internal/Column.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ instance (Ord a) => Ord (TypedColumn a) where
6868
unwrapTypedColumn :: TypedColumn a -> Column
6969
unwrapTypedColumn (TColumn value) = value
7070

71+
-- | Gets the underlying vector from a TypedColumn.
72+
vectorFromTypedColumn :: TypedColumn a -> VB.Vector a
73+
vectorFromTypedColumn (TColumn value) = either throw id (toVector value)
74+
7175
-- | Checks if a column contains missing values.
7276
hasMissing :: Column -> Bool
7377
hasMissing (OptionalColumn column) = True

src/DataFrame/Operators.hs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
{-# LANGUAGE FlexibleContexts #-}
22
{-# LANGUAGE OverloadedStrings #-}
3+
34
module DataFrame.Operators where
45

5-
import DataFrame.Internal.Column ( Columnable )
6-
import DataFrame.Internal.Expression
7-
( Expr(Lit, Binary),
8-
NamedExpr,
9-
UExpr(UExpr),
10-
BinaryOp(MkBinaryOp, binaryPrecedence, binaryFn, binaryName,
11-
binarySymbol, binaryCommutative) )
126
import Data.Function ((&))
137
import qualified Data.Text as T
8+
import DataFrame.Internal.Column (Columnable)
9+
import DataFrame.Internal.Expression (
10+
BinaryOp (
11+
MkBinaryOp,
12+
binaryCommutative,
13+
binaryFn,
14+
binaryName,
15+
binaryPrecedence,
16+
binarySymbol
17+
),
18+
Expr (Binary, Lit),
19+
NamedExpr,
20+
UExpr (UExpr),
21+
)
1422

1523
infix 8 .^^
1624
infix 4 .==, .<, .<=, .>=, .>, ./=
@@ -124,12 +132,15 @@ as expr name = (name, UExpr expr)
124132
)
125133

126134
(.^^) :: (Columnable a, Num a) => Expr a -> Int -> Expr a
127-
(.^^) expr i = Binary
135+
(.^^) expr i =
136+
Binary
128137
( MkBinaryOp
129138
{ binaryFn = (^)
130139
, binaryName = "pow"
131140
, binarySymbol = Just "^"
132141
, binaryCommutative = False
133142
, binaryPrecedence = 8
134143
}
135-
) expr (Lit i)
144+
)
145+
expr
146+
(Lit i)

0 commit comments

Comments
 (0)