Skip to content

.csv.read turns a malformed row or cell into nulls without an error; ask for a strict option #1885

Done

Description

@vbmithr

Summary

.csv.read checks the file's columns against the schema, but not its rows. A row with too few
cells, too many, or a cell that does not parse as its column's type is read without any error:
missing and unparseable cells become the type's null, extra cells are dropped. A null then flows
through later arithmetic and aggregations without complaint, so a bad cell in a feed ends up stored
as a null value.

Repro

bad.csv:

a,b,c
1,x,2.5
2,y
3,z,4.5,99
foo,w,1.5
5,v,abc
(.csv.read [I64 SYM F64] "bad.csv")
; (table [a b c] (list [1 2 3 0Nl 5] [x y z w v] [2.5 0Nf 4.5 1.5 0Nf]))
Line What happens
2,y (one cell short) c reads as 0Nf
3,z,4.5,99 (one cell too many) the extra cell is dropped
foo,w,1.5 (text in an I64 column) a reads as 0Nl
5,v,abc (text in an F64 column) c reads as 0Nf

The same holds for a timestamp column: 2026-11-27 (a date without a time) reads as 0Np.

What is already an error, for contrast: a schema with a different number of types than the file's
header has columns (csv read: schema has 2 types but file has 3 columns).

Why it matters

A loader that reads a vendor's CSV and writes the rows to a database cannot tell a bad cell from
a missing value, and a null price is stored. The only defence today is to read the table back and
count nulls in every column that must not have one, for every file, which each caller has to
rediscover.

Request

An option on .csv.read, in the style of the options it already takes, for example
{strict: true}: a row whose cell count differs from the schema's, or a cell that does not parse as
its column's type, is an error naming the line and the column
(csv read: line 3: expected 3 cells, got 2, csv read: line 5, column c: "abc" is not an F64).
Lenient stays the default if changing it would break existing code; if it does not, strict as the
default with a lenient option would be the safer contract. An empty cell would still be a null
where the column is meant to hold one, which is the caller's to say, for example with a list of
nullable columns.

Seen on rayforce-git 3.0.1.r684.g266f9ebe6.

Activity

  1. vbmithr commented on Nov 27, 2026

    @vbmithr
    ContributorAuthor

    A concrete case of the same problem, and probably the most common one: a date without a time in a
    TIMESTAMP column.

    d.csv:

    symbol,day,v
    US10Y,2026-11-27,4.94
    US2Y,2026-11-25,4.61
    
    (.csv.read [SYM TIMESTAMP F64] "d.csv")   ; the `day` column is [0Np 0Np]: no error
    (.csv.read [SYM DATE F64] "d.csv")        ; [2026.11.27 2026.11.25], as expected
    (as 'TIMESTAMP (at (.csv.read [SYM DATE F64] "d.csv") 'day))
                                              ; [2026.11.27D00:00:00.000000000 2026.11.25D00:00:00.000000000]

    The DATE column is the explicit way and works, so the request here is only the error: under the
    strict option, 2026-11-27 in a TIMESTAMP column should fail with the line and column, as any other
    cell that does not parse. Whether a TIMESTAMP column should also accept a bare date as midnight is a
    separate question for the maintainers; it is unambiguous in a type with no zone, but it blurs the
    line with DATE.

    Same build: rayforce-git 3.0.1.r684.g266f9ebe6.

  2. singaraiona commented on Nov 27, 2026

    @singaraiona
    Collaborator

    Decided: lenient stays the default, and .csv.read gains an opt-in {strict: true} (a leading options dict, as .csv.splayed and .csv.parted take {compress: ...}; they take strict too, since they share the reader). Under it a row with the wrong cell count, a malformed quoted cell, or a non-empty cell that does not parse as its column's type is a parse error naming the file, the line and the column:

    .csv.read "bad.csv": line 3: expected 3 cells, got 2
    .csv.read "bad.csv": line 6, column c: "abc" is not an F64
    

    Strict refuses exactly the non-empty cells lenient turns into nulls, so every value lenient reads reads the same (your 2026-11-27 in a TIMESTAMP column is refused; a number with surrounding spaces is too, as lenient reads it as a null). An empty cell is a null in both modes; per-column nullability is not part of this. A blank line is one empty cell, so an error unless the table has one column. The line counts the header and newlines inside quoted cells, and with several bad rows the first in the file is reported, also under the parallel reader. The default path is unchanged in code and speed.

    #1888

  3. added 4 commits that reference this issue on Nov 27, 2026
    b3b9f73
    f1e16db
    21bbdea
    2565a77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions