`boxcox` in `UnivariateBoxCoxTransformer` throws the type `DomainError` instead of a `DomainError` instance
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- julia
- Domain
- machine-learning
Research direction
Read src/transformers/other_transformers/univariate_boxcox_transformer.jl, especially the boxcox helper at lines 26–33, and inspect test/transformers/other_transformers/univariate_boxcox_transformer.jl. Add coverage for invalid transform inputs in both the general and lambda == 0 cases, then run that test file. Done means these paths throw DomainError instances with useful details about the offending value.
Written by the indexing model from the issue text.
Description
The internal boxcox helper used by UnivariateBoxCoxTransformer does throw(DomainError) when c + x is out of range:
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.
- Dominant language
- Julia
- Stars
- 1
- Forks
- 5
- Avg merge
- 6h 44m
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaAI/MLJTransforms.jl
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JuliaAI/MLJTransforms.jl#120 ·
Maintainers usually reply within 1 day
-
UnivariateStandardizer has human_name "single variable discretizer"Possibly taken @ablaom claimed this 2 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
JuliaAI/MLJTransforms.jl#117 · 1 comment · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
-
TargetEncoder: m = :auto uses the inverse of the empirical Bayes ratio and gives NaN for single-row levelsPossibly taken @EssamWisam claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JuliaAI/MLJTransforms.jl#113 · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
-
ContinuousEncoder docstring: wrong `drop_last` default and nonexistent `ordered_factors` optionPossibly taken @ablaom claimed this 5 days ago. Opendocumentation
Difficulty 1/5 Under an hour Newbie friendliness 88/100
JuliaAI/MLJTransforms.jl#109 · 1 comment · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
JuliaAI/MLJTransforms.jl#108 · 1 comment ·
Maintainers usually reply within 1 day
All issues in JuliaAI/MLJTransforms.jl
Similar issues
-
Release CorleoneInverse as 0.1.1Possibly taken @ChrisRackauckas-Claude claimed this 1 day ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 78/100
SciML/Corleone.jl#200 · 1 comment ·
Maintainers usually reply within 1 day
-
tagbot-manual
Difficulty 1/5 Under an hour Newbie friendliness 82/100
SciML/MonteCarloIntegration.jl#49 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
jaff-chemistry/jaff#231 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SciML/RecursiveArrayTools.jl#701 ·
-
DPRKN6 docstring: the velocity interpolant is 5th order, not 6thPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
SciML/OrdinaryDiffEq.jl#5175 ·
Maintainers usually reply within 1 day