| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
DataFrame.Typed.Apply
Description
Typed column transformations: the apply/derive family and
default-valued inserts, plus the horizontal merge (. Schema changes are
tracked at the type level (e.g. |||)applyColumn rewrites a column's element type
via SetColumnType).
Synopsis
- applyColumn :: forall (name :: Symbol) a b (cols :: [(Symbol, Type)]). (KnownSymbol name, a ~ SafeLookup name cols, Columnable a, Columnable b, AssertPresent name cols) => (a -> b) -> TypedDataFrame cols -> TypedDataFrame (SetColumnType name b cols)
- applyMany :: forall (names :: [Symbol]) a (cols :: [(Symbol, Type)]). (AllKnownSymbol names, Columnable a, AssertAllColumnsHaveType names a cols) => (a -> a) -> TypedDataFrame cols -> TypedDataFrame cols
- applyWhere :: forall (filterName :: Symbol) (targetName :: Symbol) a b (cols :: [(Symbol, Type)]). (KnownSymbol filterName, KnownSymbol targetName, a ~ SafeLookup filterName cols, b ~ SafeLookup targetName cols, Columnable a, Columnable b, AssertPresent filterName cols, AssertPresent targetName cols) => (a -> Bool) -> (b -> b) -> TypedDataFrame cols -> TypedDataFrame cols
- applyAtIndex :: forall (name :: Symbol) a (cols :: [(Symbol, Type)]). (KnownSymbol name, a ~ SafeLookup name cols, Columnable a, AssertPresent name cols) => Int -> (a -> a) -> TypedDataFrame cols -> TypedDataFrame cols
- safeApply :: forall (name :: Symbol) a b (cols :: [(Symbol, Type)]). (KnownSymbol name, a ~ SafeLookup name cols, Columnable a, Columnable b, AssertPresent name cols) => (a -> b) -> TypedDataFrame cols -> Either DataFrameException (TypedDataFrame (SetColumnType name b cols))
- deriveWithExpr :: forall (name :: Symbol) a (cols :: [(Symbol, Type)]). (KnownSymbol name, Columnable a, AssertAbsent name cols) => TExpr cols a -> TypedDataFrame cols -> (TExpr (Snoc cols '(name, a)) a, TypedDataFrame (Snoc cols '(name, a)))
- insertWithDefault :: forall (name :: Symbol) a (cols :: [(Symbol, Type)]) t. (KnownSymbol name, Columnable a, Foldable t, AssertAbsent name cols) => a -> t a -> TypedDataFrame cols -> TypedDataFrame ('(name, a) ': cols)
- insertVectorWithDefault :: forall (name :: Symbol) a (cols :: [(Symbol, Type)]). (KnownSymbol name, Columnable a, AssertAbsent name cols) => a -> Vector a -> TypedDataFrame cols -> TypedDataFrame ('(name, a) ': cols)
- insertUnboxedVector :: forall (name :: Symbol) a (cols :: [(Symbol, Type)]). (KnownSymbol name, Columnable a, Unbox a, AssertAbsent name cols) => Vector a -> TypedDataFrame cols -> TypedDataFrame ('(name, a) ': cols)
- (|||) :: forall (left :: [(Symbol, Type)]) (right :: [(Symbol, Type)]). AssertDisjoint left right => TypedDataFrame left -> TypedDataFrame right -> TypedDataFrame (Append left right)
Documentation
applyColumn :: forall (name :: Symbol) a b (cols :: [(Symbol, Type)]). (KnownSymbol name, a ~ SafeLookup name cols, Columnable a, Columnable b, AssertPresent name cols) => (a -> b) -> TypedDataFrame cols -> TypedDataFrame (SetColumnType name b cols) Source #
Map a function over a column, rewriting its element type from a to b.
The schema's entry for name is updated via SetColumnType.
df' = applyColumn @"age" (show :: Int -> String) df -- the "age" column is now String-typed
applyMany :: forall (names :: [Symbol]) a (cols :: [(Symbol, Type)]). (AllKnownSymbol names, Columnable a, AssertAllColumnsHaveType names a cols) => (a -> a) -> TypedDataFrame cols -> TypedDataFrame cols Source #
Apply a type-preserving function to several columns at once. Every named
column must already share the element type a (enforced by
AssertAllColumnsHaveType).
applyWhere :: forall (filterName :: Symbol) (targetName :: Symbol) a b (cols :: [(Symbol, Type)]). (KnownSymbol filterName, KnownSymbol targetName, a ~ SafeLookup filterName cols, b ~ SafeLookup targetName cols, Columnable a, Columnable b, AssertPresent filterName cols, AssertPresent targetName cols) => (a -> Bool) -> (b -> b) -> TypedDataFrame cols -> TypedDataFrame cols Source #
Apply a function to a target column only on rows where a condition holds on a filter column. Both columns are named by type application; the target keeps its type.
applyWhere @"flagged" @"score" id (* 2) df
applyAtIndex :: forall (name :: Symbol) a (cols :: [(Symbol, Type)]). (KnownSymbol name, a ~ SafeLookup name cols, Columnable a, AssertPresent name cols) => Int -> (a -> a) -> TypedDataFrame cols -> TypedDataFrame cols Source #
Apply a type-preserving function to a single row of a column.
safeApply :: forall (name :: Symbol) a b (cols :: [(Symbol, Type)]). (KnownSymbol name, a ~ SafeLookup name cols, Columnable a, Columnable b, AssertPresent name cols) => (a -> b) -> TypedDataFrame cols -> Either DataFrameException (TypedDataFrame (SetColumnType name b cols)) Source #
Like applyColumn but returns the error instead of throwing.
deriveWithExpr :: forall (name :: Symbol) a (cols :: [(Symbol, Type)]). (KnownSymbol name, Columnable a, AssertAbsent name cols) => TExpr cols a -> TypedDataFrame cols -> (TExpr (Snoc cols '(name, a)) a, TypedDataFrame (Snoc cols '(name, a))) Source #
Derive a new column and also return a typed reference to it. The returned expression lives in the extended schema, so it can feed later operations.
insertWithDefault :: forall (name :: Symbol) a (cols :: [(Symbol, Type)]) t. (KnownSymbol name, Columnable a, Foldable t, AssertAbsent name cols) => a -> t a -> TypedDataFrame cols -> TypedDataFrame ('(name, a) ': cols) Source #
Insert a column from a Foldable, padding missing rows with a default.
insertVectorWithDefault :: forall (name :: Symbol) a (cols :: [(Symbol, Type)]). (KnownSymbol name, Columnable a, AssertAbsent name cols) => a -> Vector a -> TypedDataFrame cols -> TypedDataFrame ('(name, a) ': cols) Source #
Insert a boxed Vector, padding missing rows with a default.
insertUnboxedVector :: forall (name :: Symbol) a (cols :: [(Symbol, Type)]). (KnownSymbol name, Columnable a, Unbox a, AssertAbsent name cols) => Vector a -> TypedDataFrame cols -> TypedDataFrame ('(name, a) ': cols) Source #
Insert an unboxed Vector as a new column.
(|||) :: forall (left :: [(Symbol, Type)]) (right :: [(Symbol, Type)]). AssertDisjoint left right => TypedDataFrame left -> TypedDataFrame right -> TypedDataFrame (Append left right) Source #
Horizontal merge: place two DataFrames side by side. The schemas must be
disjoint (no shared column names), enforced by AssertDisjoint; the result
schema is their concatenation.