ContrastEncoder: missing buildmatrix with vector-valued mode gives "Nothing is not callable" instead of BUILDFUNC_MUST_BE_SPECIFIED
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 90/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- julia
- Ambito
- machine-learning
Direzione di ricerca
Inizia leggendo src/encoders/contrast_encoder/contrast_encoder.jl intorno a contrast_encoder_fit, in particolare la validazione della modalità e la chiamata a buildmatrix. Esegui i casi di riproduzione, quindi aggiorna i test esistenti in test/encoders/contrast_encoder.jl per coprire le modalità vettoriali contenenti :contrast o :hypothesis e le modalità AbstractVector{Symbol} diverse da Vector. Il lavoro è completato quando questi casi generano il previsto ArgumentError anziché MethodError o un errore di modalità non supportata, mantenendo coperti i comportamenti esistenti per i valori scalari.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When mode is given as a vector, the buildmatrix check in contrast_encoder_fit never runs, so forgetting buildmatrix for a :contrast / :hypothesis feature gives a confusing MethodError instead of the intended BUILDFUNC_MUST_BE_SPECIFIED message.
The check is:
if mode in (:contrast, :hypothesis)
buildmatrix === nothing && throw(ArgumentError(BUILDFUNC_MUST_BE_SPECIFIED))
end
For mode = [:contrast, :dummy] this is [:contrast, :dummy] in (:contrast, :hypothesis), which is false, so we fall through to buildmatrix(name, k) with buildmatrix === nothing at L109/L113.
Reproduction
using MLJTransforms, MLJBase, CategoricalArrays
X = (A = categorical(["a", "b", "c", "a"]), B = categorical(["x", "y", "x", "y"]))
# scalar mode: helpful error
try
MLJTransforms.contrast_encoder_fit(X, [:A]; mode = :contrast, ignore = false)
catch e
println("scalar mode -> ", sprint(showerror, e))
end
# vector mode: check is skipped
try
MLJTransforms.contrast_encoder_fit(X, [:A, :B]; mode = [:contrast, :dummy], ignore = false)
catch e
println("vector mode -> ", sprint(showerror, e))
end
# same through the MLJ interface
enc = ContrastEncoder(features = [:A, :B], mode = [:hypothesis, :dummy], ignore = false)
mach = machine(enc, X)
try
fit!(mach, verbosity = 0)
catch e
println("machine -> ", sprint(showerror, e)[1:min(end, 300)])
end
Output:
scalar mode -> ArgumentError: In ContrastEncoder with mode=:contrast or mode=:hypothesis, the `buildmatrix` argument must be specified.
vector mode -> MethodError: objects of type Nothing are not callable.
In case you did not try calling it explicitly, check if a Nothing has been passed as an argument to a method that expects a callable instead.
The object of type `Nothing` exists, but no method is defined for this combination of argument types when trying to treat it as a callable object.
┌ Error: Problem fitting the machine machine(ContrastEncoder(features = [:A, :B], …), …).
└ @ MLJBase ~/.julia/packages/MLJBase/lZsbe/src/machines.jl:758
[ Info: Running type checks...
[ Info: Type checks okay.
machine -> MethodError: objects of type Nothing are not callable.
In case you did not try calling it explicitly, check if a Nothing has been passed as an argument to a method that expects a callable instead.
The object of type `Nothing` exists, but no method is defined for this combination of argument types wh
Expected: the vector case throws the same ArgumentError(BUILDFUNC_MUST_BE_SPECIFIED) as the scalar case.
Actual: MethodError: objects of type Nothing are not callable.
Related: non-Vector mode vectors
A nearby detail in the same block: the keyword is typed mode::Union{Symbol, AbstractVector{Symbol}} (and the struct allows AbstractVector{Symbol}), but the vector branch at L90 tests mode isa Vector{Symbol}. So any other AbstractVector{Symbol} skips the vector handling and the whole vector ends up treated as one mode:
modes = view([:sum, :dummy, :helmert], 1:2) # AbstractVector{Symbol}, not a Vector
MLJTransforms.contrast_encoder_fit(X, [:A, :B]; mode = modes, ignore = false)
ArgumentError: Mode [:sum, :dummy] is not supported.
Possible fix
Something like:
mode_is_vector = mode isa AbstractVector{Symbol}
...
modes = mode_is_vector ? mode : (mode,)
if any(in((:contrast, :hypothesis)), modes)
buildmatrix === nothing && throw(ArgumentError(BUILDFUNC_MUST_BE_SPECIFIED))
end
plus a test next to the existing BUILDFUNC_MUST_BE_SPECIFIED one in test/encoders/contrast_encoder.jl (which currently only covers the scalar mode = :contrast case). Happy to open a PR if this sounds right.
Versions
- MLJTransforms
devat d3e3db3 (v0.2.4) - Julia 1.13.3, MLJBase from the registry, Linux x86_64
- Lingua principale
- Julia
- Stelle
- 1
- Fork
- 5
- Merge medio
- 1g 20m
- PR unite (30g)
- 7
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JuliaAI/MLJTransforms.jl
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
JuliaAI/MLJTransforms.jl#107 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
JuliaAI/MLJTransforms.jl#106 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 Mezza giornata Idoneità per principianti 66/100
JuliaAI/MLJTransforms.jl#105 ·
I maintainer di solito rispondono entro 1 giorno
-
Add a `Transformer` wrapper for models that supervised that transformForse di nuovo libera @ablaom l’ha presa 240 giorni fa e non c’è nessuna pull request aperta. Apertaenhancement
JuliaAI/MLJTransforms.jl#52 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
JuliaAI/MLJTransforms.jl#39 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di JuliaAI/MLJTransforms.jl
Issue simili
-
The entrypoint deletes its manifest runfiles tree at exit even under TEST_TMPDIRForse già presa @TrapsterDK l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
periareon/rules_julia#64 ·
I maintainer di solito rispondono entro 1 giorno
-
tagbot-manual
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Add to "Why Wren.jl"Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
JuliaBayes/Wren.jl#370 · 3 commenti · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
CliMA/Oceananigans.jl#6603 ·
I maintainer di solito rispondono entro 1 giorno