diff --git a/src/collect.jl b/src/collect.jl index bab99f3..c66c84c 100644 --- a/src/collect.jl +++ b/src/collect.jl @@ -160,10 +160,7 @@ _append!!(dest::AbstractVector, itr, ::Base.SizeUnknown) = grow_to_structarray!(dest, itr) # Optimized version when element collection is an `AbstractVector` -# This only works for julia 1.3 or greater, which has `append!` for `AbstractVector` -@static if VERSION ≥ v"1.3.0" - function append!!(dest::V, v::AbstractVector{T}) where {V<:AbstractVector, T} - new = iscompatible(T, V) ? dest : widen_from_type(dest, length(dest) + 1, T) - return append!(new, v) - end +function append!!(dest::V, v::AbstractVector{T}) where {V<:AbstractVector, T} + new = iscompatible(T, V) ? dest : widen_from_type(dest, length(dest) + 1, T) + return append!(new, v) end diff --git a/src/structarray.jl b/src/structarray.jl index 0f13ad4..757653b 100644 --- a/src/structarray.jl +++ b/src/structarray.jl @@ -414,11 +414,9 @@ function Base.deleteat!(s::StructVector{T}, idxs) where T return StructVector{T}(t) end -@static if VERSION >= v"1.7.0" - function Base.keepat!(s::StructVector{T}, idxs) where T - t = map(Base.Fix2(keepat!, idxs), components(s)) - return StructVector{T}(t) - end +function Base.keepat!(s::StructVector{T}, idxs) where T + t = map(Base.Fix2(keepat!, idxs), components(s)) + return StructVector{T}(t) end Base.copyto!(I::StructArray, J::StructArray) = (foreachfield(copyto!, I, J); I) diff --git a/src/utils.jl b/src/utils.jl index 741e630..2ecc22b 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -143,11 +143,7 @@ julia> s = StructArray(a=1:3, b = fill("string", 3)); julia> s_pooled = StructArrays.replace_storage(s) do v isbitstype(eltype(v)) ? v : convert(PooledArray, v) end -$(if VERSION < v"1.6-" - "3-element StructArray(::UnitRange{Int64}, ::PooledArray{String,UInt32,1,Array{UInt32,1}}) with eltype $(NamedTuple{(:a, :b),Tuple{Int64,String}}):" -else - "3-element StructArray(::UnitRange{Int64}, ::PooledVector{String, UInt32, Vector{UInt32}}) with eltype $(NamedTuple{(:a, :b), Tuple{Int64, String}}):" -end) +3-element StructArray(::UnitRange{Int64}, ::PooledVector{String, UInt32, Vector{UInt32}}) with eltype $(NamedTuple{(:a, :b), Tuple{Int64, String}}): (a = 1, b = "string") (a = 2, b = "string") (a = 3, b = "string") diff --git a/test/runtests.jl b/test/runtests.jl index 0a57817..d565b4b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -17,7 +17,7 @@ import KernelAbstractions as KA import Tables, PooledArrays, WeakRefStrings using Documenter: doctest -if Base.VERSION == v"1.6" && Int === Int64 +if v"1.10" ≤ Base.VERSION < v"1.11" && Int === Int64 doctest(StructArrays) end @@ -262,10 +262,8 @@ end @test d == c == StructArray(a=[1,10,2,3], b=[2,20,3,4], c=["a","A","b","c"]) d = deleteat!(c, 2) @test d == c == StructArray(a=[1,2,3], b=[2,3,4], c=["a","b","c"]) - if Base.VERSION >= v"1.7.0" - d = keepat!(c, 2) - @test d == c == StructArray(a=[2], b=[3], c=["b"]) - end + d = keepat!(c, 2) + @test d == c == StructArray(a=[2], b=[3], c=["b"]) c = StructArray(a=[1], b=[2], c=["a"]) d = [(a=10, b=20, c="A")] @@ -302,10 +300,8 @@ end @test d == c == StructArray{C}(a=[1,10,2,3], b=[2,20,3,4], c=["a","A","b","c"]) d = deleteat!(c, 2) @test d == c == StructArray{C}(a=[1,2,3], b=[2,3,4], c=["a","b","c"]) - if Base.VERSION >= v"1.7.0" - d = keepat!(c, 2) - @test d == c == StructArray{C}(a=[2], b=[3], c=["b"]) - end + d = keepat!(c, 2) + @test d == c == StructArray{C}(a=[2], b=[3], c=["b"]) c = StructArray{C}(a=[1], b=[2], c=["a"]) d = [C(10, 20, "A")] @@ -491,14 +487,12 @@ end end @testset "constructor from slices" begin - if VERSION >= v"1.1" - X = [1.0 2.0; 3.0 4.0] - @test StructArray{Complex{Float64}}(X; dims=1) == [Complex(1.0,3.0), Complex(2.0,4.0)] - @test StructArray{Complex{Float64}}(X; dims=2) == [Complex(1.0,2.0), Complex(3.0,4.0)] + X = [1.0 2.0; 3.0 4.0] + @test StructArray{Complex{Float64}}(X; dims=1) == [Complex(1.0,3.0), Complex(2.0,4.0)] + @test StructArray{Complex{Float64}}(X; dims=2) == [Complex(1.0,2.0), Complex(3.0,4.0)] - X = [1.0 2.0; 3.0 4.0; 5.0 6.0] - @test StructArray{Tuple{Float64,Complex{Float64}}}(X; dims=1) == [(1.0,Complex(3.0,5.0)), (2.0, Complex(4.0,6.0))] - end + X = [1.0 2.0; 3.0 4.0; 5.0 6.0] + @test StructArray{Tuple{Float64,Complex{Float64}}}(X; dims=1) == [(1.0,Complex(3.0,5.0)), (2.0, Complex(4.0,6.0))] end struct A @@ -1105,19 +1099,11 @@ end io = IOBuffer() Base.showarg(io, rows, true) str = String(take!(io)) - if VERSION < v"1.6-" - @test str == "LazyRows(::Array{Float64,2}, ::Array{Float64,2}) with eltype LazyRow{Complex{Float64}}" - else - @test str == "LazyRows(::Matrix{Float64}, ::Matrix{Float64}) with eltype LazyRow{ComplexF64}" - end + @test str == "LazyRows(::Matrix{Float64}, ::Matrix{Float64}) with eltype LazyRow{ComplexF64}" io = IOBuffer() Base.showarg(io, rows, false) str = String(take!(io)) - if VERSION < v"1.6-" - @test str == "LazyRows(::Array{Float64,2}, ::Array{Float64,2})" - else - @test str == "LazyRows(::Matrix{Float64}, ::Matrix{Float64})" - end + @test str == "LazyRows(::Matrix{Float64}, ::Matrix{Float64})" s = StructArray((rand(10, 10), rand(10, 10))) rows = LazyRows(s) @test IndexStyle(rows) isa IndexLinear @@ -1137,19 +1123,11 @@ end io = IOBuffer() Base.showarg(io, rows, true) str = String(take!(io)) - if VERSION < v"1.6-" - @test str == "LazyRows(::Array{Float64,2}, ::Array{Float64,2}) with eltype LazyRow{Tuple{Float64,Float64}}" - else - @test str == "LazyRows(::Matrix{Float64}, ::Matrix{Float64}) with eltype LazyRow{Tuple{Float64, Float64}}" - end + @test str == "LazyRows(::Matrix{Float64}, ::Matrix{Float64}) with eltype LazyRow{Tuple{Float64, Float64}}" io = IOBuffer() Base.showarg(io, rows, false) str = String(take!(io)) - if VERSION < v"1.6-" - @test str == "LazyRows(::Array{Float64,2}, ::Array{Float64,2})" - else - @test str == "LazyRows(::Matrix{Float64}, ::Matrix{Float64})" - end + @test str == "LazyRows(::Matrix{Float64}, ::Matrix{Float64})" end @testset "refarray" begin @@ -1179,19 +1157,11 @@ end io = IOBuffer() Base.showarg(io, s, true) str = String(take!(io)) - if VERSION < v"1.6-" - @test str == "StructArray(::Array{Int64,1}, ::Array{Int64,1}) with eltype Complex{Int64}" - else - @test str == "StructArray(::Vector{Int64}, ::Vector{Int64}) with eltype Complex{Int64}" - end + @test str == "StructArray(::Vector{Int64}, ::Vector{Int64}) with eltype Complex{Int64}" io = IOBuffer() Base.showarg(io, s, false) str = String(take!(io)) - if VERSION < v"1.6-" - @test str == "StructArray(::Array{Int64,1}, ::Array{Int64,1})" - else - @test str == "StructArray(::Vector{Int64}, ::Vector{Int64})" - end + @test str == "StructArray(::Vector{Int64}, ::Vector{Int64})" end @testset "append!!" begin @@ -1468,7 +1438,7 @@ end t = map(x -> (a=rand(["", 1, nothing]),), StructVector(a=1:10))::StructVector @test eltype(t) <: NamedTuple{(:a,)} - t = VERSION >= v"1.7" ? @inferred(map(x -> (a=x.a, b=2), s)) : map(x -> (a=x.a, b=2), s) + t = @inferred map(x -> (a=x.a, b=2), s) @test t isa StructArray @test map(x -> (a=x.a, b=2), s) == [(a=1, b=2), (a=2, b=2), (a=3, b=2)]