diff --git a/src/Wrap/PyArray.jl b/src/Wrap/PyArray.jl index 64bb3176..4b260ea3 100644 --- a/src/Wrap/PyArray.jl +++ b/src/Wrap/PyArray.jl @@ -639,7 +639,8 @@ function pyarray_offset(x::PyArray{T,N,F}, i::Int) where {T,N,F} end function pyarray_offset(x::PyArray{T,N,F}, i::Vararg{Int,N}) where {T,N,F} - sum((i .- 1) .* x.strides) + # `init` covers 0-d arrays indexed as `x[]`, where `i` is empty + sum((i .- 1) .* x.strides; init=0) end function pyarray_load(::Type{T}, p::Ptr{R}) where {T,R} diff --git a/test/Wrap.jl b/test/Wrap.jl index 4720cdd4..a8d2cfbe 100644 --- a/test/Wrap.jl +++ b/test/Wrap.jl @@ -100,6 +100,16 @@ ) @test_throws Exception PyArray(nd; array = false, buffer = true) end + @testset "0-d" begin + tb = pyimport("_testbuffer") + nd = tb.ndarray(5, shape = pylist(), flags = tb.ND_WRITABLE) + a = PyArray(nd; array = false, buffer = true) + @test ndims(a) == 0 + @test a[] == 5 + a[] = 6 + @test a[] == 6 + @test pyconvert(Int, nd.tolist()) == 6 + end end @testitem "PyDict" begin