Skip to content

Commit d10edb6

Browse files
authored
Merge pull request #32 from alan-turing-institute/dev
coerce to union missing type
2 parents e3b2e0c + 9c8ef14 commit d10edb6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/conventions/mlj/mlj.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ A warning is issued if missing values are encountered, unless
4444
See also [`scitype`](@ref), [`scitype_union`](@ref).
4545
4646
"""
47-
function coerce(y::AbstractVector{<:Union{Missing,AbstractFloat}}, T::Type{Continuous};
47+
function coerce(y::AbstractVector{<:Union{Missing,AbstractFloat}}, T::Type{<:Union{Missing,Continuous}};
4848
verbosity=1)
4949
eltype(y) >: Missing && verbosity > 0 && _coerce_missing_warn(T)
5050
return y
5151
end
5252

53-
function coerce(y::AbstractVector{<:Union{Missing,Real}}, T::Type{Continuous}; verbosity=1)
53+
function coerce(y::AbstractVector{<:Union{Missing,Real}}, T::Type{<:Union{Missing,Continuous}}; verbosity=1)
5454
eltype(y) >: Missing && verbosity > 0 && _coerce_missing_warn(T)
5555
return float(y)
5656
end
@@ -61,7 +61,7 @@ end
6161
# as a String, it will error.
6262
# - if at one point it encounters a Char it will **not** error but return a float
6363
# corresponding to the Char (e.g. 65.0 for 'A') whence the warning
64-
function coerce(y::AbstractVector, T::Type{Continuous}; verbosity=1)
64+
function coerce(y::AbstractVector, T::Type{<:Union{Missing,Continuous}}; verbosity=1)
6565
has_missings = findfirst(ismissing, y) !== nothing
6666
has_missings && verbosity > 0 && _coerce_missing_warn(T)
6767
has_chars = findfirst(e->isa(e,Char), y) !== nothing
@@ -78,20 +78,20 @@ _int(x::Integer) = x
7878
_int(x) = Int(x) # may throw InexactError
7979

8080
# no-op case
81-
function coerce(y::AbstractVector{<:Union{Missing,Integer}}, T::Type{Count}; verbosity=1)
81+
function coerce(y::AbstractVector{<:Union{Missing,Integer}}, T::Type{<:Union{Missing,Count}}; verbosity=1)
8282
eltype(y) >: Missing && verbosity > 0 && _coerce_missing_warn(T)
8383
return y
8484
end
8585

8686
# NOTE: this will error if it encounters things like 1.5 or 1//2 (InexactError)
87-
function coerce(y::AbstractVector{<:Union{Missing,Real}}, T::Type{Count}; verbosity=1)
87+
function coerce(y::AbstractVector{<:Union{Missing,Real}}, T::Type{<:Union{Missing,Count}}; verbosity=1)
8888
eltype(y) >: Missing && verbosity > 0 && _coerce_missing_warn(T)
8989
return _int.(y)
9090
end
9191

9292
# NOTE: case where the data may have been badly encoded and resulted in an Any[] vector
9393
# a user should proceed with caution here (see comment earlier)
94-
function coerce(y::AbstractVector, T::Type{Count}; verbosity=1)
94+
function coerce(y::AbstractVector, T::Type{<:Union{Missing,Count}}; verbosity=1)
9595
has_missings = findfirst(ismissing, y) !== nothing
9696
has_missings && verbosity > 0 && _coerce_missing_warn(T)
9797
has_chars = findfirst(e->isa(e,Char), y) !== nothing

0 commit comments

Comments
 (0)