Skip to content

Commit 8f81a92

Browse files
committed
fix MLJModelInterface.scitype clash with ScientificTypes.scitype
1 parent 20769cf commit 8f81a92

File tree

5 files changed

+41
-41
lines changed

5 files changed

+41
-41
lines changed

Project.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ MLJModelInterface = "e80e1ace-859a-464e-9ed9-23947d8ae3ea"
1414
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1515
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
1616
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81"
17+
ScientificTypesBase = "30f210dd-8aff-4c5f-94ba-8e64358c1161"
1718
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1819
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1920
TableOperations = "ab02a1b2-a7df-11e8-156e-fb1833f50b87"
@@ -22,14 +23,15 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
2223
[compat]
2324
BitBasis = "0.9"
2425
CategoricalArrays = "0.10"
25-
MLJModelInterface = "1.11"
2626
Combinatorics = "1"
2727
Dates = "1"
2828
Distributions = "0.25"
2929
LinearAlgebra = "1"
30+
MLJModelInterface = "1.11"
3031
OrderedCollections = "1"
3132
Parameters = "0.12"
32-
ScientificTypes = "3.0"
33+
ScientificTypes = "3.1.0"
34+
ScientificTypesBase = "3.0.0"
3335
Statistics = "1"
3436
StatsBase = "0.34"
3537
TableOperations = "1.2"
@@ -38,11 +40,11 @@ julia = "1.10"
3840

3941
[extras]
4042
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
41-
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
4243
MLJBase = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
4344
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
44-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
45+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
4546
StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
47+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4648

4749
[targets]
4850
test = ["Test", "DataFrames", "MLJBase", "Random", "StableRNGs", "StatsModels"]

src/MLJTransforms.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
module MLJTransforms
22
using Tables
3-
using ScientificTypes
4-
using ScientificTypes: scitype
3+
# Note: The `scitype` in
4+
# MLJModelInterface clashes with the `scitype` in ScientificTypes. See also
5+
# https://github.com/JuliaAI/MLJBase.jl/issues/1002
6+
import ScientificTypes: elscitype, schema, coerce, ScientificTimeType
7+
using MLJModelInterface # exports `scitype`, which will call `ScientificTypes.scitype`,
8+
# once MLJBase is loaded (but this is not a dependency!)
59
using CategoricalArrays
6-
using MLJModelInterface
710
using TableOperations
811
using StatsBase
912
using LinearAlgebra
@@ -15,7 +18,6 @@ using Parameters
1518
using Dates
1619
using OrderedCollections
1720

18-
1921
const MMI = MLJModelInterface
2022

2123
# Functions of generic use across transformers

test/encoders/contrast_encoder.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,16 @@ end
195195

196196
df = DataFrame(X)
197197

198-
mf = ModelFrame(
199-
@formula(age ~ (name + height + favnum)),
198+
mf = StatsModels.ModelFrame(
199+
StatsModels.@formula(age ~ (name + height + favnum)),
200200
df,
201201
contrasts = Dict(
202202
:name => StatsModels.ContrastsCoding(buildrandomcontrast(nothing, 3)),
203203
:favnum => StatsModels.ContrastsCoding(buildrandomcontrast(nothing, 4)),
204204
),
205205
)
206206

207-
X_tr_sm = ModelMatrix(mf).m[:, 2:end]
207+
X_tr_sm = StatsModels.ModelMatrix(mf).m[:, 2:end]
208208

209209
@test X_tr_mlj == X_tr_sm
210210
end
@@ -221,24 +221,24 @@ end
221221
X_tr_mlj = Tables.matrix(X_tr)[:, 1:end-1]
222222
df = DataFrame(X)
223223

224-
mf = ModelFrame(
225-
@formula(age ~ (name + height + favnum)),
224+
mf = StatsModels.ModelFrame(
225+
StatsModels.@formula(age ~ (name + height + favnum)),
226226
df,
227227
contrasts = Dict(
228-
:name => HypothesisCoding(
228+
:name => StatsModels.HypothesisCoding(
229229
buildrandomhypothesis(nothing, 3);
230230
levels = levels(X.name),
231231
labels = [],
232232
),
233-
:favnum => HypothesisCoding(
233+
:favnum => StatsModels.HypothesisCoding(
234234
buildrandomhypothesis(nothing, 4);
235235
levels = levels(X.favnum),
236236
labels = [],
237237
),
238238
),
239239
)
240240

241-
X_tr_sm = ModelMatrix(mf).m[:, 2:end]
241+
X_tr_sm = StatsModels.ModelMatrix(mf).m[:, 2:end]
242242

243243
@test X_tr_mlj == X_tr_sm
244244
end
@@ -257,11 +257,11 @@ end
257257
for ind in 1:6
258258
stats_models(k, ind) = [
259259
StatsModels.ContrastsCoding(buildrandomcontrast(nothing, k)),
260-
DummyCoding(; base = (k == 3) ? "Mary" : 10),
261-
EffectsCoding(; base = (k == 3) ? "Mary" : 10),
262-
SeqDiffCoding(),
263-
HelmertCoding(),
264-
HypothesisCoding(
260+
StatsModels.DummyCoding(; base = (k == 3) ? "Mary" : 10),
261+
StatsModels.EffectsCoding(; base = (k == 3) ? "Mary" : 10),
262+
StatsModels.SeqDiffCoding(),
263+
StatsModels.HelmertCoding(),
264+
StatsModels.HypothesisCoding(
265265
buildrandomhypothesis(nothing, k);
266266
levels = (k == 3) ? levels(X.name) : levels(X.favnum),
267267
labels = [],
@@ -277,8 +277,8 @@ end
277277

278278
df = DataFrame(X)
279279

280-
mf = ModelFrame(
281-
@formula(age ~ (name + height + favnum)),
280+
mf = StatsModels.ModelFrame(
281+
StatsModels.@formula(age ~ (name + height + favnum)),
282282
df,
283283
contrasts = Dict(
284284
:name => stats_models(3, ind),
@@ -287,7 +287,7 @@ end
287287
)
288288

289289
X_tr_mlj = Tables.matrix(X_tr)[:, 1:end-1]
290-
X_tr_sm = ModelMatrix(mf).m[:, 2:end]
290+
X_tr_sm = StatsModels.ModelMatrix(mf).m[:, 2:end]
291291
@test X_tr_mlj X_tr_sm
292292
end
293293
end
@@ -298,11 +298,11 @@ end
298298
for ind2 in 2:5
299299
stats_models(k, ind) = [
300300
StatsModels.ContrastsCoding(buildrandomcontrast(nothing, k)),
301-
DummyCoding(; base = (k == 3) ? "Mary" : 10),
302-
EffectsCoding(; base = (k == 3) ? "Mary" : 10),
303-
SeqDiffCoding(),
304-
HelmertCoding(),
305-
HypothesisCoding(
301+
StatsModels.DummyCoding(; base = (k == 3) ? "Mary" : 10),
302+
StatsModels.EffectsCoding(; base = (k == 3) ? "Mary" : 10),
303+
StatsModels.SeqDiffCoding(),
304+
StatsModels.HelmertCoding(),
305+
StatsModels.HypothesisCoding(
306306
buildrandomhypothesis(nothing, k);
307307
levels = (k == 3) ? levels(X.name) : levels(X.favnum),
308308
labels = [],
@@ -331,8 +331,8 @@ end
331331

332332
df = DataFrame(X)
333333

334-
mf = ModelFrame(
335-
@formula(age ~ (name + height + favnum)),
334+
mf = StatsModels.ModelFrame(
335+
StatsModels.@formula(age ~ (name + height + favnum)),
336336
df,
337337
contrasts = Dict(
338338
:name => stats_models(3, ind1),
@@ -341,7 +341,7 @@ end
341341
)
342342

343343
X_tr_mlj = Tables.matrix(X_tr)[:, 1:end-1]
344-
X_tr_sm = ModelMatrix(mf).m[:, 2:end]
344+
X_tr_sm = StatsModels.ModelMatrix(mf).m[:, 2:end]
345345

346346
@test X_tr_mlj X_tr_sm
347347
end
@@ -406,4 +406,4 @@ end
406406
@test last_type <: Integer && isconcretetype(last_type)
407407
@test last_sctype <: Count
408408
end
409-
end
409+
end

test/encoders/target_encoding.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ end
368368
D = [true, false, true, false, true]
369369
E = [1, 2, 3, 4, 5]
370370

371-
# Define the target variable
371+
# Define the target variable
372372
y = ["c1", "c2", "c3", "c1", "c2"]
373373

374374
# Combine into a named tuple
@@ -396,4 +396,3 @@ end
396396
@test scs[end] === schema(X).scitypes[end]
397397
@test ts[end] == schema(X).types[end]
398398
end
399-

test/runtests.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
using MLJTransforms
22
using Test
33
using DataFrames
4-
using ScientificTypes
54
using CategoricalArrays
6-
using MLJModelInterface
75
using MLJBase
86
using StatsBase
97
using LinearAlgebra
10-
using StatsModels
8+
import StatsModels
119
using Random
10+
import MLJModelInterface
1211
const MMI = MLJModelInterface
1312
using LinearAlgebra
14-
using StatsModels
1513

1614
# Other transformers
1715
using Tables, CategoricalArrays
18-
using ScientificTypes: scitype, schema
1916
using Statistics
2017
using StableRNGs
2118
stable_rng = StableRNGs.StableRNG(123)
@@ -40,4 +37,4 @@ include("transformers/other_transformers/interaction_transformer.jl")
4037
include("transformers/other_transformers/continuous_encoder.jl")
4138
include("transformers/other_transformers/univariate_boxcox_transformer.jl")
4239
include("transformers/other_transformers/standardizer.jl")
43-
include("transformers/other_transformers/univariate_discretizer.jl")
40+
include("transformers/other_transformers/univariate_discretizer.jl")

0 commit comments

Comments
 (0)