Skip to content

toSeparated doesn't respect the null mask #211

Description

@chfin

Describe the bug

When using toSeparated (or toCSV/toTSV), nullable columns are not handled correctly. toSeparated uses showElement, which ignores the column's null mask and directly gets the value from the column vector. For unboxed columns, this returns an incorrect default value, for boxed vectors, it throws a null pointer exception.

To Reproduce

{-# LANGUAGE OverloadedStrings #-}
import DataFrame qualified as D

dfUnboxed = D.fromNamedColumns [("a", D.fromList [Nothing, Just 1 :: Maybe Int])]

dfBoxed = D.fromNamedColumns [("a", D.fromList [Nothing, Just [] :: Maybe [Int]])]

λ> D.toSeparated ',' dfUnboxed
"a\n0\n1\n"

λ> D.toSeparated ',' dfBoxed
"*** Exception: fromMaybeVec: Nothing slot

Expected behavior
toSeparated should check the nullable mask and return a null token (empty string?) for null cells, similar to show.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions