Skip to content

CSV.Chunks splits file into uneven chunks #1122

Closed

Description

@aris-mav

In the following example the "a" variable does not have a consistent size.

using CSV, DataFrames

number_of_lines = 10^6
CSV.write("data.csv", DataFrame(rand(number_of_lines, 10), :auto))

steps = 10

@time for chunk in CSV.Chunks("data.csv"; ntasks=steps)
    a = chunk |> DataFrame
    display(size((a)))
end

Please also have a look at this discourse post, for context.

Activity

  1. quinnj commented on Oct 15, 2026

    @quinnj
    Member

    [comment generated via AI] Since CSV 1.1.0 (#1204), each batch is a byte window of chunkbytes (64 MiB by default) that ends at a row boundary, so every batch except the last has about the same size, whatever ntasks is. Checked on main: a 10.8 MB file with chunkbytes=4 MiB gives batches of 155,345, 155,345, and 89,310 rows. For about N equal batches, pass chunkbytes=cld(filesize(path), N).

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