This is an automated email from the ASF dual-hosted git repository.

quinnj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-julia.git


The following commit(s) were added to refs/heads/main by this push:
     new 5231195  implement default for SubArray (#456)
5231195 is described below

commit 5231195705fc8ccb122d04da762e08f454e09cef
Author: Ben Baumgold <[email protected]>
AuthorDate: Thu Jun 8 23:26:31 2023 -0400

    implement default for SubArray (#456)
    
    `similar(::Type{<:SubArray})` doesn't exist. This change should handle
    it gracefully.
    
    ---------
    
    Co-authored-by: Jacob Quinn <[email protected]>
---
 src/ArrowTypes/src/ArrowTypes.jl | 2 ++
 test/runtests.jl                 | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/src/ArrowTypes/src/ArrowTypes.jl b/src/ArrowTypes/src/ArrowTypes.jl
index 6dee157..2245842 100644
--- a/src/ArrowTypes/src/ArrowTypes.jl
+++ b/src/ArrowTypes/src/ArrowTypes.jl
@@ -348,6 +348,8 @@ function default(::Type{A}) where {A <: AbstractVector{T}} 
where {T}
     return a
 end
 
+default(::Type{SubArray{T,N,P,I,L}}) where {T,N,P,I,L} = view(default(P), 0:-1)
+
 default(::Type{NTuple{N, T}}) where {N, T} = ntuple(i -> default(T), N)
 default(::Type{T}) where {T <: Tuple} = Tuple(default(fieldtype(T, i)) for i = 
1:fieldcount(T))
 default(::Type{T}) where {T <: AbstractDict} = T()
diff --git a/test/runtests.jl b/test/runtests.jl
index e0e974b..1c8903f 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -707,6 +707,15 @@ t = Arrow.Table(buf)
 
 end
 
+# @testset "# 456" begin
+
+# NT = @NamedTuple{x::Int, y::Union{Missing,Int}}
+# data = NT[(x=1,y=2), (x=2,y=missing), (x=3,y=4), (x=4,y=5)]
+# t = [(a=1,b=view(data,1:2)), (a=2,b=view(data,3:4)), missing]
+# @test Arrow.toarrowvector(t) isa Arrow.Struct
+
+# end
+
 end # @testset "misc"
 
 end

Reply via email to