From 0b8698ecdf5a758294b72e48effab0b4eb508ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20E=2E=20Cruz=20Serrall=C3=A9s?= Date: Thu, 15 Feb 2024 14:22:15 -0500 Subject: [PATCH 1/7] Added keepat! for StructVector Added method Base.keepat! for StructVector. The code is nearly identical to that of Base.deleteat!. --- src/structarray.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/structarray.jl b/src/structarray.jl index 64ff17a9..0c399041 100644 --- a/src/structarray.jl +++ b/src/structarray.jl @@ -418,6 +418,11 @@ function Base.deleteat!(s::StructVector{T}, idxs) where T 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) function Base.copyto!(I::StructArray, doffs::Integer, J::StructArray, soffs::Integer, n::Integer) From d7d36a2754c2016f4df33ab8f5cda6e50a90d01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20E=2E=20Cruz=20Serrall=C3=A9s?= Date: Thu, 15 Feb 2024 14:27:36 -0500 Subject: [PATCH 2/7] Added test for keepat! --- test/runtests.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index ed6f573a..835fb495 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -259,6 +259,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"]) + 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")] @@ -295,6 +297,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"]) + 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")] From d7c35aa0933961364e269badd0ad697050a86bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20E=2E=20Cruz=20Serrall=C3=A9s?= Date: Thu, 15 Feb 2024 14:28:12 -0500 Subject: [PATCH 3/7] Updated version number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index dd9b3676..5b465623 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "StructArrays" uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" -version = "0.6.16" +version = "0.6.17" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" From 76148b132e036228c8807d650cb6c74e622839ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20E=2E=20Cruz=20Serrall=C3=A9s?= Date: Thu, 15 Feb 2024 14:37:44 -0500 Subject: [PATCH 4/7] Added check for version number in structarray.jl --- src/structarray.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/structarray.jl b/src/structarray.jl index 0c399041..924e1e49 100644 --- a/src/structarray.jl +++ b/src/structarray.jl @@ -418,9 +418,11 @@ function Base.deleteat!(s::StructVector{T}, idxs) where T 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) +@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) From 7f6ea0eebae3959f35eb26c2b9723712befcd34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20E=2E=20Cruz=20Serrall=C3=A9s?= Date: Thu, 15 Feb 2024 14:39:20 -0500 Subject: [PATCH 5/7] Added version check for keepat! tests --- test/runtests.jl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 835fb495..4cd57d53 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -259,8 +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"]) - d = keepat!(c, 2) - @test d == c == StructArray(a=[2], b=[3], c=["b"]) + 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")] @@ -297,8 +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"]) - d = keepat!(c, 2) - @test d == c == StructArray{C}(a=[2], b=[3], c=["b"]) + 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")] From aed41aa979220dc22dc5515422d12aa7796cb2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20E=2E=20Cruz=20Serrall=C3=A9s?= Date: Thu, 15 Feb 2024 14:47:17 -0500 Subject: [PATCH 6/7] Fixed version number Previous version was out-of-date --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 5b465623..d5c32444 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "StructArrays" uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" -version = "0.6.17" +version = "0.6.18" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" From d19f7d38730f7299b339dc57b05be511226680fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20E=2E=20Cruz=20Serrall=C3=A9s?= Date: Fri, 16 Feb 2024 12:19:22 -0500 Subject: [PATCH 7/7] Update Project.toml Bumped version due to breaking changes Co-authored-by: Pietro Vertechi --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index d5c32444..368db5f4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "StructArrays" uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" -version = "0.6.18" +version = "0.7.0" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"