4
4
"""
5
5
scitype(X)
6
6
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
+
8
36
"""
9
37
scitype (X; kw... ) = scitype (X, convention (); kw... )
10
38
scitype (X, C; kw... ) = scitype (X, C, Val (trait (X)); kw... )
@@ -23,7 +51,10 @@ scitype(t::Tuple, ::Convention; kw...) = Tuple{scitype.(t; kw...)...}
23
51
Return the type union, over all elements `x` generated by the iterable `A`,
24
52
of `scitype(x)`. See also [`scitype`](@ref).
25
53
"""
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
27
58
28
59
29
60
# -----------------------------------------------------------------
0 commit comments