You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by qu...@apache.org on 2022/11/28 23:10:14 UTC

[arrow-julia] 01/01: Ensure elements are converted when indexed from ArrowTypes.ToArrow

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

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

commit 09c34453fbe4c11c49c959a65f9ea9c9d70f92af
Author: Jacob Quinn <qu...@gmail.com>
AuthorDate: Mon Nov 28 15:50:26 2022 -0700

    Ensure elements are converted when indexed from ArrowTypes.ToArrow
    
    Fixes #364. This is an unfortunate bug that was sneaking in under
    the guise of "supposedly passing" tests. i.e. we had a test like:
    
    ```julia
    @test ArrowTypes.ToArrow(Any[1, 3.14]) == [1.0, 3.14]
    ```
    _BUT_, this was misleading, because, in reality, we had:
    
    ```julia
    x = ArrowTypes.ToArrow(Any[1, 3.14])
    @test x === 1
    ```
    
    i.e. when you indexed an element of `ToArrow`, no actual conversion
    was happening. So even though `ToArrow` was doing the work of figuring
    out the right concrete promoted type or union type, when you indexed
    later, it was just giving you the original element. Which actually
    works in a number of cases, for example, if the promoted type was a
    `Union` and all elements were one of the Union types, but in this case,
    where the promoted case was `Float64` and one element was an integer,
    we just got the plain integer out, when in reality, we want that integer
    converted to a float.
---
 Project.toml                     | 2 +-
 src/ArrowTypes/src/ArrowTypes.jl | 2 +-
 src/ArrowTypes/test/tests.jl     | 4 +++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Project.toml b/Project.toml
index 3f060c5..e10125c 100644
--- a/Project.toml
+++ b/Project.toml
@@ -37,7 +37,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
 WorkerUtilities = "76eceee3-57b5-4d4a-8e66-0e911cebbf60"
 
 [compat]
-ArrowTypes = "1.1"
+ArrowTypes = "1.1,2"
 BitIntegers = "0.2"
 CodecLz4 = "0.4"
 CodecZstd = "0.7"
diff --git a/src/ArrowTypes/src/ArrowTypes.jl b/src/ArrowTypes/src/ArrowTypes.jl
index 6117896..1313845 100644
--- a/src/ArrowTypes/src/ArrowTypes.jl
+++ b/src/ArrowTypes/src/ArrowTypes.jl
@@ -354,6 +354,6 @@ end
 Base.IndexStyle(::Type{<:ToArrow}) = Base.IndexLinear()
 Base.size(x::ToArrow) = (length(x.data),)
 Base.eltype(x::ToArrow{T, A}) where {T, A} = T
-Base.getindex(x::ToArrow{T}, i::Int) where {T} = toarrow(getindex(x.data, i))
+Base.getindex(x::ToArrow{T}, i::Int) where {T} = toarrow(convert(T, getindex(x.data, i)))
 
 end # module ArrowTypes
diff --git a/src/ArrowTypes/test/tests.jl b/src/ArrowTypes/test/tests.jl
index eeeb2e2..7552d89 100644
--- a/src/ArrowTypes/test/tests.jl
+++ b/src/ArrowTypes/test/tests.jl
@@ -141,7 +141,9 @@ v_nt = (major=1, minor=0, patch=0, prerelease=(), build=())
 
 @test ArrowTypes.ToArrow([1,2,3]) == [1,2,3]
 @test ArrowTypes.ToArrow([:hey, :ho]) == ["hey", "ho"]
-@test ArrowTypes.ToArrow(Any[1, 3.14]) == [1.0, 3.14]
+x = ArrowTypes.ToArrow(Any[1, 3.14])
+@test x[1] === 1.0
+@test x[2] === 3.14
 @test ArrowTypes.ToArrow(Any[1, 3.14, "hey"]) == [1.0, 3.14, "hey"]
 
 end