Skip to content

Commit 28d4f22

Browse files
authored
Merge pull request #190 from JuliaAI/dev
For a 1.9.5 release
2 parents a992ea2 + 7578027 commit 28d4f22

File tree

10 files changed

+104
-81
lines changed

10 files changed

+104
-81
lines changed

.github/codecov.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ coverage:
22
status:
33
project:
44
default:
5-
threshold: 0.5%
5+
threshold: 0.5%
6+
patch:
7+
default:
8+
target: 80%

Project.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
name = "MLJModelInterface"
22
uuid = "e80e1ace-859a-464e-9ed9-23947d8ae3ea"
33
authors = ["Thibaut Lienart and Anthony Blaom"]
4-
version = "1.9.4"
4+
version = "1.9.5"
55

66
[deps]
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
88
ScientificTypesBase = "30f210dd-8aff-4c5f-94ba-8e64358c1161"
99
StatisticalTraits = "64bff920-2084-43da-a3e6-9bb72801c0c9"
1010

1111
[compat]
12-
ScientificTypesBase = "3.0"
12+
Aqua = "0.8"
13+
CategoricalArrays = "0.10"
14+
DataFrames = "1"
15+
Distances = "0.10"
16+
InteractiveUtils = "<0.0.1, 1"
17+
Markdown = "<0.0.1, 1"
18+
OrderedCollections = "1"
19+
Random = "<0.0.1, 1"
20+
ScientificTypes = "3"
21+
ScientificTypesBase = "3"
1322
StatisticalTraits = "3.2"
23+
Tables = "1"
24+
Test = "<0.0.1, 1"
1425
julia = "1.6"
1526

1627
[extras]
28+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
1729
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
1830
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
1931
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
@@ -25,4 +37,4 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
2537
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2638

2739
[targets]
28-
test = ["CategoricalArrays", "DataFrames", "Distances", "InteractiveUtils", "Markdown", "OrderedCollections", "ScientificTypes", "Tables", "Test"]
40+
test = ["Aqua", "CategoricalArrays", "DataFrames", "Distances", "InteractiveUtils", "Markdown", "OrderedCollections", "ScientificTypes", "Tables", "Test"]

src/data_utils.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ end
5858
# int
5959

6060
"""
61-
int(x; type=nothing)
61+
int(x)
6262
6363
The positional integer of the `CategoricalString` or `CategoricalValue` `x`, in
6464
the ordering defined by the pool of `x`. The type of `int(x)` is the reference
@@ -96,9 +96,9 @@ julia> int(v)
9696
```
9797
See also: [`decoder`](@ref).
9898
"""
99-
function int(x; type::Union{Nothing, Type{T}}=nothing) where T <: Real
99+
function int(x; type=nothing)
100100
type === nothing && return int(get_interface_mode(), x)
101-
return convert.(T, int(get_interface_mode(), x))
101+
return convert.(type, int(get_interface_mode(), x))
102102
end
103103

104104
int(::LightInterface, x) = errlight("int")

src/equality.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function is_same_except(m1::M1,
124124
is_same_except(
125125
getproperty(m1, name),
126126
getproperty(m2, name)
127-
) ||
127+
) ||
128128
getproperty(m1, name) isa AbstractRNG ||
129129
getproperty(m2, name) isa AbstractRNG
130130
) || return false
@@ -155,7 +155,8 @@ function special_in(x, itr)::Union{Bool,Missing}
155155
end
156156

157157
Base.in(x::MLJType, itr::Set) = special_in(x, itr)
158-
Base.in(x::MLJType, itr::AbstractVector) = special_in(x, itr)
158+
Base.in(x::MLJType, itr::AbstractVector{<:MLJType}) = special_in(x, itr)
159+
Base.in(x::MLJType, itr::AbstractRange{<:MLJType}) = special_in(x, itr)
159160
Base.in(x::MLJType, itr::Tuple) = special_in(x, itr)
160161

161162
# A version of `in` that actually uses `==`:

src/model_traits.jl

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,50 +97,39 @@ end
9797
# in `prediction_type` for models which, historically, have not
9898
# implemented the trait.
9999

100+
# Actually, this has proven more trouble than it's worth and should be removed in 2.0.
101+
# See https://discourse.julialang.org/t/deconstructing-unionall-types/108328 to appreciate
102+
# some of the complications.
103+
100104
function StatTraits.predict_scitype(
101105
M::Type{<:Union{Probabilistic, ProbabilisticDetector}}
102106
)
103107
return _density(target_scitype(M))
104108
end
105109

106-
_density(::Any) = Unknown
107-
108-
for T in [:Continuous, :Count, :Textual]
109-
eval(
110-
quote
111-
function _density(::Type{AbstractArray{$T, D}}) where D
112-
return AbstractArray{Density{$T}, D}
113-
end
114-
end
115-
)
116-
end
110+
const SCALAR_SCITYPES_EXS =
111+
[:Finite, :Multiclass, :OrderedFactor, :Infinite, :Continuous, :Count, :Textual]
117112

118-
for T in [:Finite, :Multiclass, :OrderedFactor, :Infinite, :Continuous, :Count, :Textual]
119-
eval(
120-
quote
121-
function _density(::Type{AbstractArray{<:$T, D}}) where D
122-
return AbstractArray{Density{<:$T}, D}
123-
end
113+
const SCALAR_SCITYPES =
114+
eval.([:Finite, :Multiclass, :OrderedFactor, :Infinite, :Continuous, :Count, :Textual])
124115

125-
_density(::Type{Table($T)}) = Table(Density{$T})
126-
end
127-
)
116+
function _density(t)
117+
for T in SCALAR_SCITYPES
118+
t == AbstractVector{<:T} && return AbstractVector{Density{<:T}}
119+
t == AbstractMatrix{<:T} && return AbstractMatrix{Density{<:T}}
120+
t == Table(T) && return Table{<:AbstractVector{<:Density{<:T}}}
121+
end
122+
for T in [Finite, Multiclass, OrderedFactor]
123+
t == Table(T{2}) && return Table(Density{<:T{2}})
124+
end
125+
return Unknown
128126
end
129127

130-
131-
for T in [:Finite, :Multiclass, :OrderedFactor]
132-
eval(
128+
for T in SCALAR_SCITYPES_EXS
133129
quote
134-
function _density(::Type{AbstractArray{<:$T{N}, D}}) where {N, D}
135-
return AbstractArray{Density{<:$T{N}}, D}
136-
end
137-
138-
function _density(::Type{AbstractArray{$T{N}, D}}) where {N, D}
139-
return AbstractArray{Density{$T{N}}, D}
140-
end
141-
142-
_density(::Type{Table($T{N})}) where N = Table(Density{$T{N}})
143-
end
144-
)
130+
_density(::Type{<:AbstractArray{W, D}}) where {W<:$T, D} =
131+
AbstractArray{Density{W}, D}
132+
_density(::Type{<:Table{<:AbstractVector{W}}}) where W<:$T =
133+
Table(Density{W})
134+
end |> eval
145135
end
146-

test/aqua.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Aqua
2+
import MLJModelInterface
3+
4+
Aqua.test_all(MLJModelInterface, ambiguities=true)

test/data_utils.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ end
2323
# needing the `FullInterface`.
2424
X = (1, 2, 3)
2525
@test_throws M.InterfaceError matrix(X)
26-
26+
2727
X = (a=[1, 2, 3], b=[1, 2, 3])
2828
@test_throws M.InterfaceError matrix(X)
2929
end
3030

3131
@testset "matrix-full" begin
3232
setfull()
33-
M.matrix(::FI, ::Val{:table}, X; kw...) = Tables.matrix(X; kw...)
33+
# next line commented out as already defined in test/mode.jl:
34+
# M.matrix(::FI, ::Val{:table}, X; kw...) = Tables.matrix(X; kw...)
3435
X = (a=[1, 2, 3], b=[1, 2, 3])
3536
@test matrix(X) == hcat([1, 2, 3], [1, 2, 3])
3637
end
@@ -120,14 +121,14 @@ end
120121
# ------------------------------------------------------------------------
121122
@testset "istable" begin
122123
# Nothing stops someone from implementing a Tables.jl
123-
# interface that subtypes `AbstractArray`, so therefore
124+
# interface that subtypes `AbstractArray`, so therefore
124125
# `istable` should throw an error for `LightInterface`
125126
setlight()
126127
X = rand(5)
127128
@test_throws M.InterfaceError M.istable(X)
128129
X = randn(5, 5)
129130
@test_throws M.InterfaceError M.istable(X)
130-
131+
131132
# The method runs in `FullInterface`
132133
setfull()
133134
X = rand(5)
@@ -184,10 +185,10 @@ end
184185
X = ones(5)
185186
@test nrows(X) == 5
186187
X = ones(5, 3)
187-
@test nrows(X) == 5
188-
# It doesn't make sense to get the numbers of rows for
189-
# `AbstractArray`'s of dimension 3 or more. Except if these are
190-
# defined as Tables. Hence `FullInterface` would be required to check this
188+
@test nrows(X) == 5
189+
# It doesn't make sense to get the numbers of rows for
190+
# `AbstractArray`'s of dimension 3 or more. Except if these are
191+
# defined as Tables. Hence `FullInterface` would be required to check this
191192
X = ones(5, 3, 2)
192193
@test_throws ArgumentError nrows(X)
193194
M.nrows(::FI, ::Val{:table}, X) = Tables.rowcount(X)
@@ -220,13 +221,13 @@ end
220221

221222
@testset "select-full" begin
222223
setfull()
223-
224+
224225
# test fallback
225226
X = nothing
226227
@test selectrows(X, 1) === nothing
227228
@test selectcols(X, 1) === nothing
228229
@test select(X, 1, 2) === nothing
229-
230+
230231
# vector
231232
X = ones(5)
232233
@test selectrows(X, 1) == [1.0]
@@ -273,11 +274,11 @@ end
273274

274275
project(t::NamedTuple, label::Colon) = t
275276
project(t::NamedTuple, label::Symbol) = project(t, [label,])
276-
277+
277278
function project(t::NamedTuple, indices::AbstractArray{<:Integer})
278279
return NamedTuple{tuple(keys(t)[indices]...)}(tuple([t[i] for i in indices]...))
279280
end
280-
281+
281282
project(t::NamedTuple, i::Integer) = project(t, [i,])
282283

283284
X = (x=[1, 2, 3], y=[4, 5, 6], z=[0, 0, 0])
@@ -292,7 +293,7 @@ end
292293
@test select(X, :, 1) == [1, 2, 3]
293294
@test selectcols(X, :x) == [1, 2, 3]
294295
@test select(X, 1:2, :z) == [0, 0]
295-
296+
296297
# extra tests by Anthony
297298
X = (x=[1, 2, 3], y=[10, 20, 30], z= [:a, :b, :c])
298299
@test select(X, 2, :y) == 20

test/metadata_utils.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,6 @@ metadata_pkg(FooRegressor2,
198198
is_wrapper=false
199199
)
200200

201-
# this is added in MLJBase but not in MLJModelInterface, to avoid
202-
# InteractiveUtils as dependency:
203-
setfull()
204-
M.implemented_methods(::FI, M::Type{<:MLJType}) =
205-
getfield.(methodswith(M), :name)
206-
207201
const HEADER2 = MLJModelInterface.doc_header(FooRegressor2, augment=true)
208202

209203
@doc """

test/model_traits.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ M.human_name(::Type{<:U1}) = "funky model"
114114

115115
setfull()
116116

117-
function M.implemented_methods(::FI, M::Type{<:MLJType})
118-
return getfield.(methodswith(M), :name)
119-
end
120-
121117
@test Set(implemented_methods(mp)) == Set([:clean!,:bar,:foo])
122118
end
123119

@@ -140,19 +136,15 @@ end
140136
M._density(AbstractVector{<:T}),
141137
AbstractVector{Density{<:T}}
142138
)
143-
@test M._density(Table(T)) == Table(Density{T})
139+
@test M._density(Table(T)) == Table(Density{<:T})
144140
end
145141

146142
for T in [Finite, Multiclass, OrderedFactor]
147-
@test ==(
148-
M._density(AbstractArray{<:T{2},3}),
149-
AbstractArray{Density{<:T{2}},3}
150-
)
151143
@test ==(
152144
M._density(AbstractArray{T{2},3}),
153145
AbstractArray{Density{T{2}},3}
154146
)
155-
@test M._density(Table(T{2})) == Table(Density{T{2}})
147+
@test M._density(Table(T{2})) == Table(Density{<:T{2}})
156148
end
157149
end
158150

test/runtests.jl

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,45 @@ using Tables, Distances, CategoricalArrays, InteractiveUtils
44
import DataFrames: DataFrame
55
import Markdown
66
import OrderedCollections
7+
import Aqua
78

89
const M = MLJModelInterface
910
const FI = M.FullInterface
1011

1112
setlight() = M.set_interface_mode(M.LightInterface())
1213
setfull() = M.set_interface_mode(M.FullInterface())
1314

14-
include("mode.jl")
15-
include("parameter_inspection.jl")
16-
include("data_utils.jl")
17-
include("metadata_utils.jl")
18-
include("model_def.jl")
19-
include("model_api.jl")
20-
include("model_traits.jl")
21-
include("equality.jl")
15+
@testset "mode.jl" begin
16+
include("mode.jl")
17+
end
18+
19+
@testset "parameter_inspection.jl" begin
20+
include("parameter_inspection.jl")
21+
end
22+
23+
@testset "data_utils.jl" begin
24+
include("data_utils.jl")
25+
end
26+
27+
@testset "metadata_utils.jl" begin
28+
include("metadata_utils.jl")
29+
end
30+
@testset "model_def.jl" begin
31+
include("model_def.jl")
32+
end
33+
34+
@testset "model_api.jl" begin
35+
include("model_api.jl")
36+
end
37+
38+
@testset "model_traits.jl" begin
39+
include("model_traits.jl")
40+
end
41+
42+
@testset "equality.jl" begin
43+
include("equality.jl")
44+
end
45+
46+
@testset "aqua.jl" begin
47+
include("aqua.jl")
48+
end

0 commit comments

Comments
 (0)