@@ -30,6 +30,7 @@ module DataFrame.Typed.Operations (
3030
3131 -- * Schema-modifying operations
3232 derive ,
33+ impute ,
3334 select ,
3435 exclude ,
3536 rename ,
@@ -54,7 +55,6 @@ module DataFrame.Typed.Operations (
5455 (|>) ,
5556) where
5657
57- import qualified Data.Foldable as F
5858import Data.Function ((&) )
5959import Data.Proxy (Proxy (.. ))
6060import qualified Data.Text as T
@@ -63,9 +63,9 @@ import GHC.TypeLits (KnownSymbol, Symbol, symbolVal)
6363import System.Random (RandomGen )
6464import Prelude hiding (drop , filter , take )
6565
66+ import qualified DataFrame.Functions as DF
6667import DataFrame.Internal.Column (Columnable )
6768import qualified DataFrame.Internal.Column as C
68- import DataFrame.Internal.Expression (Expr (.. ))
6969import qualified DataFrame.Operations.Aggregation as DA
7070import qualified DataFrame.Operations.Core as D
7171import DataFrame.Operations.Merge ()
@@ -75,7 +75,7 @@ import qualified DataFrame.Operations.Transformations as D
7575
7676-- Semigroup instance
7777
78- import DataFrame.Typed.Freeze (thaw , unsafeFreeze )
78+ import DataFrame.Typed.Freeze (unsafeFreeze )
7979import DataFrame.Typed.Schema
8080import DataFrame.Typed.Types (TExpr (.. ), TSortOrder (.. ), TypedDataFrame (.. ))
8181import qualified DataFrame.Typed.Types as T
@@ -222,6 +222,20 @@ derive (TExpr expr) (TDF df) = unsafeFreeze (D.derive colName expr df)
222222 where
223223 colName = T. pack (symbolVal (Proxy @ name ))
224224
225+ impute ::
226+ forall name a cols .
227+ ( KnownSymbol name
228+ , Columnable a
229+ ) =>
230+ a ->
231+ TypedDataFrame cols ->
232+ TypedDataFrame (Impute name cols )
233+ impute value (TDF df) =
234+ unsafeFreeze
235+ (D. derive colName (DF. fromMaybe value (DF. col @ (Maybe a ) colName)) df)
236+ where
237+ colName = T. pack (symbolVal (Proxy @ name ))
238+
225239-- | Select a subset of columns by name.
226240select ::
227241 forall (names :: [Symbol ]) cols .
0 commit comments