Skip to content

Commit 9f125f1

Browse files
authored
fix: remove global constants (#46)
* 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
1 parent bed29bc commit 9f125f1

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/pycall/AwkwardPyCall.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
module AwkwardPyCall
2-
32
using PyCall
43
using JSON
54
using AwkwardArray
65

7-
const ak = pyimport("awkward")
8-
const np = pyimport("numpy")
9-
106
function _as_numpy(array::AbstractVector{UInt8})
117
py_array = PyObject(array)
12-
np.asarray(py_array, dtype = np.uint8)
8+
pyimport("numpy").asarray(py_array, dtype = pyimport("numpy").uint8)
139
end
1410

1511
function julia_array_to_python(array)
@@ -21,7 +17,7 @@ function julia_array_to_python(array)
2117
py_buffers[key] = _as_numpy(buffer)
2218
end
2319

24-
return ak.from_buffers(form, len, py_buffers)
20+
return pyimport("awkward").from_buffers(form, len, py_buffers)
2521
end
2622

2723
function _as_julia(py_buffer)
@@ -30,7 +26,7 @@ function _as_julia(py_buffer)
3026
end
3127

3228
function python_array_to_julia(py_array)
33-
form, len, containers = ak.to_buffers(py_array)
29+
form, len, containers = pyimport("awkward").to_buffers(py_array)
3430

3531
julia_buffers = Dict{String,AbstractVector{UInt8}}()
3632
for (key, buffer) in containers

test/runpytests.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ using JSON
2222

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

25-
import Main.AwkwardPyCall: ak
26-
2725
import Main.AwkwardPyCall: julia_array_to_python
2826

2927
# Test julia_array_to_python function
@@ -38,14 +36,16 @@ import Main.AwkwardPyCall: julia_array_to_python
3836
# Test case 2: Check if the awkward array has the correct layout
3937
py_array = julia_array_to_python(array)
4038
@test typeof(py_array) == PyObject
41-
@test ak.to_list(py_array) == [[1.1, 2.2, 3.3], [], [4.4, 5.5]]
39+
@test pyimport("awkward").to_list(py_array) == [[1.1, 2.2, 3.3], [], [4.4, 5.5]]
40+
41+
4242
end
4343

4444
import Main.AwkwardPyCall: python_array_to_julia
4545

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

5050
# Test case 1: Check if the function returns an awkward array
5151
@test isa(

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,4 +3166,5 @@ end
31663166
@test df.x == AwkwardArray.to_vector(awt[:x])
31673167
@test df.y == AwkwardArray.to_vector(awt[:y])
31683168
end
3169+
31693170
end # @testset "AwkwardArray.jl"

0 commit comments

Comments
 (0)