@@ -51,8 +51,8 @@ module DataFrame.Typed.Expr (
5151 ifThenElse ,
5252
5353 -- * Unary / binary lifting
54- tlift ,
55- tlift2 ,
54+ lift ,
55+ lift2 ,
5656
5757 -- * Comparison operators
5858 (.==.) ,
@@ -65,15 +65,15 @@ module DataFrame.Typed.Expr (
6565 -- * Logical operators
6666 (.&&.) ,
6767 (.||.) ,
68- tnot ,
68+ DataFrame.Typed.Expr. not ,
6969
7070 -- * Aggregation combinators
71- tsum ,
72- tmean ,
73- tcount ,
74- tminimum ,
75- tmaximum ,
76- tcollect ,
71+ sum ,
72+ mean ,
73+ count ,
74+ minimum ,
75+ maximum ,
76+ collect ,
7777
7878 -- * Named expression helper
7979 as ,
@@ -98,12 +98,10 @@ import DataFrame.Internal.Expression (
9898 UExpr (.. ),
9999 UnaryOp (.. ),
100100 )
101+ import DataFrame.Internal.Statistics
101102import DataFrame.Typed.Schema (AssertPresent , Lookup )
102103import DataFrame.Typed.Types (TExpr (.. ), TSortOrder (.. ))
103-
104- -------------------------------------------------------------------------------
105- -- Column reference — the core type-safe construction point
106- -------------------------------------------------------------------------------
104+ import Prelude hiding (maximum , minimum , sum )
107105
108106{- | Create a typed column reference. This is the key type-safety entry point.
109107
@@ -181,19 +179,15 @@ instance (IsString a, Columnable a) => IsString (TExpr cols a) where
181179-------------------------------------------------------------------------------
182180
183181-- | Lift a unary function into a typed expression.
184- tlift ::
182+ lift ::
185183 (Columnable a , Columnable b ) => (a -> b ) -> TExpr cols a -> TExpr cols b
186- tlift f (TExpr e) = TExpr (Unary (MkUnaryOp f " unaryUdf" Nothing ) e)
184+ lift f (TExpr e) = TExpr (Unary (MkUnaryOp f " unaryUdf" Nothing ) e)
187185
188186-- | Lift a binary function into typed expressions.
189- tlift2 ::
187+ lift2 ::
190188 (Columnable a , Columnable b , Columnable c ) =>
191189 (a -> b -> c ) -> TExpr cols a -> TExpr cols b -> TExpr cols c
192- tlift2 f (TExpr a) (TExpr b) = TExpr (Binary (MkBinaryOp f " binaryUdf" Nothing False 0 ) a b)
193-
194- -------------------------------------------------------------------------------
195- -- Comparison operators
196- -------------------------------------------------------------------------------
190+ lift2 f (TExpr a) (TExpr b) = TExpr (Binary (MkBinaryOp f " binaryUdf" Nothing False 0 ) a b)
197191
198192infixl 4 .==. , ./=. , .<. , .<=. , .>=. , .>.
199193infixr 3 .&&.
@@ -229,35 +223,30 @@ infixr 2 .||.
229223(.||.) :: TExpr cols Bool -> TExpr cols Bool -> TExpr cols Bool
230224(.||.) (TExpr a) (TExpr b) = TExpr (Binary (MkBinaryOp (||) " or" (Just " ||" ) True 2 ) a b)
231225
232- tnot :: TExpr cols Bool -> TExpr cols Bool
233- tnot (TExpr e) = TExpr (Unary (MkUnaryOp not " not" (Just " !" )) e)
226+ not :: TExpr cols Bool -> TExpr cols Bool
227+ not (TExpr e) = TExpr (Unary (MkUnaryOp Prelude. not " not" (Just " !" )) e)
234228
235229-------------------------------------------------------------------------------
236230-- Aggregation combinators
237231-------------------------------------------------------------------------------
238232
239- tsum :: (Columnable a , Num a ) => TExpr cols a -> TExpr cols a
240- tsum (TExpr e) = TExpr (Agg (FoldAgg " sum" Nothing (+) ) e)
233+ sum :: (Columnable a , Num a ) => TExpr cols a -> TExpr cols a
234+ sum (TExpr e) = TExpr (Agg (FoldAgg " sum" Nothing (+) ) e)
241235
242- tmean :: (Columnable a , Real a , VU. Unbox a ) => TExpr cols a -> TExpr cols Double
243- tmean (TExpr e) = TExpr (Agg (CollectAgg " mean" mean') e)
244- where
245- mean' v =
246- let s = VU. foldl' (\ acc x -> acc + realToFrac x) (0 :: Double ) v
247- n = VU. length v
248- in if n == 0 then 0 else s / fromIntegral n
236+ mean :: (Columnable a , Real a , VU. Unbox a ) => TExpr cols a -> TExpr cols Double
237+ mean (TExpr e) = TExpr (Agg (CollectAgg " mean" mean') e)
249238
250- tcount :: (Columnable a ) => TExpr cols a -> TExpr cols Int
251- tcount (TExpr e) = TExpr (Agg (FoldAgg " count" (Just 0 ) (\ acc _ -> acc + 1 )) e)
239+ count :: (Columnable a ) => TExpr cols a -> TExpr cols Int
240+ count (TExpr e) = TExpr (Agg (FoldAgg " count" (Just 0 ) (\ acc _ -> acc + 1 )) e)
252241
253- tminimum :: (Columnable a , Ord a ) => TExpr cols a -> TExpr cols a
254- tminimum (TExpr e) = TExpr (Agg (FoldAgg " minimum" Nothing min ) e)
242+ minimum :: (Columnable a , Ord a ) => TExpr cols a -> TExpr cols a
243+ minimum (TExpr e) = TExpr (Agg (FoldAgg " minimum" Nothing min ) e)
255244
256- tmaximum :: (Columnable a , Ord a ) => TExpr cols a -> TExpr cols a
257- tmaximum (TExpr e) = TExpr (Agg (FoldAgg " maximum" Nothing max ) e)
245+ maximum :: (Columnable a , Ord a ) => TExpr cols a -> TExpr cols a
246+ maximum (TExpr e) = TExpr (Agg (FoldAgg " maximum" Nothing max ) e)
258247
259- tcollect :: (Columnable a ) => TExpr cols a -> TExpr cols [a ]
260- tcollect (TExpr e) = TExpr (Agg (FoldAgg " collect" (Just [] ) (flip (:) )) e)
248+ collect :: (Columnable a ) => TExpr cols a -> TExpr cols [a ]
249+ collect (TExpr e) = TExpr (Agg (FoldAgg " collect" (Just [] ) (flip (:) )) e)
261250
262251-------------------------------------------------------------------------------
263252-- Named expression helper
@@ -267,10 +256,6 @@ tcollect (TExpr e) = TExpr (Agg (FoldAgg "collect" (Just []) (flip (:))) e)
267256as :: (Columnable a ) => TExpr cols a -> T. Text -> NamedExpr
268257as (TExpr e) name = (name, UExpr e)
269258
270- -------------------------------------------------------------------------------
271- -- Sort helpers
272- -------------------------------------------------------------------------------
273-
274259-- | Create an ascending sort order from a typed expression.
275260asc :: (Columnable a ) => TExpr cols a -> TSortOrder cols
276261asc = Asc
0 commit comments