Skip to content

Commit

Permalink
fix: remove global constants (#46)
Browse files Browse the repository at this point in the history
* create julia_helpers.jl

* a helper to convert Julia Awkward array to Python

* type lock to a PrimitiveArray

* fix: use np.asarray

* convert only vectors of uint8

* use np.asarray instead

* check if PyCall is installed

* check PyCall installation

* check for PyCall in Main?

* move the import in

* Update and rename julia_helpers.jl to AwkwardPyCall.jl

* try reexport AwkwardArray

* Update AwkwardPyCall.jl

* test: add tests

* fix: remove global constants

* fix: cleanup

* fix: add PyCall

* fix: revert changes

* fix: add AwkwardArray

* fix: include AwkwardArray

* fix: revert changes
  • Loading branch information
ianna authored Nov 28, 2023
1 parent bed29bc commit 9f125f1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
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"

0 comments on commit 9f125f1

Please sign in to comment.