`boxcox` in `UnivariateBoxCoxTransformer` throws the type `DomainError` instead of a `DomainError` instance

Đang mở Phù hợp với người mới
#119 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
julia
Lĩnh vực
machine-learning

Hướng nghiên cứu

Đọc src/transformers/other_transformers/univariate_boxcox_transformer.jl, đặc biệt là helper boxcox ở các dòng 26–33, và kiểm tra test/transformers/other_transformers/univariate_boxcox_transformer.jl. Bổ sung kiểm thử cho các đầu vào biến đổi không hợp lệ trong cả trường hợp tổng quát lẫn trường hợp lambda == 0, sau đó chạy tệp kiểm thử đó. Công việc hoàn tất khi các đường đi này ném ra các đối tượng DomainError có chi tiết hữu ích về giá trị gây lỗi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

The internal boxcox helper used by UnivariateBoxCoxTransformer does throw(DomainError) when c + x is out of range:

https://github.com/JuliaAI/MLJTransforms.jl/blob/d3e3db364f30bef397eddeae7f30a5e7967757fc/src/transformers/other_transformers/univariate_boxcox_transformer.jl#L26-L33

function boxcox(lambda, c, x::Real)
    c + x >= 0 || throw(DomainError)
    if lambda == 0.0
        c + x > 0 || throw(DomainError)
        return log(c + x)
    end
    return ((c + x)^lambda - 1)/lambda
end

That throws the DataType DomainError itself, not an exception object. So when you fit on positive data and later call transform on new data with a negative value, the error you get is not actually a DomainError. catch e; e isa DomainError is false, @test_throws DomainError fails, and the message is just DomainError with nothing about which value was bad.

Minimal example:

using MLJBase, MLJTransforms, Test
import MLJTransforms as MT

x = [1.0, 2.0, 3.0, 4.0, 5.0]
mach = machine(UnivariateBoxCoxTransformer(), x)
fit!(mach, verbosity=0)

try
    transform(mach, [-1.0, 2.0])
catch e
    @show e typeof(e) (e isa DomainError) (e === DomainError)
    print("showerror: "); showerror(stdout, e); println()
end

# lambda == 0 branch, same thing
try
    MT.boxcox(0.0, 0.0, 0.0)
catch e
    @show e typeof(e) (e isa DomainError)
end

# for comparison, what Base throws
try
    log(-1.0)
catch e
    @show typeof(e) (e isa DomainError)
end

@test_throws DomainError transform(mach, [-1.0])

Output:

fitted_params(mach) = (λ = 0.98, c = 0.0)
e = DomainError
typeof(e) = DataType
e isa DomainError = false
e === DomainError = true
showerror: DomainError
e = DomainError
typeof(e) = DataType
e isa DomainError = false
typeof(e) = DomainError
e isa DomainError = true

test_throws: Test Failed at boxcox.jl:35
  Expression: transform(mach, [-1.0])
    Expected: DomainError
      Thrown: DataType
      DomainError
      Stacktrace:
        [1] boxcox
          @ src/transformers/other_transformers/univariate_boxcox_transformer.jl:27 [inlined]
        ...
        [5] boxcox(lambda::Float64, c::Float64, v::Vector{Float64})
          @ MLJTransforms src/transformers/other_transformers/univariate_boxcox_transformer.jl:35
        [6] transform
          @ src/transformers/other_transformers/univariate_boxcox_transformer.jl:70 [inlined]

Expected: an actual DomainError instance with the offending value and a short hint, e.g.

c + x >= 0 || throw(DomainError(x, "Box-Cox transformation requires x + c >= 0 (c = $c)."))

and the same for the lambda == 0 branch (x + c > 0).

Actual: the type DomainError is thrown, so it doesn't match DomainError in catch/@test_throws and the message carries no information.

The existing test in test/transformers/other_transformers/univariate_boxcox_transformer.jl only covers the round trip, so nothing exercises this path right now. A @test_throws DomainError for a negative input at transform time (and for 0.0 when λ == 0) would cover it.

Versions: Julia 1.13.4, MLJTransforms 0.2.4 (dev at d3e3db3), MLJBase 1.15.4.

Ngôn ngữ chính
Julia
Star
1
Fork
5
Merge trung bình
6 giờ 44 phút
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của JuliaAI/MLJTransforms.jl

Tất cả issue của JuliaAI/MLJTransforms.jl

Issue tương tự

Thêm issue về Julia

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.