File tree Expand file tree Collapse file tree 3 files changed +24
-19
lines changed Expand file tree Collapse file tree 3 files changed +24
-19
lines changed Original file line number Diff line number Diff line change @@ -36,11 +36,14 @@ docstring(M::Type{<:MLJType}) = name(M)
36
36
docstring (M:: Type{<:Model} ) = " $(name (M)) from $(package_name (M)) .jl.\n " *
37
37
" [Documentation]($(package_url (M)) )."
38
38
# "derived" traits:
39
- typename (s) = replace (s, r" typename\( (.*?)\) " => s "\1 " )
40
- name (M:: Type ) = string (M) |> typename
41
- name (M:: Type{<:MLJType} ) = split (string (coretype (M)), ' .' )[end ] |> String |> typename
42
-
43
-
39
+ function _coretype (M)
40
+ if isdefined (M, :name )
41
+ return M. name. name
42
+ else
43
+ return _coretype (M. body)
44
+ end
45
+ end
46
+ name (M:: Type ) = string (_coretype (M))
44
47
is_supervised (:: Type ) = false
45
48
is_supervised (:: Type{<:Supervised} ) = true
46
49
prediction_type (:: Type ) = :unknown # used for measures too
Original file line number Diff line number Diff line change @@ -2,10 +2,3 @@ if VERSION < v"1.1"
2
2
fieldtypes (t) = Tuple (fieldtype (t, i) for i = 1 : fieldcount (t))
3
3
end
4
4
5
- function coretype (M)
6
- if isdefined (M, :name )
7
- return M. name
8
- else
9
- return coretype (M. body)
10
- end
11
- end
Original file line number Diff line number Diff line change @@ -64,18 +64,27 @@ bar(::P1) = nothing
64
64
@test Set (implemented_methods (mp)) == Set ([:clean! ,:bar ,:foo ])
65
65
end
66
66
67
- struct FooMeasure <: MLJType end
67
+ module Fruit
68
+
69
+ import MLJModelInterface. MLJType
70
+
71
+ struct Banana <: MLJType end
72
+ struct Apple end
73
+
74
+ end
75
+
76
+ import . Banana
68
77
69
78
@testset " extras" begin
70
79
@test docstring (Float64) == " Float64"
71
- @test docstring (FooMeasure ) == " FooMeasure "
80
+ @test docstring (Fruit . Banana ) == " Banana "
72
81
@test name (Float64) == " Float64"
73
82
74
83
df = DataFrame (a= randn (2 ), b= randn (2 ))
75
- @static if VERSION < v " 1.6-"
76
- @test string (M. coretype (typeof (df))) == " DataFrame"
77
- else
78
- @test string (M. coretype (typeof (df))) == " typename(DataFrame)"
79
- end
80
84
@test M. name (typeof (df)) == " DataFrame"
85
+ @test M. name (df) == " DataFrame"
86
+ @test M. name (Fruit. Banana) == " Banana"
87
+ @test M. name (Fruit. Banana ()) == " Banana"
88
+ @test M. name (Fruit. Apple) == " Apple"
89
+ @test M. name (Fruit. Apple ()) == " Apple"
81
90
end
You can’t perform that action at this time.
0 commit comments