Skip to content

Commit d07353b

Browse files
authored
Merge pull request #109 from alan-turing-institute/dev
For a 0.8.1 release
2 parents 7c14931 + d352cb8 commit d07353b

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ os:
44
- linux
55
julia:
66
- 1.0
7-
- 1.1
8-
- 1.2
9-
- 1.3
10-
- 1.4
7+
- 1.5
118
- nightly
129
matrix:
1310
allow_failures:

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ScientificTypes"
22
uuid = "321657f4-b219-11e9-178b-2701a2544e81"
33
authors = ["Anthony D. Blaom <[email protected]>"]
4-
version = "0.8.0"
4+
version = "0.8.1"
55

66
[compat]
77
julia = "1"

src/scitype.jl

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,35 @@
44
"""
55
scitype(X)
66
7-
The scientific type that `X` may represent.
7+
The scientific type (interpretation) of `X`, as distinct from its
8+
machine type, as specified by the active convention.
9+
10+
### Examples from the MLJ convention
11+
12+
```
13+
julia> using MLJScientificTypes # or `using MLJ`
14+
julia> scitype(3.14)
15+
Continuous
16+
17+
julia> scitype([1, 2, 3, missing])
18+
AbstractArray{Union{Missing, Count},1}
19+
20+
julia> scitype((5, "beige"))
21+
Tuple{Count, Textual}
22+
23+
julia> using CategoricalArrays
24+
julia> X = (gender = categorical([:M, :M, :F, :M, :F]),
25+
ndevices = [1, 3, 2, 3, 2])
26+
julia> scitype(X)
27+
Table{Union{AbstractArray{Count,1}, AbstractArray{Multiclass{2},1}}}
28+
```
29+
30+
The specific behavior of `scitype` is governed by the active
31+
convention, as returned by `ScientificTypes.convention()`. The
32+
[MLJScientificTypes.jl
33+
documentation](https://alan-turing-institute.github.io/MLJScientificTypes.jl/dev/)
34+
details the convention demonstrated above.
35+
836
"""
937
scitype(X; kw...) = scitype(X, convention(); kw...)
1038
scitype(X, C; kw...) = scitype(X, C, Val(trait(X)); kw...)
@@ -23,7 +51,10 @@ scitype(t::Tuple, ::Convention; kw...) = Tuple{scitype.(t; kw...)...}
2351
Return the type union, over all elements `x` generated by the iterable `A`,
2452
of `scitype(x)`. See also [`scitype`](@ref).
2553
"""
26-
scitype_union(A) = reduce((a,b)->Union{a,b}, (scitype(el) for el in A))
54+
function scitype_union(A)
55+
isempty(A) && return scitype(eltype(A))
56+
reduce((a,b)->Union{a,b}, (scitype(el) for el in A))
57+
end
2758

2859

2960
# -----------------------------------------------------------------

test/scitype.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
Xm = Any[missing, missing]
1818
@test scitype(Xm) == AbstractVector{Missing}
19-
19+
2020
@test scitype([missing, missing]) == AbstractVector{Missing}
2121
end
2222

@@ -41,3 +41,13 @@ end
4141
@test ScientificDateTime <: ScientificTimeType
4242
@test ScientificTime <: ScientificTimeType
4343
end
44+
45+
@testset "Empty array" begin
46+
set_convention(MockMLJ())
47+
ScientificTypes.Scitype(::Type{<:Integer}, ::MockMLJ) = Count
48+
ScientificTypes.Scitype(::Type{Missing}, ::MockMLJ) = Missing
49+
@test scitype(Int[]) == AbstractVector{Count}
50+
@test scitype(Any[]) == AbstractVector{Unknown}
51+
@test scitype(Missing[]) == AbstractVector{Missing}
52+
@test scitype(Vector{Union{Int,Missing}}()) == AbstractVector{Union{Missing,Count}}
53+
end

0 commit comments

Comments
 (0)