Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 3 additions & 7 deletions src/pycall/AwkwardPyCall.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
module AwkwardPyCall

using PyCall
using JSON
using AwkwardArray

const ak = pyimport("awkward")
const np = pyimport("numpy")

function _as_numpy(array::AbstractVector{UInt8})
py_array = PyObject(array)
np.asarray(py_array, dtype = np.uint8)
pyimport("numpy").asarray(py_array, dtype = pyimport("numpy").uint8)
end

function julia_array_to_python(array)
Expand All @@ -21,7 +17,7 @@ function julia_array_to_python(array)
py_buffers[key] = _as_numpy(buffer)
end

return ak.from_buffers(form, len, py_buffers)
return pyimport("awkward").from_buffers(form, len, py_buffers)
end

function _as_julia(py_buffer)
Expand All @@ -30,7 +26,7 @@ function _as_julia(py_buffer)
end

function python_array_to_julia(py_array)
form, len, containers = ak.to_buffers(py_array)
form, len, containers = pyimport("awkward").to_buffers(py_array)

julia_buffers = Dict{String,AbstractVector{UInt8}}()
for (key, buffer) in containers
Expand Down
8 changes: 4 additions & 4 deletions test/runpytests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ using JSON

include("../src/pycall/AwkwardPyCall.jl")

import Main.AwkwardPyCall: ak

import Main.AwkwardPyCall: julia_array_to_python

# Test julia_array_to_python function
Expand All @@ -38,14 +36,16 @@ import Main.AwkwardPyCall: julia_array_to_python
# Test case 2: Check if the awkward array has the correct layout
py_array = julia_array_to_python(array)
@test typeof(py_array) == PyObject
@test ak.to_list(py_array) == [[1.1, 2.2, 3.3], [], [4.4, 5.5]]
@test pyimport("awkward").to_list(py_array) == [[1.1, 2.2, 3.3], [], [4.4, 5.5]]


end

import Main.AwkwardPyCall: python_array_to_julia

# Test python_array_to_julia function
@testset "python_array_to_julia tests" begin
py_array = ak.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]])
py_array = pyimport("awkward").Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]])

# Test case 1: Check if the function returns an awkward array
@test isa(
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3166,4 +3166,5 @@ end
@test df.x == AwkwardArray.to_vector(awt[:x])
@test df.y == AwkwardArray.to_vector(awt[:y])
end

end # @testset "AwkwardArray.jl"