Skip to content

Commit 861653a

Browse files
committed
feat: make numeric column conversion functions more general.
1 parent c70718d commit 861653a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/DataFrame/Operations/Core.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,8 @@ Returns 'Left' with a 'DataFrameException' if the column cannot be converted to
864864
This may occur if the column contains non-numeric data or values outside the 'Int' range.
865865
-}
866866
columnAsIntVector ::
867-
Expr Int -> DataFrame -> Either DataFrameException (VU.Vector Int)
867+
(Columnable a, Num a) =>
868+
Expr a -> DataFrame -> Either DataFrameException (VU.Vector Int)
868869
columnAsIntVector (Col name) df = case getColumn name df of
869870
Just col -> toIntVector col
870871
Nothing ->
@@ -880,7 +881,8 @@ Returns 'Left' with a 'DataFrameException' if the column cannot be converted to
880881
This may occur if the column contains non-numeric data.
881882
-}
882883
columnAsDoubleVector ::
883-
Expr Double -> DataFrame -> Either DataFrameException (VU.Vector Double)
884+
(Columnable a, Num a) =>
885+
Expr a -> DataFrame -> Either DataFrameException (VU.Vector Double)
884886
columnAsDoubleVector (Col name) df = case getColumn name df of
885887
Just col -> toDoubleVector col
886888
Nothing ->
@@ -896,7 +898,8 @@ Returns 'Left' with a 'DataFrameException' if the column cannot be converted to
896898
This may occur if the column contains non-numeric data.
897899
-}
898900
columnAsFloatVector ::
899-
Expr Float -> DataFrame -> Either DataFrameException (VU.Vector Float)
901+
(Columnable a, Num a) =>
902+
Expr a -> DataFrame -> Either DataFrameException (VU.Vector Float)
900903
columnAsFloatVector (Col name) df = case getColumn name df of
901904
Just col -> toFloatVector col
902905
Nothing ->

src/DataFrame/Synthesis.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ percentiles :: DataFrame -> [Expr Double]
266266
percentiles df =
267267
let
268268
doubleColumns =
269-
map (either throw id . ((`columnAsDoubleVector` df) . Col)) (D.columnNames df)
269+
map
270+
(either throw id . ((`columnAsDoubleVector` df) . Col @Double))
271+
(D.columnNames df)
270272
in
271273
concatMap
272274
(\c -> map (Lit . roundTo2SigDigits . (`percentile'` c)) [1, 25, 75, 99])

0 commit comments

Comments
 (0)