Skip to content

Commit 990cd64

Browse files
committed
Safe lookup for column info function
1 parent 824fe3b commit 990cd64

File tree

1 file changed

+4
-4
lines changed
  • src/Data/DataFrame/Operations

1 file changed

+4
-4
lines changed

src/Data/DataFrame/Operations/Core.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,28 +169,28 @@ columnInfo df = empty & insertColumn' "Column Name" (Just $! toColumn (map nameO
169169
where
170170
infos = L.sortBy (compare `on` nonNullValues) (V.ifoldl' go [] (columns df)) :: [ColumnInfo]
171171
indexMap = M.fromList (map (\(a, b) -> (b, a)) $ M.toList (columnIndices df))
172-
columnName i = indexMap M.! i
172+
columnName i = M.lookup i indexMap
173173
go acc i Nothing = acc
174174
go acc i (Just col@(OptionalColumn (c :: V.Vector a))) = let
175175
cname = columnName i
176176
countNulls = nulls col
177177
countPartial = partiallyParsed col
178178
columnType = T.pack $ show $ typeRep @a
179179
unique = S.size $ VG.foldr S.insert S.empty c
180-
in ColumnInfo cname (columnLength col - countNulls) countNulls countPartial unique columnType : acc
180+
in if cname == Nothing then acc else ColumnInfo (fromMaybe "" cname) (columnLength col - countNulls) countNulls countPartial unique columnType : acc
181181
go acc i (Just col@(BoxedColumn (c :: V.Vector a))) = let
182182
cname = columnName i
183183
countPartial = partiallyParsed col
184184
columnType = T.pack $ show $ typeRep @a
185185
unique = S.size $ VG.foldr S.insert S.empty c
186-
in ColumnInfo cname (columnLength col) 0 countPartial unique columnType : acc
186+
in if cname == Nothing then acc else ColumnInfo (fromMaybe "" cname) (columnLength col) 0 countPartial unique columnType : acc
187187
go acc i (Just col@(UnboxedColumn c)) = let
188188
cname = columnName i
189189
columnType = T.pack $ columnTypeString col
190190
unique = S.size $ VG.foldr S.insert S.empty c
191191
-- Unboxed columns cannot have nulls since Maybe
192192
-- is not an instance of Unbox a
193-
in ColumnInfo cname (columnLength col) 0 0 unique columnType : acc
193+
in if cname == Nothing then acc else ColumnInfo (fromMaybe "" cname) (columnLength col) 0 0 unique columnType : acc
194194

195195
nulls :: Column -> Int
196196
nulls (OptionalColumn xs) = VG.length $ VG.filter isNothing xs

0 commit comments

Comments
 (0)