Skip to content

Commit 7a2cc8e

Browse files
committed
chore: Remove t prefix from operations.
1 parent 4ed1e0e commit 7a2cc8e

6 files changed

Lines changed: 40 additions & 82 deletions

File tree

src/DataFrame/Typed.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ module DataFrame.Typed (
6868
col,
6969
lit,
7070
ifThenElse,
71-
tlift,
72-
tlift2,
71+
lift,
72+
lift2,
7373

7474
-- * Comparison operators
7575
(.==.),
@@ -82,15 +82,15 @@ module DataFrame.Typed (
8282
-- * Logical operators
8383
(.&&.),
8484
(.||.),
85-
tnot,
85+
DataFrame.Typed.Expr.not,
8686

8787
-- * Aggregation expression combinators
88-
tsum,
89-
tmean,
90-
tcount,
91-
tminimum,
92-
tmaximum,
93-
tcollect,
88+
DataFrame.Typed.Expr.sum,
89+
mean,
90+
count,
91+
DataFrame.Typed.Expr.minimum,
92+
DataFrame.Typed.Expr.maximum,
93+
collect,
9494

9595
-- * Typed sort orders
9696
TSortOrder (..),

src/DataFrame/Typed/Aggregate.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Result schema = grouping key columns ++ aggregated columns (in declaration order
7979
8080
@
8181
result = aggregate
82-
(agg \@\"total\" (tsum salary) $ agg \@\"count\" (tcount salary) $ aggNil)
82+
(agg \@\"total\" (tsum (col @"salary")) $ agg \@\"count\" (tcount (col @"salary") $ aggNil)
8383
(groupBy \@'[\"dept\"] employees)
8484
-- result :: TDF '[Column \"dept\" Text, Column \"total\" Double, Column \"count\" Int]
8585
@

src/DataFrame/Typed/Expr.hs

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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
101102
import DataFrame.Typed.Schema (AssertPresent, Lookup)
102103
import 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

198192
infixl 4 .==., ./=., .<., .<=., .>=., .>.
199193
infixr 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)
267256
as :: (Columnable a) => TExpr cols a -> T.Text -> NamedExpr
268257
as (TExpr e) name = (name, UExpr e)
269258

270-
-------------------------------------------------------------------------------
271-
-- Sort helpers
272-
-------------------------------------------------------------------------------
273-
274259
-- | Create an ascending sort order from a typed expression.
275260
asc :: (Columnable a) => TExpr cols a -> TSortOrder cols
276261
asc = Asc

src/DataFrame/Typed/Freeze.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ Used internally after delegation where the library guarantees schema correctness
5454
unsafeFreeze :: D.DataFrame -> TypedDataFrame cols
5555
unsafeFreeze = TDF
5656

57-
-------------------------------------------------------------------------------
58-
-- Internal validation
59-
-------------------------------------------------------------------------------
60-
6157
validateSchema ::
6258
forall cols.
6359
(KnownSchema cols) =>

src/DataFrame/Typed/Schema.hs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ import DataFrame.Internal.Column (Columnable)
6767
import DataFrame.Internal.Types (If)
6868
import DataFrame.Typed.Types (Column)
6969

70-
-------------------------------------------------------------------------------
71-
-- Core type families
72-
-------------------------------------------------------------------------------
73-
7470
-- | Look up the element type of a column by name.
7571
type family Lookup (name :: Symbol) (cols :: [Type]) :: Type where
7672
Lookup name (Column name a ': _) = a
@@ -79,6 +75,7 @@ type family Lookup (name :: Symbol) (cols :: [Type]) :: Type where
7975
TypeError
8076
('Text "Column '" ':<>: 'Text name ':<>: 'Text "' not found in schema")
8177

78+
-- | Unwrap a Maybe from a type after we impute values.
8279
type family Impute (name :: Symbol) (cols :: [Type]) :: [Type] where
8380
Impute name (Column name (Maybe a) ': rest) = Column name a ': rest
8481
Impute name (Column name _ ': rest) =
@@ -186,10 +183,6 @@ type family
186183
TypeError
187184
('Text "Column '" ':<>: 'Text name ':<>: 'Text "' not found in schema")
188185

189-
-------------------------------------------------------------------------------
190-
-- Maybe-stripping families
191-
-------------------------------------------------------------------------------
192-
193186
{- | Strip 'Maybe' from all columns. Used by 'filterAllJust'.
194187
195188
@Column "x" (Maybe Double)@ becomes @Column "x" Double@.
@@ -213,10 +206,6 @@ type family StripMaybeAt (name :: Symbol) (cols :: [Type]) :: [Type] where
213206
TypeError
214207
('Text "Column '" ':<>: 'Text name ':<>: 'Text "' not found in schema")
215208

216-
-------------------------------------------------------------------------------
217-
-- Join schema families
218-
-------------------------------------------------------------------------------
219-
220209
-- | Extract column names that appear in both schemas.
221210
type family SharedNames (left :: [Type]) (right :: [Type]) :: [Symbol] where
222211
SharedNames '[] right = '[]
@@ -324,10 +313,6 @@ type family GroupKeyColumns (keys :: [Symbol]) (cols :: [Type]) :: [Type] where
324313
(Column n a ': GroupKeyColumns keys rest)
325314
(GroupKeyColumns keys rest)
326315

327-
-------------------------------------------------------------------------------
328-
-- KnownSchema class
329-
-------------------------------------------------------------------------------
330-
331316
-- | Provides runtime evidence of a schema: a list of (name, TypeRep) pairs.
332317
class KnownSchema (cols :: [Type]) where
333318
schemaEvidence :: [(T.Text, SomeTypeRep)]
@@ -343,10 +328,6 @@ instance
343328
(T.pack (symbolVal (Proxy @name)), someTypeRep (Proxy @a))
344329
: schemaEvidence @rest
345330

346-
-------------------------------------------------------------------------------
347-
-- AllKnownSymbol helper
348-
-------------------------------------------------------------------------------
349-
350331
-- | A class that provides a list of 'Text' values for a type-level list of Symbols.
351332
class AllKnownSymbol (names :: [Symbol]) where
352333
symbolVals :: [T.Text]

src/DataFrame/Typed/TH.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ deriveSchemaFromCsvFile typeName path = do
5353
df <- liftIO (D.readCsv path)
5454
deriveSchema typeName df
5555

56-
-------------------------------------------------------------------------------
57-
-- Internal helpers
58-
-------------------------------------------------------------------------------
59-
6056
getSchemaInfo :: D.DataFrame -> [(T.Text, String)]
6157
getSchemaInfo df =
6258
let orderedNames =

0 commit comments

Comments
 (0)