|
1 | 1 | """ |
2 | | - @testapi learner dataset1, dataset2 ... verbosity=1 |
| 2 | + @testapi learner dataset1 dataset2 ... verbosity=1 |
3 | 3 |
|
4 | 4 | Test that `learner` correctly implements the LearnAPI.jl interface, by checking |
5 | 5 | contracts against one or more data sets. |
@@ -37,15 +37,20 @@ The following are *not* tested: |
37 | 37 |
|
38 | 38 | - That the output of `LearnAPI.target(learner, data)` is indeed a target, in the sense |
39 | 39 | that it can be paired, in some way, with the output of `predict`. Such a test would be |
40 | | - to suitably pair the output with a predicted proxy for the target, using, say, a proper |
41 | | - scoring rule, in the case of probabilistic predictions. |
| 40 | + to suitably pair the output with a predicted proxy for the target, using, for example, a |
| 41 | + proper scoring rule, in the case of probabilistic predictions. |
42 | 42 |
|
43 | 43 | - That `inverse_transform` is an approximate left or right inverse to `transform` |
44 | 44 |
|
45 | 45 | - That the one-line convenience methods, `transform(learner, ...)` or `predict(learner, |
46 | 46 | ...)`, where implemented, have the same effect as the two-line calls they combine. |
47 | 47 |
|
48 | | -- The veracity of `is_pure_julia(learner)`. |
| 48 | +- The veracity of `LearnAPI.is_pure_julia(learner)`. |
| 49 | +
|
| 50 | +- The second of the two contracts appearing in the |
| 51 | + [`LearnAPI.target_observation_scitype`](@extref) docstring. The first contract is only |
| 52 | + tested if `LearnAPI.data_interface(learner)` is `LearnAPI.RandomAccess()` or |
| 53 | + `LearnAPI.FiniteIterable()`. |
49 | 54 |
|
50 | 55 | Whenever the internal `learner` algorithm involves case distinctions around data or |
51 | 56 | hyperparameters, it is recommended that multiple datasets, and learners with a variety of |
@@ -637,12 +642,34 @@ macro testapi(learner, data...) |
637 | 642 | end |
638 | 643 |
|
639 | 644 | @logged_testset $HUMAN_NAME verbosity begin |
640 | | - human_name = LearnAPI.human_name(learner) |
641 | | - Test.@test human_name isa String |
| 645 | + Test.@test _human_name isa String |
| 646 | + end |
| 647 | + |
| 648 | + @logged_testset $FIT_SCITYPE verbosity begin |
| 649 | + S = LearnAPI.fit_scitype(learner) |
| 650 | + if S == Union{} |
| 651 | + push!(missing_traits, :(LearnAPI.fit_scitype)) |
| 652 | + else |
| 653 | + Test.@test ScientificTypes.scitype(data) <: S |
| 654 | + end |
| 655 | + end |
| 656 | + |
| 657 | + S = LearnAPI.target_observation_scitype(learner) |
| 658 | + testable = :(LearnAPI.target) in _functions && |
| 659 | + _data_interface in (LearnAPI.RandomAccess(), LearnAPI.FiniteIterable()) |
| 660 | + if S == Any |
| 661 | + push!(missing_traits, :(LearnAPI.target_observation_scitype)) |
| 662 | + elseif testable |
| 663 | + @logged_testset $TARGET_OBSERVATION_SCITYPE verbosity begin |
| 664 | + Test.@test all([o for o in _y]) do o |
| 665 | + ScientificTypes.scitype(o) <: S |
| 666 | + end |
| 667 | + end |
642 | 668 | end |
643 | 669 |
|
644 | 670 | end # for loop over datasets |
645 | | - verbosity > 0 && !isempty(missing_traits) && @info $MISSING_TRAITS(missing_traits) |
| 671 | + verbosity > 0 && !isempty(missing_traits) && |
| 672 | + @info $MISSING_TRAITS(missing_traits, _human_name) |
646 | 673 | verbosity > 0 && @info "------ @testapi - $_human_name - tests complete ------" |
647 | 674 | nothing |
648 | 675 | end # quote |
|
0 commit comments