File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,23 @@ classes(x) = classes(get_interface_mode(), x)
123
123
124
124
classes (:: LightInterface , x) = errlight (" classes" )
125
125
126
+ # ------------------------------------------------------------------------
127
+ # schema
128
+
129
+ """
130
+ schema(X)
131
+
132
+ If `X` is tabular, inspect the column types and scitypes, otherwise return
133
+ `nothing`.
134
+ """
135
+ schema (X; kw... ) = schema (get_interface_mode (), vtrait (X), X; kw... )
136
+
137
+ schema (:: Mode , :: Val{:other} , X; kw... ) = nothing
138
+
139
+ schema (:: LightInterface , :: Val{:other} , X; kw... ) = errlight (" schema" )
140
+
141
+ schema (:: LightInterface , :: Val{:table} , X; kw... ) = errlight (" schema" )
142
+
126
143
# ------------------------------------------------------------------------
127
144
# decoder
128
145
Original file line number Diff line number Diff line change 58
58
@test classes (x[1 ]) == [' a' , ' b' ]
59
59
end
60
60
# ------------------------------------------------------------------------
61
+ @testset " schema-light" begin
62
+ # throw error for any input anyway
63
+ setlight ()
64
+ ary = rand (10 , 3 )
65
+ @test_throws M. InterfaceError M. schema (ary)
66
+ df = DataFrame (rand (10 , 3 ))
67
+ @test_throws M. InterfaceError M. schema (df)
68
+ end
69
+ @testset " schema-full" begin
70
+ setfull ()
71
+ ary = rand (10 , 3 )
72
+ @test M. schema (ary) === nothing
73
+ M. schema (:: FI , :: Val{:table} , X; kw... ) = schema (X; kw... ) # this would be defined in MLJBase.jl
74
+ df = DataFrame (A = rand (10 ), B = categorical (rand (' a' :' c' , 10 )))
75
+ sch = M. schema (df)
76
+ @test sch. names == (:A , :B )
77
+ @test sch. types[1 ] <: Float64
78
+ @test sch. types[2 ] <: CategoricalValue
79
+ @test sch. scitypes[1 ] <: Continuous
80
+ @test sch. scitypes[2 ] <: Multiclass
81
+ end
82
+ # ------------------------------------------------------------------------
61
83
@testset " decoder-light" begin
62
84
setlight ()
63
85
x = 5
You can’t perform that action at this time.
0 commit comments