SentinelArrays.jl icon indicating copy to clipboard operation
SentinelArrays.jl copied to clipboard

reducing over an empty collection is not allowed; consider supplying `init` to the reducer

Open kafisatz opened this issue 2 years ago • 0 comments

I have a date vector (originally from CSV.read) on which extrema fails, see below Interestingly when I copy the data, things work. I.e. extrema(dd[1:end]) works

below is an MWE.

julia> using Dates

julia> using DataFrames

julia> using CSV

julia> #p = CSV.read(raw"C:\temp\ori2c.csv",DataFrame,dateformat="dd.mm.yyyy",copycols=true,stringtype=String,pool=false);

julia> fi = raw"https://gist.githubusercontent.com/kafisatz/e64a61727d8817a4433cecf17144dd55/raw/f49241d0d6b177c10d23809750b1c7af21f53adf/ori2c.csv";

julia> p = CSV.read(download(fi),DataFrame,dateformat="dd.mm.yyyy",copycols=true,stringtype=String,pool=false);

julia> addtldf=DataFrame(a=String[],date=Date[],b=Int[],c=Int[],date2=Date[]);

julia> append!(p,addtldf);

julia> extrema(p.date)
ERROR: MethodError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
  [1] reduce_empty(op::Base.MappingRF{Base.ExtremaMap{typeof(identity)}, typeof(Base._extrema_rf)}, #unused#::Type{Date})
    @ Base .\reduce.jl:356
  [2] reduce_empty_iter
    @ .\reduce.jl:379 [inlined]
  [3] mapreduce_empty_iter(f::Function, op::Function, itr::Vector{Date}, ItrEltype::Base.HasEltype)
    @ Base .\reduce.jl:375
  [4] _mapreduce
    @ .\reduce.jl:427 [inlined]
  [5] _mapreduce_dim
    @ .\reducedim.jl:365 [inlined]
  [6] #mapreduce#765
    @ .\reducedim.jl:357 [inlined]
  [7] mapreduce
    @ .\reducedim.jl:357 [inlined]
  [8] #_extrema#791
    @ .\reducedim.jl:999 [inlined]
  [9] _extrema
    @ .\reducedim.jl:999 [inlined]
 [10] #extrema#789
    @ .\reducedim.jl:995 [inlined]
 [11] extrema
    @ .\reducedim.jl:995 [inlined]
 [12] extrema
    @ C:\Users\bernhard.konig\.julia\packages\SentinelArrays\BcfVF\src\chainedvector.jl:793 [inlined]
 [13] extrema(x::SentinelArrays.ChainedVector{Date, Vector{Date}})
    @ SentinelArrays C:\Users\bernhard.konig\.julia\packages\SentinelArrays\BcfVF\src\chainedvector.jl:787
 [14] top-level scope
    @ REPL[9]:1

julia> extrema(p.date[1:end])
(Date("2023-02-01"), Date("2023-05-03"))

julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65e (2023-01-08 06:45 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 32 × AMD Ryzen 9 5950X 16-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, znver3)
  Threads: 16 on 32 virtual cores
Environment:
  JULIA_NUM_THREADS = 16
  JULIA_EDITOR = "code"

julia> 


[a93c6f00] DataFrames v1.5.0    
[336ed68f] CSV v0.10.9  
[91c51154] SentinelArrays v1.3.18

ori2c.csv

kafisatz avatar May 04 '23 10:05 kafisatz