Skip to content

Commit 9bd53d2

Browse files
committed
Add column type to columnInfo operation result.
1 parent 4271ccc commit 9bd53d2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Data/DataFrame/Operations.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,11 @@ parseDefault safeRead (BoxedColumn (c :: V.Vector a)) = let
486486
hasNulls = V.foldl' (\acc v -> if isNothing v then acc || True else acc) False safeVector
487487
in if safeRead && hasNulls then BoxedColumn safeVector else BoxedColumn c
488488

489-
-- | O(n) Returns the number of non-null columns in the dataframe.
490-
columnInfo :: DataFrame -> [(String, Int)]
491-
columnInfo df = L.sortBy (compare `on` snd) (MS.foldlWithKey go [] (columns df))
492-
where go acc k (BoxedColumn (c :: Vector a)) = (T.unpack k, V.length $ V.filter (flip S.member nullish . show) c) : acc
493-
go acc k (UnboxedColumn (c :: VU.Vector a)) = (T.unpack k, V.length $ V.filter (flip S.member nullish . show) (V.convert c)) : acc
489+
-- | O(n) Returns the number of non-null columns in the dataframe and the type associated
490+
-- with each column.
491+
columnInfo :: DataFrame -> [(String, Int, String)]
492+
columnInfo df = L.sortBy (compare `on` snd') (MS.foldlWithKey go [] (columns df))
493+
where go acc k (BoxedColumn (c :: Vector a)) = (T.unpack k, V.length $ V.filter (flip S.member nullish . show) c, show $ typeRep @a) : acc
494+
go acc k (UnboxedColumn (c :: VU.Vector a)) = (T.unpack k, V.length $ V.filter (flip S.member nullish . show) (V.convert c), show $ typeRep @a) : acc
494495
nullish = S.fromList ["Nothing", "NULL", "", " ", "nan"]
496+
snd' (_, x, _) = x

0 commit comments

Comments
 (0)