JuliaAI / JuliaAI/LearnAPI.jl

LearnAPI.clone calls the advertised keyword constructor positionally

Open Beginner friendly
#67 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
45
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Hello,

While working on a downstream package (OnlineML.jl), I noticed a discrepancy between the constructor trait documentation and the actual implementation of LearnAPI.clone.

The constructor trait documentation requires a keyword constructor and demonstrates reconstruction with:

LearnAPI.constructor(learner)(; named_properties...)

However, LearnAPI.clone currently collects the learner properties and passes them as positional arguments by splatting a NamedTuple without a semicolon:

LearnAPI.constructor(learner)(NamedTuple{names}(new_values)...)

Minimal reproducer
using LearnAPI

Base.@kwdef struct DemoLearner
    rate::Float64 = 0.1
end

LearnAPI.constructor(::DemoLearner) = DemoLearner

LearnAPI.clone(DemoLearner(); rate=0.2)

Expected Behavior

DemoLearner(0.2) should be returned through the documented keyword-constructor contract (e.g., if clone splatted with a semicolon: ; NamedTuple{names}(new_values)...).

Actual Behavior

clone calls DemoLearner(0.2) positionally. A learner that intentionally provides only the documented keyword constructor (like the one generated by Base.@kwdef without a custom positional fallback) raises a MethodError.

Additional Context

Currently, downstream learners with properties must provide an additional positional constructor solely for compatibility with LearnAPI.clone.

Fixing this by changing clone to splat the named tuple as keywords (;) would align the code with the documentation. However, please note that changing clone upstream may affect existing learners that have already implemented (or only implemented) a positional constructor to work around this, so an upstream compatibility transition/deprecation phase might be necessary.

Affected code

https://github.com/JuliaAI/LearnAPI.jl/blob/b17f7dea942464c626e2f7c5267751f7de3705ea/src/clone.jl#L26

Possible change

return LearnAPI.constructor(learner)(; NamedTuple{names}(new_values)...) 

PS : this issue have been filled with AI assistance

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/clone.jl around line 26 and compare the constructor call with the keyword-constructor contract described in the issue. Run the DemoLearner reproducer to verify the failure, then confirm that clone works with the documented keyword-only constructor and consider the compatibility impact on existing positional constructors.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
api, machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.