Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

append! NamedTuple to Table lead to strange behavior #116

Open
femtotrader opened this issue Apr 25, 2024 · 2 comments
Open

append! NamedTuple to Table lead to strange behavior #116

femtotrader opened this issue Apr 25, 2024 · 2 comments

Comments

@femtotrader
Copy link

Hello,

I was trying to append! a NamedTuple to Table... and noticed this odd behiavor

julia> t = Table(a = [1, 2, 3], b = [2.0, 4.0, 6.0])
Table with 2 columns and 3 rows:
     a  b
   ┌───────
 11  2.0
 22  4.0
 33  6.0

julia> append!(t, (a=4, b=8.0))
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type @NamedTuple{a::Int64, b::Float64}

Closest candidates are:
  convert(::Type{NT}, ::NT) where {names, T<:Tuple, NT<:NamedTuple{names, T}}
   @ Base namedtuple.jl:184
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84
  convert(::Type{NT}, ::NamedTuple{names}) where {names, T<:Tuple, NT<:NamedTuple{names, T}}
   @ Base namedtuple.jl:186
  ...

Stacktrace:
 [1] setindex!
   @ C:\Users\femto\.julia\packages\TypedTables\ItVth\src\Table.jl:142 [inlined]
 [2] _append!
   @ .\array.jl:1201 [inlined]
 [3] append!(a::Table{@NamedTuple{…}, 1, @NamedTuple{…}}, iter::@NamedTuple{a::Int64, b::Float64})
   @ Base .\array.jl:1187
 [4] top-level scope
   @ REPL[31]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> t
Table with 2 columns and 5 rows:
     a  b
   ┌────────────
 11  2.0
 22  4.0
 33  6.0
 43  1.0e-323
 53  1.0e-323

These 2 rows are intriguing

 4 │ 3  1.0e-323
 5 │ 3  1.0e-323

Any idea what is causing that?

Would it be possible to append! a NamedTuple to a Table (without creating a Table from NamedTuple)

Kind regards

@andyferris
Copy link
Member

Interesting.

The correct operation here is push! since you are attempting to add a single row to a collection of rows (and appending is for merging two tables).

I’m not sure what’s going on with the behavior above, I would need to take a look.

@femtotrader
Copy link
Author

Thanks @andyferris

julia> push!(t, (a=4, b=8.0))
Table with 2 columns and 4 rows:
     a  b
   ┌───────
 1 │ 1  2.0
 2 │ 2  4.0
 3 │ 3  6.0
 4 │ 4  8.0

works fine.

@femtotrader femtotrader changed the title append! NamedTuple to Table append! NamedTuple to Table lead to strange behavior Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants