Skip to content

zinfo(z) fails when no chunks of z are initialized #197

@bwalker1

Description

@bwalker1

The output of something like z = zcreate(Int64, 5, chunks=(1,), path="test.zarr") produces an error if you run zinfo(z)

ERROR: ArgumentError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
  [1] _empty_reduce_error()
    @ Base ./reduce.jl:319
  [2] mapreduce_empty(f::Function, op::Function, T::Type)
    @ Base ./reduce.jl:321
  [3] reduce_empty(op::Base.MappingRF{Zarr.var"#17#19"{DirectoryStore, String}, typeof(Base.add_sum)}, ::Type{String})
    @ Base ./reduce.jl:358
  [4] reduce_empty_iter
    @ ./reduce.jl:381 [inlined]
  [5] mapreduce_empty_iter(f::Function, op::Function, itr::Vector{String}, ItrEltype::Base.HasEltype)
    @ Base ./reduce.jl:377
  [6] _mapreduce(f::Zarr.var"#17#19"{DirectoryStore, String}, op::typeof(Base.add_sum), ::IndexLinear, A::Vector{String})
    @ Base ./reduce.jl:429
  [7] _mapreduce_dim
    @ ./reducedim.jl:337 [inlined]
  [8] mapreduce
    @ ./reducedim.jl:329 [inlined]
  [9] _sum
    @ ./reducedim.jl:987 [inlined]
 [10] sum
    @ ./reducedim.jl:983 [inlined]
 [11] storagesize(d::DirectoryStore, p::String)
    @ Zarr ~/Documents/GitHub/Zarr.jl/src/Storage/directorystore.jl:38
 [12] storagesize
    @ ~/Documents/GitHub/Zarr.jl/src/ZArray.jl:71 [inlined]
 [13] zinfo(io::Base.TTY, z::ZArray{Int64, 1, Zarr.BloscCompressor, DirectoryStore})
    @ Zarr ~/Documents/GitHub/Zarr.jl/src/ZArray.jl:91
 [14] zinfo(z::ZArray{Int64, 1, Zarr.BloscCompressor, DirectoryStore})
    @ Zarr ~/Documents/GitHub/Zarr.jl/src/ZArray.jl:86
 [15] top-level scope
    @ REPL[7]:1

Due to the implementation of storagesize(d::DirectoryStore,p). This could be fixed by using reduce instead of sum to give an explicit init value of 0. The issue is not present with the DictStore version:

julia> zinfo(zcreate(Int64, 5, chunks=(1,)))
Type                : ZArray
Data type           : Int64
Shape               : (5,)
Chunk Shape         : (1,)
Order               : C
Read-Only           : false
Compressor          : Zarr.BloscCompressor(0, 5, "lz4", 1)
Filters             : nothing
Store type          : Dictionary Storage
No. bytes           : 40
No. bytes stored    : 0
Storage ratio       : Inf
Chunks initialized  : 0/5

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