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

Explicit error for unequal column sizes

Open adigitoleo opened this issue 3 years ago • 1 comments

Low priority, QOL issue. The constructors could throw an error if the column sizes don't match. Currently they are quietly accepted until the table is shown/acessed, and then:

julia> t = Table(a = [1, 2, 3], b = [2.0, 4.0])
Table with 2 columns and 3 rowsError showing value of type Table{NamedTuple{(:a, :b), Tuple{Int64, Float64}}, 1, NamedTuple{(:a, :b), Tuple{Vector{Int64}, Vector{Float64}}}}:
ERROR: BoundsError: attempt to access 3-element Table{NamedTuple{(:a, :b), Tuple{Int64, Float64}}, 1, NamedTuple{(:a, :b), Tuple{Vector{Int64}, Vector{Float64}}}} at index [3]
Stacktrace:
  [1] throw_boundserror(A::Table{NamedTuple{(:a, :b), Tuple{Int64, Float64}}, 1, NamedTuple{(:a, :b), Tuple{Vector{Int64}, Vector{Float64}}}}, I::Tuple{Int64})
    @ Base ./abstractarray.jl:691
  [2] checkbounds
    @ ./abstractarray.jl:656 [inlined]
  [3] getindex(t::Table{NamedTuple{(:a, :b), Tuple{Int64, Float64}}, 1, NamedTuple{(:a, :b), Tuple{Vector{Int64}, Vector{Float64}}}}, i::Int64)
    @ TypedTables ~/vcs/TypedTables.jl/src/Table.jl:128
  [4] showtable(io::IOContext{Base.TTY}, t::Any, keyname::Nothing)
    @ TypedTables ~/vcs/TypedTables.jl/src/show.jl:141
  [5] showtable
    @ ~/vcs/TypedTables.jl/src/show.jl:102 [inlined]
[...]

adigitoleo avatar Jan 05 '22 06:01 adigitoleo

Yes, I think we should look at this. The dictionary-based tables have some checks now I believe.

andyferris avatar Jan 28 '22 05:01 andyferris