You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let adata = [:abstract_type_var] where :abstract-type-var will have an abstract type SuperType and the outcomes of :abstract-type-var will have types such as A <: SuperType or B <: SuperType
One would expect after running the run! command to collect data that the column would look like: adf.abstract_type_var = [A(),B(),C()] where each row has a different primitive type, but they are all the same abstract type.
Statement
Function: run! does not allow for heterogeneous primitive types which are subtypes or a homogeneous abstract type.
Minimal Working Example
abstract type SuperType endstruct A <:SuperTypeendstruct B <:SuperTypeend@agentstructTestAgent(NoSpaceAgent)
type_agent::SuperTypeend# Set up modelfunctioninitialize_model(;num_agents =10, seed =123)
rng =MersenneTwister(seed)
properties = ()
model =StandardABM(TestAgent;
agent_step! = agent_step!,
properties = properties,
rng = rng,
scheduler = Schedulers.Randomly(),
warn =false
)
# Add agentsfor _ in Base.OneTo(num_agents)
add_agent!(
TestAgent,
model,
rand(abmrng(model),[A(),B()]))
endreturn model
endfunctionagent_step!(agent,model)
agent.type_agent =rand(abmrng(model),[A(),B()])
end# Run a sample
stable_params = (;num_agents =10,seed =2314)
model =initialize_model(;stable_params...)
adata = [:type_agent]
steps =60
adf, _ =run!(model, steps; adata)
This gives the following output
julia> adf, _ =run!(model, steps; adata)
┌ Error: Error adding value to column :type_agent. Maybe you forgot passing `promote=true`?
└ @ DataFrames C:\Users\jonathan.miller\.julia\packages\DataFrames\kcA9R\src\dataframe\insertion.jl:369
ERROR: MethodError: Cannot `convert` an object of type B to an object of type A
The function`convert` exists, but no method is defined for this combination of argument types.
Closest candidates are:convert(::Type{T}, ::T) where T
@ Base Base.jl:126
Stacktrace:
[1] push!(a::Vector{A}, item::B)
@ Base .\array.jl:1244
[2] _append!(a::Vector{A}, ::Base.HasShape{1}, iter::Vector{SuperType})
@ Base .\array.jl:1322
[3] append!(a::Vector{A}, iter::Vector{SuperType})
@ Base .\array.jl:1313
[4] _append_or_prepend!(df1::DataFrame, df2::DataFrame; cols::Symbol, promote::Bool, atend::Bool)
@ DataFrames C:\Users\jonathan.miller\.julia\packages\DataFrames\kcA9R\src\dataframe\insertion.jl:308
[5] _append_or_prepend!
@ C:\Users\jonathan.miller\.julia\packages\DataFrames\kcA9R\src\dataframe\insertion.jl:239 [inlined]
[6] append!(df1::DataFrame, df2::DataFrame)
@ DataFrames C:\Users\jonathan.miller\.julia\packages\DataFrames\kcA9R\src\dataframe\insertion.jl:93
[7] collect_agent_data!(df::DataFrame, model::StandardABM{…}, properties::Vector{…}, step::Int64; kwargs::@Kwargs{…})
@ Agents C:\Users\jonathan.miller\.julia\packages\Agents\eKASH\src\simulations\collect.jl:474
[8] collect_agent_data!
@ C:\Users\jonathan.miller\.julia\packages\Agents\eKASH\src\simulations\collect.jl:458 [inlined]
[9] run!(model::StandardABM{…}, n::Int64; when::Int64, when_model::Int64, mdata::Nothing, adata::Vector{…}, obtainer::Function, showprogress::Bool, init::Bool, dt::Float64)
@ Agents C:\Users\jonathan.miller\.julia\packages\Agents\eKASH\src\simulations\collect.jl:137
[10] top-level scope
@ c:\Users\jonathan.miller\Projects\genetic_modelling\src\julia-version\insect_sex_mating\src\testing_insect_sex_mating.jl:308
Some type information was truncated. Use `show(err)` to see complete types.
This is possible directly in DataFrames.jl
using DataFrames
vec_types = [A(),B()]
df =DataFrame(abstract_type_var = vec_types)
df
Describe the bug
Mini scenario
Let
adata = [:abstract_type_var]
where:abstract-type-var
will have an abstract typeSuperType
and the outcomes of:abstract-type-var
will have types such asA <: SuperType
orB <: SuperType
One would expect after running the
run!
command to collect data that the column would look like:adf.abstract_type_var = [A(),B(),C()]
where each row has a different primitive type, but they are all the same abstract type.Statement
Function:
run!
does not allow for heterogeneous primitive types which are subtypes or a homogeneous abstract type.Minimal Working Example
This gives the following output
This is possible directly in
DataFrames.jl
gives
Agents.jl version
Agents v6.1.9
Julia version
Version 1.11.0 (2024-10-07)
The text was updated successfully, but these errors were encountered: