Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Type Instability of Schema

Aperta
#253 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
julia
Ambito
data

Direzione di ricerca

Start by running the Julia MWE with @code_warntype, then inspect schema, apply_schema, and modelcols to trace the inferred types. Compare the function results with the step-by-step REPL behavior shown in the issue. Done means establishing whether the instability is a real package problem and either fixing it or documenting why the issue can be closed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

When I was doing some testing, there seems to be some type instability related to the Schema Struct. Just as a MWE:

f = @formula(a ~ b + c)
data = (
    a = randn(1000),
    b = randn(1000),
    c = randn(1000)
)
function simple_function(f, data)
    sch = apply_schema(f, schema(f, data))
    sch.lhs
end

@code_warntype simple_function(f, data)
# MethodInstance for simple_function(::FormulaTerm{Term, Tuple{Term, Term}}, ::NamedTuple{(:a, :b, :c), Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}}})
#     from simple_function(f, data) in Main at c:\Users\underwjo\Documents\GitHub\AbnormalReturns.jl\benchmark\run_benchmark.jl:203
#   Arguments
#     #self#::Core.Const(simple_function)
#     f::FormulaTerm{Term, Tuple{Term, Term}}
#     data::NamedTuple{(:a, :b, :c), Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}}}
#   Locals
#     sch::FormulaTerm
#   Body::Any
#   1 ─ %1 = Main.schema(f, data)::StatsModels.Schema
#   │        (sch = Main.apply_schema(f, %1))
#   │   %3 = Base.getproperty(sch, :lhs)::Any
#   └──      return %3

Similarly, if the last line of the function was modelcols(sch, data), then the compiler interprets the return type as Tuple{Any, Any}.

Maybe this isn't really a problem since Julia can optimize it later. For example, just doing each step in the REPL and then calling modelcols(sch, data), the compiler correctly interprets the type as Tuple{Vector{Float64}, Matrix{Float64}}. Therefore, if this isn't really a problem, then please go ahead and close this issue.

Lingua principale
Julia
Stelle
250
Fork
35
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di JuliaStats/StatsModels.jl

Tutte le issue di JuliaStats/StatsModels.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.