Skip to content

Commit 63e4e4d

Browse files
committed
add docstring to doc_header
1 parent 781e5fd commit 63e4e4d

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed

src/metadata_utils.jl

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,80 @@ function metadata_model(
134134
parentmodule(T).eval(ex)
135135
end
136136

137-
function doc_header(model)
138-
name = MLJModelInterface.name(model)
139-
human_name = MLJModelInterface.human_name(model)
140-
package_name = MLJModelInterface.package_name(model)
141-
package_url = MLJModelInterface.package_url(model)
142-
params = MLJModelInterface.hyperparameters(model)
137+
# TODO: After `human_name` trait is added as model trait, include in
138+
# example given in the docstring for `doc_header`.
139+
140+
"""
141+
MLJModelInterface.doc_header(SomeModelType)
142+
143+
Return a string suitable for interpolation in the document string of
144+
an MLJ model type. In the example given below, the header expands to
145+
something like this:
146+
147+
> `FooRegressor`
148+
>
149+
>Model type for foo regressor, based on [FooRegressorPkg](http://existentialcomics.com/).
150+
>
151+
>From MLJ, the type can be imported using
152+
>
153+
>
154+
> `FooRegressor = @load FooRegressor pkg=FooRegressorPkg`
155+
>
156+
>Construct an instance with default hyper-parameters using the syntax
157+
>`model = FooRegressor()`. Provide keyword arguments to override
158+
>hyper-parameter defaults, as in `FooRegressor(a=...)`.
159+
160+
Ordinarily `doc_header` is used in document strings defined *after*
161+
the model type definition, as `doc_header` assumes model traits (in
162+
particular, `package_name` and `package_url`) to be defined; see also
163+
[`MLJModelInterface.metadata_pkg`](@ref).
164+
165+
166+
### Example
167+
168+
Suppose a model type and traits have been defined by:
169+
170+
```
171+
mutable struct FooRegressor
172+
a::Int
173+
b::Float64
174+
end
175+
176+
metadata_pkg(FooRegressor,
177+
name="FooRegressorPkg",
178+
uuid="10745b16-79ce-11e8-11f9-7d13ad32a3b2",
179+
url="http://existentialcomics.com/",
180+
)
181+
metadata_model(FooRegressor,
182+
input=Table(Continuous),
183+
target=AbstractVector{Continuous},
184+
descr="La di da")
185+
```
186+
187+
Then the docstring is defined post-facto with the following code:
188+
189+
```
190+
const HEADER = MLJModelInterface.doc_header(FooRegressor)
191+
192+
@doc \"\"\"
193+
\$HEADER
194+
195+
### Training data
196+
197+
In MLJ or MLJBase, bind an instance `model` ...
198+
199+
<rest of doc string goes here>
200+
201+
\"\"\" FooRegressor
202+
```
203+
204+
"""
205+
function doc_header(SomeModelType)
206+
name = MLJModelInterface.name(SomeModelType)
207+
human_name = MLJModelInterface.human_name(SomeModelType)
208+
package_name = MLJModelInterface.package_name(SomeModelType)
209+
package_url = MLJModelInterface.package_url(SomeModelType)
210+
params = MLJModelInterface.hyperparameters(SomeModelType)
143211

144212
ret =
145213
"""

test/metadata_utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Yes, we have no bananas. We have no bananas today!
5656
@test infos[:hyperparameter_ranges] == (nothing, nothing)
5757
end
5858

59-
@testset "doc_header(model)" begin
59+
@testset "doc_header(ModelType)" begin
6060

6161
# we test markdown parsed strings for less fussy comparison
6262

0 commit comments

Comments
 (0)