Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "StructArrays"
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
version = "0.6.16"
version = "0.6.18"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
7 changes: 7 additions & 0 deletions src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,13 @@ 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
end

Base.copyto!(I::StructArray, J::StructArray) = (foreachfield(copyto!, I, J); I)

function Base.copyto!(I::StructArray, doffs::Integer, J::StructArray, soffs::Integer, n::Integer)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ 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

c = StructArray(a=[1], b=[2], c=["a"])
d = [(a=10, b=20, c="A")]
Expand Down Expand Up @@ -295,6 +299,10 @@ 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

c = StructArray{C}(a=[1], b=[2], c=["a"])
d = [C(10, 20, "A")]
Expand Down