Skip to content

Commit b75414d

Browse files
authored
fix: merge rename to convert branch (#49)
1 parent 41db204 commit b75414d

File tree

6 files changed

+36
-49
lines changed

6 files changed

+36
-49
lines changed

ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,33 @@ using PythonCall
33
using JSON
44
import AwkwardArray
55

6-
function _as_numpy(array::AbstractVector{UInt8})
7-
np = pyimport("numpy")
8-
np.asarray(array, dtype = np.uint8)
9-
end
10-
11-
function AwkwardArray.julia_array_to_python(array)
12-
form, len, containers = AwkwardArray.to_buffers(array)
6+
function AwkwardArray.convert(layout::AwkwardArray.Content)::Py
7+
form, len, containers = AwkwardArray.to_buffers(layout)
138

149
py_buffers = Dict{String,Any}()
1510

1611
for (key, buffer) in containers
17-
py_buffers[key] = _as_numpy(buffer)
12+
py_buffers[key] = pyimport("numpy").asarray(buffer, dtype = pyimport("numpy").uint8)
1813
end
1914

20-
return pyimport("awkward").from_buffers(form, len, py_buffers)
15+
pyimport("awkward").from_buffers(form, len, py_buffers)
2116
end
2217

23-
function _as_julia(py_buffer)
24-
uint8_buffer = reinterpret(UInt8, py_buffer)
25-
return uint8_buffer
26-
end
27-
28-
function AwkwardArray.python_array_to_julia(py_array)
29-
form, len, _containers = pyimport("awkward").to_buffers(py_array)
18+
function AwkwardArray.convert(array::Py)::AwkwardArray.Content
19+
form, len, _containers = pyimport("awkward").to_buffers(array)
3020
containers = pyconvert(Dict, _containers)
3121

3222
julia_buffers = Dict{String,AbstractVector{UInt8}}()
23+
3324
for (key, buffer) in containers
34-
julia_buffers[key] = _as_julia(buffer)
25+
julia_buffers[key] = reinterpret(UInt8, buffer)
3526
end
3627

37-
return AwkwardArray.from_buffers(pyconvert(String, form.to_json()), pyconvert(Int, len), julia_buffers)
28+
AwkwardArray.from_buffers(
29+
pyconvert(String, form.to_json()),
30+
pyconvert(Int, len),
31+
julia_buffers,
32+
)
3833
end
3934

4035
end # module

ext/AwkwardPythonCallExt/README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
[PyCall](https://github.com/JuliaPy/PyCall.jl) is currently configured to use the Julia-specific Python distribution
2-
installed by the [Conda.jl](https://github.com/JuliaPy/Conda.jl) package.
3-
4-
conda create --name ak-julia
5-
conda activate ak-julia
6-
conda install -c conda-forge awkward
1+
[PythonCall](https://github.com/JuliaPy/PythonCall.jl) is currently configured to use the Julia-specific Python distribution
2+
installed by the [CondaPkg.jl](https://github.com/JuliaPy/CondaPkg.jl) package.
73

84
```julia
9-
using Conda
10-
Conda.add("awkward")
5+
using CondaPkg
6+
CondaPkg.add("numpy")
7+
CondaPkg.add("awkward")
118
```
129

1310
```julia
14-
using PyCall
11+
using PythonCall
1512

1613
const ak = pyimport("awkward")
1714

18-
test() = println(ak.__version__)
19-
20-
test()
21-
2.4.6
15+
println(ak.__version__)
16+
2.5.0
2217
```

src/AwkwardArray.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import Tables
66
include("./all_implementations.jl")
77
include("./tables.jl")
88

9-
# stub for PyCall Extention
10-
function julia_array_to_python end
11-
function python_array_to_julia end
12-
9+
# stub for PythonCall Extention
10+
function convert end
1311

1412
end # module AwkwardArray

src/all_implementations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3606,4 +3606,4 @@ function _to_buffers_index(IndexType::DataType)
36063606
else
36073607
error("unexpected INDEX type in to_buffers: $IndexType")
36083608
end
3609-
end
3609+
end

test/runpytests.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
using PythonCall
2-
using AwkwardArray: julia_array_to_python
1+
using PythonCall
2+
using AwkwardArray: convert
33

4-
# Test julia_array_to_python function
5-
@testset "julia_array_to_python tests" begin
4+
# Test convert Julia array to Python function
5+
@testset "convert Julia array to Python tests" begin
66
array = AwkwardArray.ListOffsetArray(
77
[0, 3, 3, 5],
88
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
99
)
10+
py_array = convert(array)
11+
1012
# Test case 1: Check if the function returns an awkward array
11-
@test isa(julia_array_to_python(array), Py)
13+
@test py_array isa Py
1214

1315
# Test case 2: Check if the awkward array has the correct layout
14-
py_array = julia_array_to_python(array)
1516
@test typeof(py_array) == Py
17+
1618
ak_array = pyconvert(Vector, pyimport("awkward").to_list(py_array))
1719
@test ak_array == [[1.1, 2.2, 3.3], [], [4.4, 5.5]]
1820

19-
2021
end
2122

22-
using AwkwardArray: python_array_to_julia
23-
24-
# Test python_array_to_julia function
25-
@testset "python_array_to_julia tests" begin
23+
# Test convert Python array to Julia function
24+
@testset "convert Python array to Julia tests" begin
2625
py_array = pyimport("awkward").Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]])
2726

28-
array = python_array_to_julia(py_array)
2927
# Test case 1: Check if the function returns an awkward array
28+
array = convert(py_array)
3029
@test array isa AwkwardArray.ListOffsetArray
3130

3231
@test array == [[1.1, 2.2, 3.3], [], [4.4, 5.5]]

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3170,4 +3170,4 @@ end
31703170

31713171
end # @testset "AwkwardArray.jl"
31723172

3173-
include("./runpytests.jl")
3173+
include("./runpytests.jl")

0 commit comments

Comments
 (0)