From c18dab2f82b4ea0bd1a9ce2c9877eff947f6ce27 Mon Sep 17 00:00:00 2001 From: quinnj Date: Wed, 10 Jan 2018 15:49:47 -0700 Subject: [PATCH 1/2] Some compat for 0.7 --- src/Missings.jl | 32 ++++++++++++++++++++++++++++++-- test/runtests.jl | 16 +++++++++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/Missings.jl b/src/Missings.jl index 9ccabf0..519a5ca 100644 --- a/src/Missings.jl +++ b/src/Missings.jl @@ -206,6 +206,10 @@ else Base.float(A::AbstractArray{Missing}) = A end +if isdefined(Base, :adjoint) +Base.adjoint(d::Missing) = missing +end + T(::Type{Union{T1, Missing}}) where {T1} = T1 T(::Type{Missing}) = Union{} T(::Type{T1}) where {T1} = T1 @@ -213,8 +217,8 @@ T(::Type{Any}) = Any # vector constructors missings(dims...) = fill(missing, dims) -missings(::Type{T}, dims...) where {T >: Missing} = fill!(Array{T}(dims), missing) -missings(::Type{T}, dims...) where {T} = fill!(Array{Union{T, Missing}}(dims), missing) +missings(::Type{T}, dims...) where {T >: Missing} = fill!(Array{T}(uninitialized, dims), missing) +missings(::Type{T}, dims...) where {T} = fill!(Array{Union{T, Missing}}(uninitialized, dims), missing) """ allowmissing(x::AbstractArray) @@ -272,10 +276,17 @@ struct EachReplaceMissing{T, U} x::T replacement::U end +if VERSION < v"0.7.0-DEV.3309" Base.iteratorsize(::Type{<:EachReplaceMissing{T}}) where {T} = Base.iteratorsize(T) Base.iteratoreltype(::Type{<:EachReplaceMissing{T}}) where {T} = Base.iteratoreltype(T) +else +Base.IteratorSize(::Type{<:EachReplaceMissing{T}}) where {T} = + Base.IteratorSize(T) +Base.IteratorEltype(::Type{<:EachReplaceMissing{T}}) where {T} = + Base.IteratorEltype(T) +end Base.length(itr::EachReplaceMissing) = length(itr.x) Base.size(itr::EachReplaceMissing) = size(itr.x) Base.start(itr::EachReplaceMissing) = start(itr.x) @@ -286,6 +297,7 @@ Base.eltype(itr::EachReplaceMissing) = Missings.T(eltype(itr.x)) (v isa Missing ? itr.replacement : v, s) end +@static if !isdefined(Base, :skipmissing) """ skipmissing(itr) @@ -315,10 +327,17 @@ skipmissing(itr) = EachSkipMissing(itr) struct EachSkipMissing{T} x::T end +if VERSION < v"0.7.0-DEV.3309" Base.iteratorsize(::Type{<:EachSkipMissing}) = Base.SizeUnknown() Base.iteratoreltype(::Type{EachSkipMissing{T}}) where {T} = Base.iteratoreltype(T) +else +Base.IteratorSize(::Type{<:EachSkipMissing}) = + Base.SizeUnknown() +Base.IteratorEltype(::Type{EachSkipMissing{T}}) where {T} = + Base.IteratorEltype(T) +end Base.eltype(itr::EachSkipMissing) = Missings.T(eltype(itr.x)) # Fallback implementation for general iterables: we cannot access a value twice, # so after finding the next non-missing element in start() or next(), we have to @@ -364,6 +383,8 @@ end (v, _next_nonmissing_ind(itr.x, state)) end +end # isdefined + """ Missings.fail(itr) @@ -391,10 +412,17 @@ fail(itr) = EachFailMissing(itr) struct EachFailMissing{T} x::T end +if VERSION < v"0.7.0-DEV.3309" Base.iteratorsize(::Type{EachFailMissing{T}}) where {T} = Base.iteratorsize(T) Base.iteratoreltype(::Type{EachFailMissing{T}}) where {T} = Base.iteratoreltype(T) +else +Base.IteratorSize(::Type{EachFailMissing{T}}) where {T} = + Base.IteratorSize(T) +Base.IteratorEltype(::Type{EachFailMissing{T}}) where {T} = + Base.IteratorEltype(T) +end Base.length(itr::EachFailMissing) = length(itr.x) Base.size(itr::EachFailMissing) = size(itr.x) Base.start(itr::EachFailMissing) = start(itr.x) diff --git a/test/runtests.jl b/test/runtests.jl index 86cdef3..c115b84 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,9 @@ -using Base.Test, Missings, Compat +@static if VERSION < v"0.7.0-DEV.2005" + using Base.Test +else + using Test +end +using Missings, Compat @testset "Missings" begin # test promote rules @@ -17,7 +22,7 @@ using Base.Test, Missings, Compat @test promote_type(Union{Int, Missing}, Union{Int, Missing}) == Union{Int, Missing} @test promote_type(Union{Float64, Missing}, Union{String, Missing}) == Any @test promote_type(Union{Float64, Missing}, Union{Int, Missing}) == Union{Float64, Missing} - @test promote_type(Union{Void, Missing, Int}, Float64) == Any + # @test_broken promote_type(Union{Nothing, Missing, Int}, Float64) == Any bit_operators = [&, |, ⊻] @@ -32,7 +37,7 @@ using Base.Test, Missings, Compat iseven, isodd, ispow2, isfinite, isinf, isnan, iszero, isinteger, isreal, - isempty, transpose, ctranspose, float] + isempty, transpose, float] VERSION < v"0.7.0-DEV" && push!(elementary_functions, isimag) rounding_functions = [ceil, floor, round, trunc] @@ -46,6 +51,11 @@ using Base.Test, Missings, Compat for f in elementary_functions @test ismissing(f(missing)) end + if isdefined(Base, :adjoint) + @test ismissing(adjoint(missing)) + else + @test ismissing(ctranspose(missing)) + end # All rounding functions return missing when evaluating missing as first argument for f in rounding_functions From 23aac16a8aa99be79192d1e87d48df5fb92b0793 Mon Sep 17 00:00:00 2001 From: quinnj Date: Wed, 10 Jan 2018 17:29:40 -0700 Subject: [PATCH 2/2] fixes --- test/runtests.jl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index c115b84..42816f5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,9 +1,4 @@ -@static if VERSION < v"0.7.0-DEV.2005" - using Base.Test -else - using Test -end -using Missings, Compat +using Missings, Compat, Compat.Test @testset "Missings" begin # test promote rules