MissingnessEncoder / CardinalityReducer constructors throw MethodError for a custom label dict with concrete value type
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 半日
- 初心者へのやさしさ
- 66/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
調査の方向性
The bug is in the struct definitions and keyword constructors of MissingnessEncoder and CardinalityReducer, in src/encoders/missingness_encoding/interface_mlj.jl and src/transformers/cardinality_reducer/interface_mlj.jl. Both reuse one type parameter A for features and for the value type of the label dict, so start there and reproduce with the two constructor calls from the issue. Done when both constructors accept Dict(AbstractString => "NA")-style dicts with concrete value types, the default construction still works, and the existing tests pass.
索引モデルが issue の本文から書いたものです。
説明
MissingnessEncoder and CardinalityReducer throw a MethodError as soon as you pass your own label_for_missing / label_for_infrequent dict, unless the dict's value type happens to be Any.
For example, if I only want to change the label used for string columns:
using MLJTransforms, MLJBase, CategoricalArrays
MissingnessEncoder(label_for_missing = Dict(AbstractString => "NA"))
CardinalityReducer(label_for_infrequent = Dict(AbstractString => "rare"))
Output:
ERROR: MethodError: no method matching MissingnessEncoder(::Vector{Symbol}, ::Bool, ::Bool, ::Dict{DataType, String})
The type `MissingnessEncoder` exists, but no method is defined for this combination of argument types when trying to construct it.
Closest candidates are:
MissingnessEncoder(::A, ::Bool, ::Bool, ::Dict{T, A}) where {T<:Type, A}
@ MLJTransforms src/encoders/missingness_encoding/interface_mlj.jl:8
MissingnessEncoder(; features, ignore, ordered_factor, label_for_missing)
@ MLJTransforms src/encoders/missingness_encoding/interface_mlj.jl:15
ERROR: MethodError: no method matching CardinalityReducer(::Vector{Symbol}, ::Bool, ::Bool, ::Int64, ::Dict{DataType, String})
The type `CardinalityReducer` exists, but no method is defined for this combination of argument types when trying to construct it.
Closest candidates are:
CardinalityReducer(::A, ::Bool, ::Bool, ::R, ::Dict{T, A}) where {R<:Real, T<:Type, A}
@ MLJTransforms src/transformers/cardinality_reducer/interface_mlj.jl:9
CardinalityReducer(; features, ignore, ordered_factor, min_frequency, label_for_infrequent)
@ MLJTransforms src/transformers/cardinality_reducer/interface_mlj.jl:17
The same dict works fine with the functional API:
X = (A = categorical(["a", "b", missing, "a"]),)
c = MLJTransforms.missingness_encoder_fit(X; label_for_missing = Dict(AbstractString => "NA"))
MLJTransforms.missingness_encoder_transform(X, c) # levels become ["a", "b", "NA"] as expected
and the MLJ model also works if I force the dict to Dict{Type,Any}(AbstractString => "NA"), so it's only the struct typing that gets in the way.
Cause
Both structs use the same type parameter A for the features field and for the value type of the label dict:
mutable struct MissingnessEncoder{T <: Type, A <: Any} <: Unsupervised
features::A
...
label_for_missing::Dict{T, A}
end
(src/encoders/missingness_encoding/interface_mlj.jl#L4-L12, and the same pattern for label_for_infrequent in src/transformers/cardinality_reducer/interface_mlj.jl#L4-L14)
The defaults only construct because Dict(AbstractString => "missing", Char => 'm') has value type Any, so A = Any and features::Any matches anything (MissingnessEncoder() gives MissingnessEncoder{DataType, Any}). Any dict with a concrete value type (String, Char, Int, ...) forces A to be that type, and then features = Symbol[] no longer matches.
Expected
MissingnessEncoder(label_for_missing = Dict(AbstractString => "NA")) and CardinalityReducer(label_for_infrequent = Dict(AbstractString => "rare")) should construct, since that is the documented Dict{<:Type, <:Any} form. Giving the dict values their own type parameter (or not tying them to features' type) looks like it would be enough.
Versions
- MLJTransforms v0.2.4 (
devat d3e3db3) - MLJBase v1.15.3, MLJModelInterface v1.12.2, CategoricalArrays v1.1.1
- Julia 1.13.3
- 主要言語
- Julia
- スター
- 1
- フォーク
- 5
- 平均マージ
- 1日 20分
- マージ済み PR(30日)
- 7
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaAI/MLJTransforms.jl のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
JuliaAI/MLJTransforms.jl#108 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
JuliaAI/MLJTransforms.jl#107 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
JuliaAI/MLJTransforms.jl#106 ·
メンテナーはふだん 1 日以内に返信
-
Add a `Transformer` wrapper for models that supervised that transform再び着手できるかも @ablaom が 240 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンenhancement
JuliaAI/MLJTransforms.jl#52 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
JuliaAI/MLJTransforms.jl#39 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
JuliaAI/MLJTransforms.jl の issue をすべて見る
似ている issue
-
The entrypoint deletes its manifest runfiles tree at exit even under TEST_TMPDIR対応中かも @TrapsterDK が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
periareon/rules_julia#64 ·
メンテナーはふだん 1 日以内に返信
-
tagbot-manual
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
Add to "Why Wren.jl"オープン
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
JuliaBayes/Wren.jl#370 · コメント 3 件 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
JuliaGPU/GemmKernels.jl#232 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100