Skip to content

Commit 3736e2a

Browse files
authored
light fixes (#5)
* minor export changes * int modif
1 parent 70cb9fb commit 3736e2a

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

Project.toml

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

66
[deps]
77
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81"
@@ -19,5 +19,4 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1919
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2020

2121
[targets]
22-
test = ["Test", "Tables", "Distances", "CategoricalArrays", "InteractiveUtils",
23-
"DataFrames"]
22+
test = ["Test", "Tables", "Distances", "CategoricalArrays", "InteractiveUtils", "DataFrames"]

src/MLJModelInterface.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@ export MLJType, Model, Supervised, Unsupervised,
1515
Probabilistic, Deterministic, Interval, Static,
1616
UnivariateFinite
1717

18-
# reexport types from ScientificTypes
19-
export Scientific, Found, Unknown, Known, Finite, Infinite,
20-
OrderedFactor, Multiclass, Count, Continuous, Textual,
21-
Binary, ColorImage, GrayImage, Table
22-
2318
# model constructor + metadata
24-
export @mlj_model, metadata_pkg, metadata_model, metadata_measure
19+
export @mlj_model, metadata_pkg, metadata_model
2520

2621
# model api
2722
export fit, update, update_data, transform, inverse_transform,
@@ -41,6 +36,12 @@ export input_scitype, output_scitype, target_scitype,
4136
export matrix, int, classes, decoder, table,
4237
nrows, selectrows, selectcols, select
4338

39+
# re-exports from ScientificTypes
40+
export Scientific, Found, Unknown, Known, Finite, Infinite,
41+
OrderedFactor, Multiclass, Count, Continuous, Textual,
42+
Binary, ColorImage, GrayImage, Image, Table
43+
export scitype, scitype_union, elscitype, nonmissing, trait
44+
4445
# ------------------------------------------------------------------------
4546
# Mode trick
4647

src/data_utils.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ matrix(::LightInterface, ::Val{:table}, X; kw...) = errlight("matrix")
3131
# int
3232

3333
"""
34-
int(x)
34+
int(x; type=nothing)
3535
3636
The positional integer of the `CategoricalString` or `CategoricalValue` `x`, in
3737
the ordering defined by the pool of `x`. The type of `int(x)` is the reference
@@ -61,9 +61,12 @@ Broadcasted versions of `int`.
6161
6262
See also: [`decoder`](@ref).
6363
"""
64-
int(x; kw...) = int(get_interface_mode(), x; kw...)
64+
function int(x; type::Union{Nothing,Type{T}}=nothing) where T <: Real
65+
type === nothing && return int(get_interface_mode(), x)
66+
return convert.(T, int(get_interface_mode(), x))
67+
end
6568

66-
int(::LightInterface, x; kw...) = errlight("int")
69+
int(::LightInterface, x) = errlight("int")
6770

6871
# ------------------------------------------------------------------------
6972
# classes
@@ -270,7 +273,7 @@ be of type `CategoricalElement` (see above) and the dictionary values specify
270273
the corresponding probabilities.
271274
"""
272275
UnivariateFinite(d::AbstractDict) = UnivariateFinite(get_interface_mode(), d)
273-
UnivariateFinite(c::AbstractVector, p::AbstractVector) =
276+
UnivariateFinite(c::AbstractVector, p) =
274277
UnivariateFinite(get_interface_mode(), c, p)
275278

276279
UnivariateFinite(::LightInterface, a...) = errlight("UnivariateFinite")

test/data_utils.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ end
2727
x = categorical(['a','b','a'])
2828
@test int(x[1]) == 0x01
2929
@test int(x[2]) == 0x02
30+
@test int(x[2]) isa UInt32
31+
@test int(x[1], type=Int64) == 1
32+
@test int(x[1], type=Int64) isa Int64
3033
end
3134
# ------------------------------------------------------------------------
3235
@testset "classes-light" begin

0 commit comments

Comments
 (0)