Skip to content

Get rid of all VERSION checks #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/collect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 3 additions & 5 deletions src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
64 changes: 17 additions & 47 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)]

Expand Down
Loading