3
3
x = 1 : 5
4
4
@test_throws M. InterfaceError M. categorical (x)
5
5
end
6
+
6
7
@testset " cat-full" begin
7
8
setfull ()
8
9
M. categorical (:: FI , a... ; kw... ) = categorical (a... ; kw... )
9
10
x = 1 : 5
10
11
@test M. categorical (x) == categorical (x)
11
12
end
13
+
12
14
# ------------------------------------------------------------------------
13
15
@testset " matrix-light" begin
14
16
setlight ()
25
27
X = (a= [1 , 2 , 3 ], b= [1 , 2 , 3 ])
26
28
@test_throws M. InterfaceError matrix (X)
27
29
end
30
+
28
31
@testset " matrix-full" begin
29
32
setfull ()
30
33
M. matrix (:: FI , :: Val{:table} , X; kw... ) = Tables. matrix (X; kw... )
31
34
X = (a= [1 , 2 , 3 ], b= [1 , 2 , 3 ])
32
35
@test matrix (X) == hcat ([1 , 2 , 3 ], [1 , 2 , 3 ])
33
36
end
37
+
34
38
# ------------------------------------------------------------------------
35
39
@testset " int-light" begin
36
40
setlight ()
37
41
x = categorical ([1 , 2 , 3 ])
38
42
@test_throws M. InterfaceError int (x)
39
43
end
44
+
40
45
@testset " int-full" begin
41
46
setfull ()
42
47
M. int (:: FI , x:: CategoricalValue ) = CategoricalArrays. refcode (x)
61
66
x = categorical ([' a' ,' b' ,' a' ])
62
67
@test classes (x[1 ]) == [' a' , ' b' ]
63
68
end
69
+
70
+ # ------------------------------------------------------------------------
71
+ @testset " scitype-light" begin
72
+ # throw error for any input anyway
73
+ setlight ()
74
+
75
+ ary = rand (10 , 3 )
76
+ @test_throws M. InterfaceError M. scitype (ary)
77
+
78
+ df = DataFrame (rand (10 , 3 ), :auto )
79
+ @test_throws M. InterfaceError M. scitype (df)
80
+ end
81
+
82
+ @testset " scitype-full" begin
83
+ setfull ()
84
+ M. scitype (:: FI , v, X) = ScientificTypes. scitype (X)
85
+
86
+ ary = rand (10 , 3 )
87
+ @test M. scitype (ary) == AbstractArray{Continuous, 2 }
88
+
89
+ df = DataFrame (A = rand (10 ), B = categorical (rand (' a' :' c' , 10 )))
90
+ sch = M. scitype (df)
91
+ @test sch <: Table (Continuous, Multiclass)
92
+ end
93
+
64
94
# ------------------------------------------------------------------------
65
95
@testset " schema-light" begin
66
96
# throw error for any input anyway
70
100
df = DataFrame (rand (10 , 3 ), :auto )
71
101
@test_throws M. InterfaceError M. schema (df)
72
102
end
103
+
73
104
@testset " schema-full" begin
74
105
setfull ()
106
+ M. schema (:: FI , v, X) = ScientificTypes. schema (X)
107
+
75
108
ary = rand (10 , 3 )
76
- M. schema (:: FI , :: Val{:table} , X; kw... ) =
77
- ScientificTypes. schema (X; kw... )
78
- M. schema (:: FI , :: Val{:other} , X; kw... ) = nothing
109
+ @test_throws ArgumentError M. schema (ary)
79
110
80
- @test M. schema (ary) === nothing
81
111
df = DataFrame (A = rand (10 ), B = categorical (rand (' a' :' c' , 10 )))
82
112
sch = M. schema (df)
83
113
@test sch. names == (:A , :B )
86
116
@test sch. scitypes[1 ] <: Continuous
87
117
@test sch. scitypes[2 ] <: Multiclass
88
118
end
119
+
89
120
# ------------------------------------------------------------------------
90
121
@testset " istable" begin
91
122
# Nothing stops someone from implementing a Tables.jl
@@ -106,24 +137,28 @@ end
106
137
X = DataFrame (A= rand (10 ))
107
138
@test M. istable (X)
108
139
end
140
+
109
141
# ------------------------------------------------------------------------
110
142
@testset " decoder-light" begin
111
143
setlight ()
112
144
x = 5
113
145
@test_throws M. InterfaceError decoder (x)
114
146
end
147
+
115
148
@testset " decoder-full" begin
116
149
setfull ()
117
150
# toy test because I don't want to copy the decoder logic here
118
151
M. decoder (:: FI , x) = 0
119
152
@test decoder (nothing ) == 0
120
153
end
154
+
121
155
# ------------------------------------------------------------------------
122
156
@testset " table-light" begin
123
157
setlight ()
124
158
X = ones (3 , 2 )
125
159
@test_throws M. InterfaceError table (X)
126
160
end
161
+
127
162
@testset " table-full" begin
128
163
setfull ()
129
164
function M. table (:: FI , A:: AbstractMatrix ; names= nothing )
@@ -135,13 +170,15 @@ end
135
170
@test Tables. istable (T)
136
171
@test Tables. matrix (T) == X
137
172
end
173
+
138
174
# ------------------------------------------------------------------------
139
175
@testset " nrows-light" begin
140
176
setlight ()
141
177
X = (a= [4 , 2 , 1 ], b= [3 , 2 , 1 ])
142
178
@test_throws M. InterfaceError nrows (X)
143
179
@test nrows (nothing ) == 0
144
180
end
181
+
145
182
@testset " nrows-full" begin
146
183
setfull ()
147
184
X = ones (5 )
157
194
X = (a= [4 , 2 , 1 ], b= [3 , 2 , 1 ])
158
195
@test nrows (X) == 3
159
196
end
197
+
160
198
# ------------------------------------------------------------------------
161
199
@testset " select-light" begin
162
200
setlight ()
179
217
@test_throws M. InterfaceError selectcols (X, 1 )
180
218
@test_throws M. InterfaceError select (X, 1 , 1 )
181
219
end
220
+
182
221
@testset " select-full" begin
183
222
setfull ()
184
223
0 commit comments