From ee0d3e10938b7323ac5c3e81e96ed3645c319582 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Mon, 11 Dec 2023 10:22:08 +0100 Subject: [PATCH 01/16] feat: add a method to convert `PyIterable` --- ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl b/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl index fed937f..1bfd1ec 100644 --- a/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl +++ b/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl @@ -32,4 +32,20 @@ function AwkwardArray.convert(array::Py)::AwkwardArray.Content ) end +function AwkwardArray.convert(array::PyIterable{Any})::AwkwardArray.Content + form, len, _containers = pyimport("awkward").to_buffers(array) + containers = pyconvert(Dict, _containers) + + julia_buffers = Dict{String,AbstractVector{UInt8}}() + for (key, buffer) in containers + julia_buffers[key] = reinterpret(UInt8, buffer) + end + + AwkwardArray.from_buffers( + pyconvert(String, form.to_json()), + pyconvert(Int, len), + julia_buffers, + ) +end + end # module From e3c09a5803a3121d2d5792db04ee93467f35a9ff Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 12 Dec 2023 15:44:34 +0100 Subject: [PATCH 02/16] feat: add auto conversion rules --- .../AwkwardPythonCallExt.jl | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl b/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl index 1bfd1ec..68ca778 100644 --- a/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl +++ b/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl @@ -48,4 +48,45 @@ function AwkwardArray.convert(array::PyIterable{Any})::AwkwardArray.Content ) end + +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.PrimitiveArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.EmptyArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListOffsetArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RegularArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.StringOffsetArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.StringArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.StringRegularArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteStringOffsetArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteStringArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteStringRegularArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RecordArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.TupleArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedOptionArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteMaskedArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.BitMaskedArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnmaskedArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnionArray}, x::Py) = AwkwardArray.convert(x) + +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.PrimitiveArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.EmptyArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListOffsetArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RegularArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.StringOffsetArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.StringArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.StringRegularArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteStringOffsetArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteStringArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteStringRegularArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RecordArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.TupleArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedOptionArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteMaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.BitMaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.UnmaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.UnionArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + end # module From 5ab43352bd424998cbfc60c652aafbf0ac95cc97 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Thu, 14 Dec 2023 16:59:10 +0100 Subject: [PATCH 03/16] fix: update conversion rules --- ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl b/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl index 68ca778..f3c0450 100644 --- a/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl +++ b/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl @@ -49,17 +49,12 @@ function AwkwardArray.convert(array::PyIterable{Any})::AwkwardArray.Content end + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.PrimitiveArray}, x::Py) = AwkwardArray.convert(x) PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.EmptyArray}, x::Py) = AwkwardArray.convert(x) PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListOffsetArray}, x::Py) = AwkwardArray.convert(x) PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListArray}, x::Py) = AwkwardArray.convert(x) PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RegularArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.StringOffsetArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.StringArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.StringRegularArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteStringOffsetArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteStringArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteStringRegularArray}, x::Py) = AwkwardArray.convert(x) PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RecordArray}, x::Py) = AwkwardArray.convert(x) PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.TupleArray}, x::Py) = AwkwardArray.convert(x) PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedArray}, x::Py) = AwkwardArray.convert(x) @@ -74,12 +69,6 @@ PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.EmptyArray PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListOffsetArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RegularArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.StringOffsetArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.StringArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.StringRegularArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteStringOffsetArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteStringArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -# FIXME: PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteStringRegularArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RecordArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.TupleArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) From 7af724dc3fdda09dace4545f184881ba91c9a6e9 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 17 Jan 2024 14:14:10 +0100 Subject: [PATCH 04/16] feat: define __init__ function --- Project.toml | 2 +- .../AwkwardPythonCallExt.jl | 57 ++++++++++--------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Project.toml b/Project.toml index c78d433..6f79a23 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "AwkwardArray" uuid = "7d259134-7f60-4bf1-aa00-7452e11bde56" authors = ["Jim Pivarski ", "Jerry Ling ", "and contributors"] -version = "0.1.2" +version = "0.1.3" [deps] JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" diff --git a/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl b/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl index f3c0450..fe4b91d 100644 --- a/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl +++ b/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl @@ -49,33 +49,34 @@ function AwkwardArray.convert(array::PyIterable{Any})::AwkwardArray.Content end - -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.PrimitiveArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.EmptyArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListOffsetArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RegularArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RecordArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.TupleArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedOptionArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteMaskedArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.BitMaskedArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnmaskedArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnionArray}, x::Py) = AwkwardArray.convert(x) - -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.PrimitiveArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.EmptyArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListOffsetArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RegularArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RecordArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.TupleArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedOptionArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteMaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.BitMaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.UnmaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) -PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.UnionArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +function __init__() + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.PrimitiveArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.EmptyArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListOffsetArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RegularArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RecordArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.TupleArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedOptionArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteMaskedArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.BitMaskedArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnmaskedArray}, x::Py) = AwkwardArray.convert(x) + PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnionArray}, x::Py) = AwkwardArray.convert(x) + + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.PrimitiveArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.EmptyArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListOffsetArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RegularArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RecordArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.TupleArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedOptionArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteMaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.BitMaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.UnmaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.UnionArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) +end end # module From 009bcafae0bad9da9a07d466b16f0a0e2dd9ae83 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 17 Jan 2024 14:23:36 +0100 Subject: [PATCH 05/16] fix: move convert out of the __init__ function --- .../AwkwardPythonCallExt.jl | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl b/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl index fe4b91d..eab0a4f 100644 --- a/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl +++ b/ext/AwkwardPythonCallExt/AwkwardPythonCallExt.jl @@ -49,21 +49,22 @@ function AwkwardArray.convert(array::PyIterable{Any})::AwkwardArray.Content end -function __init__() - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.PrimitiveArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.EmptyArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListOffsetArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RegularArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RecordArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.TupleArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedOptionArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteMaskedArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.BitMaskedArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnmaskedArray}, x::Py) = AwkwardArray.convert(x) - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnionArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.PrimitiveArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.EmptyArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListOffsetArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RegularArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RecordArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.TupleArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedOptionArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteMaskedArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.BitMaskedArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnmaskedArray}, x::Py) = AwkwardArray.convert(x) +PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnionArray}, x::Py) = AwkwardArray.convert(x) + +function __init__() PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.PrimitiveArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.EmptyArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListOffsetArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) From d6000ab09887874857c000211649492c361a6822 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 17 Jan 2024 14:31:22 +0100 Subject: [PATCH 06/16] test: add a test passing a Python array to a Julia function --- Project.toml | 2 +- test/runpytests.jl | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 6f79a23..c78d433 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "AwkwardArray" uuid = "7d259134-7f60-4bf1-aa00-7452e11bde56" authors = ["Jim Pivarski ", "Jerry Ling ", "and contributors"] -version = "0.1.3" +version = "0.1.2" [deps] JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" diff --git a/test/runpytests.jl b/test/runpytests.jl index e0ab499..fd65e29 100644 --- a/test/runpytests.jl +++ b/test/runpytests.jl @@ -30,3 +30,15 @@ end @test array == [[1.1, 2.2, 3.3], [], [4.4, 5.5]] end + +# Test passing Python array to Julia function +@testset "pass Python array to Julia test" begin + function f1(x) + x + end + + py_array = pyimport("awkward").Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]]) + + array = f1(py_array) + @test array isa AwkwardArray.ListOffsetArray +end From f2b14066271ca5234997f2b05c56aa60442065ba Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 23 Jan 2024 11:17:50 +0100 Subject: [PATCH 07/16] feat: define conversion rules --- Project.toml | 14 +++++--------- src/AwkwardArray.jl | 5 +++-- .../AwkwardPythonCallExt.jl | 0 test/runpytests.jl | 3 ++- 4 files changed, 10 insertions(+), 12 deletions(-) rename {ext/AwkwardPythonCallExt => src}/AwkwardPythonCallExt.jl (100%) diff --git a/Project.toml b/Project.toml index c78d433..b5455c0 100644 --- a/Project.toml +++ b/Project.toml @@ -4,23 +4,19 @@ authors = ["Jim Pivarski ", "Jerry Ling Date: Tue, 23 Jan 2024 12:11:30 +0100 Subject: [PATCH 08/16] fix: remove convertion of an iterable --- src/AwkwardPythonCallExt.jl | 16 ---------------- test/runpytests.jl | 5 ++--- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/AwkwardPythonCallExt.jl b/src/AwkwardPythonCallExt.jl index eab0a4f..040365a 100644 --- a/src/AwkwardPythonCallExt.jl +++ b/src/AwkwardPythonCallExt.jl @@ -32,22 +32,6 @@ function AwkwardArray.convert(array::Py)::AwkwardArray.Content ) end -function AwkwardArray.convert(array::PyIterable{Any})::AwkwardArray.Content - form, len, _containers = pyimport("awkward").to_buffers(array) - containers = pyconvert(Dict, _containers) - - julia_buffers = Dict{String,AbstractVector{UInt8}}() - for (key, buffer) in containers - julia_buffers[key] = reinterpret(UInt8, buffer) - end - - AwkwardArray.from_buffers( - pyconvert(String, form.to_json()), - pyconvert(Int, len), - julia_buffers, - ) -end - PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.PrimitiveArray}, x::Py) = AwkwardArray.convert(x) PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.EmptyArray}, x::Py) = AwkwardArray.convert(x) diff --git a/test/runpytests.jl b/test/runpytests.jl index d32e935..fcbb298 100644 --- a/test/runpytests.jl +++ b/test/runpytests.jl @@ -34,12 +34,11 @@ end # Test passing Python array to Julia function @testset "pass Python array to Julia test" begin function f1(x) - print(typeof(x)) - x + convert(x) # FIXME invoke convert when passing Py as an argument? end py_array = pyimport("awkward").Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]]) array = f1(py_array) - @test array isa Py #AwkwardArray.ListOffsetArray + @test array isa AwkwardArray.ListOffsetArray end From 11c7c4681f985d79315fa03ff0e60c79f173a4cc Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 23 Jan 2024 15:07:01 +0100 Subject: [PATCH 09/16] feat: add rules and register --- src/AwkwardPythonCallExt.jl | 114 ++++++++++++++++++++++++++++-------- test/runpytests.jl | 2 + 2 files changed, 90 insertions(+), 26 deletions(-) diff --git a/src/AwkwardPythonCallExt.jl b/src/AwkwardPythonCallExt.jl index 040365a..bbec639 100644 --- a/src/AwkwardPythonCallExt.jl +++ b/src/AwkwardPythonCallExt.jl @@ -32,36 +32,98 @@ function AwkwardArray.convert(array::Py)::AwkwardArray.Content ) end +# rule functions +function pyconvert_rule_awkward_array_primitive(::Type{AwkwardArray.PrimitiveArray}, x::Py) + py_arr = pyconvert(AwkwardArray.PrimitiveArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end + +function pyconvert_rule_awkward_array_empty(::Type{AwkwardArray.EmptyArray}, x::Py) + py_arr = pyconvert(AwkwardArray.EmptyArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end + +function pyconvert_rule_awkward_array_listoffset(::Type{AwkwardArray.ListOffsetArray}, x::Py) + py_arr = pyconvert(AwkwardArray.ListOffsetArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end + +function pyconvert_rule_awkward_array_list(::Type{AwkwardArray.ListArray}, x::Py) + py_arr = pyconvert(AwkwardArray.ListArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end +function pyconvert_rule_awkward_array_regular(::Type{AwkwardArray.RegularArray}, x::Py) + py_arr = pyconvert(AwkwardArray.RegularArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end + +function pyconvert_rule_awkward_array_record(::Type{AwkwardArray.RecordArray}, x::Py) + py_arr = pyconvert(AwkwardArray.RecordArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end + +function pyconvert_rule_awkward_array_tuple(::Type{AwkwardArray.TupleArray}, x::Py) + py_arr = pyconvert(AwkwardArray.TupleArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end + +function pyconvert_rule_awkward_array_indexed(::Type{AwkwardArray.IndexedArray}, x::Py) + py_arr = pyconvert(AwkwardArray.IndexedArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.PrimitiveArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.EmptyArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListOffsetArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ListArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RegularArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.RecordArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.TupleArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.IndexedOptionArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.ByteMaskedArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.BitMaskedArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnmaskedArray}, x::Py) = AwkwardArray.convert(x) -PythonCall.pyconvert_rule_array_nocopy(::Type{AwkwardArray.UnionArray}, x::Py) = AwkwardArray.convert(x) +function pyconvert_rule_awkward_array_indexedoption(::Type{AwkwardArray.IndexedOptionArray}, x::Py) + py_arr = pyconvert(AwkwardArray.IndexedOptionArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end + +function pyconvert_rule_awkward_array_bytemasked(::Type{AwkwardArray.ByteMaskedArray}, x::Py) + py_arr = pyconvert(AwkwardArray.ByteMaskedArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end +function pyconvert_rule_awkward_array_bitmasked(::Type{AwkwardArray.BitMaskedArray}, x::Py) + py_arr = pyconvert(AwkwardArray.BitMaskedArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end + +function pyconvert_rule_awkward_array_unmasked(::Type{AwkwardArray.UnmaskedArray}, x::Py) + py_arr = pyconvert(AwkwardArray.UnmaskedArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end + +function pyconvert_rule_awkward_array_union(::Type{AwkwardArray.UnionArray}, x::Py) + py_arr = pyconvert(AwkwardArray.UnionArray, x) + array = AwkwardArray.convert(py_arr) + return PythonCall.pyconvert_return(array) +end function __init__() - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.PrimitiveArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.EmptyArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListOffsetArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RegularArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RecordArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.TupleArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedOptionArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteMaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.BitMaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.UnmaskedArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) - PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.UnionArray, PythonCall.pyconvert_rule_array_nocopy, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.PrimitiveArray, pyconvert_rule_awkward_array_primitive, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.EmptyArray, pyconvert_rule_awkward_array_empty, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListOffsetArray, pyconvert_rule_awkward_array_listoffset, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ListArray, pyconvert_rule_awkward_array_list, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RegularArray, pyconvert_rule_awkward_array_regular, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.RecordArray, pyconvert_rule_awkward_array_record, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.TupleArray, pyconvert_rule_awkward_array_tuple, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedArray, pyconvert_rule_awkward_array_indexed, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.IndexedOptionArray, pyconvert_rule_awkward_array_indexedoption, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.ByteMaskedArray, pyconvert_rule_awkward_array_bytemasked, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.BitMaskedArray, pyconvert_rule_awkward_array_bitmasked, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.UnmaskedArray, pyconvert_rule_awkward_array_unmasked, PythonCall.PYCONVERT_PRIORITY_ARRAY) + PythonCall.pyconvert_add_rule("awkward.highlevel:Array", AwkwardArray.UnionArray, pyconvert_rule_awkward_array_union, PythonCall.PYCONVERT_PRIORITY_ARRAY) end end # module diff --git a/test/runpytests.jl b/test/runpytests.jl index fcbb298..04c5429 100644 --- a/test/runpytests.jl +++ b/test/runpytests.jl @@ -34,6 +34,8 @@ end # Test passing Python array to Julia function @testset "pass Python array to Julia test" begin function f1(x) + println(typeof(x)) + println(typeof(convert(x))) convert(x) # FIXME invoke convert when passing Py as an argument? end From 3b8663e02f7954c44cc75e8ebca164cf72899f5c Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 23 Jan 2024 15:15:55 +0100 Subject: [PATCH 10/16] fix: leave it to a user to invoke pyconvert --- src/AwkwardPythonCallExt.jl | 39 +++++++++++++------------------------ test/runpytests.jl | 2 +- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/AwkwardPythonCallExt.jl b/src/AwkwardPythonCallExt.jl index bbec639..e906efb 100644 --- a/src/AwkwardPythonCallExt.jl +++ b/src/AwkwardPythonCallExt.jl @@ -34,79 +34,66 @@ end # rule functions function pyconvert_rule_awkward_array_primitive(::Type{AwkwardArray.PrimitiveArray}, x::Py) - py_arr = pyconvert(AwkwardArray.PrimitiveArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_empty(::Type{AwkwardArray.EmptyArray}, x::Py) - py_arr = pyconvert(AwkwardArray.EmptyArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_listoffset(::Type{AwkwardArray.ListOffsetArray}, x::Py) - py_arr = pyconvert(AwkwardArray.ListOffsetArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_list(::Type{AwkwardArray.ListArray}, x::Py) - py_arr = pyconvert(AwkwardArray.ListArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_regular(::Type{AwkwardArray.RegularArray}, x::Py) - py_arr = pyconvert(AwkwardArray.RegularArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_record(::Type{AwkwardArray.RecordArray}, x::Py) - py_arr = pyconvert(AwkwardArray.RecordArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_tuple(::Type{AwkwardArray.TupleArray}, x::Py) - py_arr = pyconvert(AwkwardArray.TupleArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_indexed(::Type{AwkwardArray.IndexedArray}, x::Py) - py_arr = pyconvert(AwkwardArray.IndexedArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_indexedoption(::Type{AwkwardArray.IndexedOptionArray}, x::Py) - py_arr = pyconvert(AwkwardArray.IndexedOptionArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_bytemasked(::Type{AwkwardArray.ByteMaskedArray}, x::Py) - py_arr = pyconvert(AwkwardArray.ByteMaskedArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_bitmasked(::Type{AwkwardArray.BitMaskedArray}, x::Py) - py_arr = pyconvert(AwkwardArray.BitMaskedArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_unmasked(::Type{AwkwardArray.UnmaskedArray}, x::Py) - py_arr = pyconvert(AwkwardArray.UnmaskedArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end function pyconvert_rule_awkward_array_union(::Type{AwkwardArray.UnionArray}, x::Py) - py_arr = pyconvert(AwkwardArray.UnionArray, x) - array = AwkwardArray.convert(py_arr) + array = AwkwardArray.convert(x) return PythonCall.pyconvert_return(array) end diff --git a/test/runpytests.jl b/test/runpytests.jl index 04c5429..76b5e44 100644 --- a/test/runpytests.jl +++ b/test/runpytests.jl @@ -36,7 +36,7 @@ end function f1(x) println(typeof(x)) println(typeof(convert(x))) - convert(x) # FIXME invoke convert when passing Py as an argument? + pyconvert(Any, x) # FIXME invoke convert when passing Py as an argument? end py_array = pyimport("awkward").Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]]) From 9ea8d9c0b18b50086a747e0ade1247fc38e98b7c Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 23 Jan 2024 16:06:13 +0100 Subject: [PATCH 11/16] test: test pyconvert of an awkward array --- test/runpytests.jl | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/test/runpytests.jl b/test/runpytests.jl index 76b5e44..148a72e 100644 --- a/test/runpytests.jl +++ b/test/runpytests.jl @@ -31,16 +31,10 @@ end @test array == [[1.1, 2.2, 3.3], [], [4.4, 5.5]] end -# Test passing Python array to Julia function -@testset "pass Python array to Julia test" begin - function f1(x) - println(typeof(x)) - println(typeof(convert(x))) - pyconvert(Any, x) # FIXME invoke convert when passing Py as an argument? - end - +# Test pyconvert Python array to Julia +@testset "convert Python array to Julia test" begin py_array = pyimport("awkward").Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]]) - array = f1(py_array) + array = pyconvert(Any, py_array) @test array isa AwkwardArray.ListOffsetArray end From 34f33a79af903350d67709ae2937564e2ac1e6c6 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 24 Jan 2024 13:28:31 +0100 Subject: [PATCH 12/16] tests: add tests --- test/runpytests.jl | 167 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 2 deletions(-) diff --git a/test/runpytests.jl b/test/runpytests.jl index 148a72e..f89d556 100644 --- a/test/runpytests.jl +++ b/test/runpytests.jl @@ -31,10 +31,173 @@ end @test array == [[1.1, 2.2, 3.3], [], [4.4, 5.5]] end -# Test pyconvert Python array to Julia -@testset "convert Python array to Julia test" begin +# Test pyconvert Python Awkwar Array to Julia Awkward Array +# @testset "convert Python array to Julia test" begin +@testset "convert # PrimitiveArray" begin + layout = pyimport("awkward").contents.NumpyArray( + pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]) + ) + py_array = pyimport("awkward").Array(layout) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.PrimitiveArray +end + +@testset "convert # EmptyArray" begin + layout = pyimport("awkward").contents.EmptyArray() + py_array = pyimport("awkward").Array(layout) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.EmptyArray +end + +@testset "convert # ListOffsetArray" begin py_array = pyimport("awkward").Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]]) array = pyconvert(Any, py_array) @test array isa AwkwardArray.ListOffsetArray end + +@testset "convert # ListArray" begin + content = pyimport("awkward").contents.NumpyArray( + pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]) + ) + starts = pyimport("awkward").index.Index64(pyimport("numpy").array([0, 3, 3, 5, 6])) + stops = pyimport("awkward").index.Index64(pyimport("numpy").array([3, 3, 5, 6, 9])) + offsets = pyimport("awkward").index.Index64(pyimport("numpy").array([0, 3, 3, 5, 6, 9])) + layout = pyimport("awkward").contents.ListArray(starts, stops, content) + + py_array = pyimport("awkward").Array(layout) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.ListArray +end + +@testset "convert # RegularArray" begin + content = pyimport("awkward").contents.NumpyArray( + pyimport("numpy").array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]) + ) + offsets = pyimport("awkward").index.Index64(pyimport("numpy").array([0, 3, 3, 5, 6, 10, 10])) + listoffsetarray = pyimport("awkward").contents.ListOffsetArray(offsets, content) + regulararray = pyimport("awkward").contents.RegularArray(listoffsetarray, 2, zeros_length=0) + + py_array = pyimport("awkward").Array(regulararray) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.RegularArray +end + +@testset "convert # RecordArray" begin + content1 = pyimport("awkward").contents.NumpyArray(pyimport("numpy").array([1, 2, 3, 4, 5], dtype=pyimport("numpy").int64)) + content2 = pyimport("awkward").contents.NumpyArray( + pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9], dtype=pyimport("numpy").float64) + ) + offsets = pyimport("awkward").index.Index64(pyimport("numpy").array([0, 3, 3, 5, 6, 9], dtype=pyimport("numpy").int64)) + listoffsetarray = pyimport("awkward").contents.ListOffsetArray(offsets, content2) + recordarray = pyimport("awkward").contents.RecordArray( + [content1, listoffsetarray, content2, content1], + fields=["one", "two", "2", "wonky"], + ) + + py_array = pyimport("awkward").Array(recordarray) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.RecordArray +end + +@testset "convert # TupleArray" begin + tuplearray = pyimport("awkward").contents.RecordArray([pyimport("awkward").contents.NumpyArray(pyimport("numpy").arange(10))], pybuiltins.None) + + py_array = pyimport("awkward").Array(tuplearray) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.TupleArray +end + +@testset "convert # IndexedArray" begin + content = pyimport("awkward").contents.NumpyArray(pyimport("numpy").array([0.0, 1.1, 2.2, 3.3, 4.4])) + + ind = pyimport("numpy").array([2, 2, 0, 3, 4], dtype=pyimport("numpy").int32) + index = pyimport("awkward").index.Index32(ind) + indexedarray = pyimport("awkward").contents.IndexedArray(index, content) + + py_array = pyimport("awkward").Array(indexedarray) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.IndexedArray +end + +@testset "convert # IndexedOptionArray" begin + content = pyimport("awkward").contents.NumpyArray(pyimport("numpy").array([0.0, 1.1, 2.2, 3.3, 4.4])) + index = pyimport("awkward").index.Index64(pyimport("numpy").array([2, 2, 0, -1, 4], dtype=pyimport("numpy").int64)) + indexedoptionarray = pyimport("awkward").contents.IndexedOptionArray(index, content) + + py_array = pyimport("awkward").Array(indexedoptionarray) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.IndexedOptionArray +end + +@testset "convert # ByteMaskedArray" begin + layout = pyimport("awkward").contents.ByteMaskedArray( + pyimport("awkward").index.Index8(pyimport("numpy").array([0, 1, 0, 1, 0], dtype=pyimport("numpy").int8)), + pyimport("awkward").contents.NumpyArray(pyimport("numpy").arange(5)), + valid_when=pybuiltins.True, + ) + py_array = pyimport("awkward").Array(layout) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.ByteMaskedArray +end + +# @testset "convert # BitMaskedArray" begin +# content = pyimport("awkward").operations.from_iter( +# [[0.0, 1.1, 2.2], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]], highlevel=pybuiltins.False +# ) +# mask = pyimport("awkward").index.IndexU8(pyimport("numpy").array([66], dtype=pyimport("numpy").uint8)) +# maskedarray = pyimport("awkward").contents.BitMaskedArray( +# mask, content, valid_when=pybuiltins.False, length=4, lsb_order=pybuiltins.True +# ) +# py_array = pyimport("awkward").Array(maskedarray) + +# array = pyconvert(Any, py_array) +# @test array isa AwkwardArray.BitMaskedArray +# end + +@testset "convert # UnmaskedArray" begin + unmaskedarray = pyimport("awkward").contents.UnmaskedArray( + pyimport("awkward").contents.NumpyArray( + pyimport("numpy").array([0.0, 1.1, 2.2, 3.3], dtype=pyimport("numpy").float64) + ) + ) + py_array = pyimport("awkward").Array(unmaskedarray) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.UnmaskedArray +end + +@testset "convert # UnionArray" begin + layout = pyimport("awkward").contents.unionarray.UnionArray( + pyimport("awkward").index.Index(pyimport("numpy").array([1, 1, 0, 0, 1, 0, 1], dtype=pyimport("numpy").int8)), + pyimport("awkward").index.Index(pyimport("numpy").array([4, 3, 0, 1, 2, 2, 4, 100])), + [ + pyimport("awkward").contents.recordarray.RecordArray( + [pyimport("awkward").from_iter(["1", "2", "3"], highlevel=pybuiltins.False)], ["nest"] + ), + pyimport("awkward").contents.recordarray.RecordArray( + [ + pyimport("awkward").contents.numpyarray.NumpyArray( + pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5]) + ) + ], + ["nest"], + ), + ], + ) + py_array = pyimport("awkward").Array(layout) + + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.UnionArray +end + +#end From c396ae73c0c4aedd04d8593fa18cbd8cd50b9a4c Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 24 Jan 2024 14:14:19 +0100 Subject: [PATCH 13/16] fix: use Vector in convert to avoid problems with BitMasked buffers --- src/AwkwardPythonCallExt.jl | 2 +- test/runpytests.jl | 33 +++++++++++++++------------------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/AwkwardPythonCallExt.jl b/src/AwkwardPythonCallExt.jl index e906efb..11fb4f8 100644 --- a/src/AwkwardPythonCallExt.jl +++ b/src/AwkwardPythonCallExt.jl @@ -19,7 +19,7 @@ function AwkwardArray.convert(array::Py)::AwkwardArray.Content form, len, _containers = pyimport("awkward").to_buffers(array) containers = pyconvert(Dict, _containers) - julia_buffers = Dict{String,AbstractVector{UInt8}}() + julia_buffers = Dict{String,Vector{UInt8}}() for (key, buffer) in containers julia_buffers[key] = reinterpret(UInt8, buffer) diff --git a/test/runpytests.jl b/test/runpytests.jl index f89d556..4ab3398 100644 --- a/test/runpytests.jl +++ b/test/runpytests.jl @@ -32,14 +32,13 @@ end end # Test pyconvert Python Awkwar Array to Julia Awkward Array -# @testset "convert Python array to Julia test" begin @testset "convert # PrimitiveArray" begin layout = pyimport("awkward").contents.NumpyArray( pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]) ) py_array = pyimport("awkward").Array(layout) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.PrimitiveArray, py_array) @test array isa AwkwardArray.PrimitiveArray end @@ -47,14 +46,14 @@ end layout = pyimport("awkward").contents.EmptyArray() py_array = pyimport("awkward").Array(layout) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.EmptyArray, py_array) @test array isa AwkwardArray.EmptyArray end @testset "convert # ListOffsetArray" begin py_array = pyimport("awkward").Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]]) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.ListOffsetArray, py_array) @test array isa AwkwardArray.ListOffsetArray end @@ -150,19 +149,19 @@ end @test array isa AwkwardArray.ByteMaskedArray end -# @testset "convert # BitMaskedArray" begin -# content = pyimport("awkward").operations.from_iter( -# [[0.0, 1.1, 2.2], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]], highlevel=pybuiltins.False -# ) -# mask = pyimport("awkward").index.IndexU8(pyimport("numpy").array([66], dtype=pyimport("numpy").uint8)) -# maskedarray = pyimport("awkward").contents.BitMaskedArray( -# mask, content, valid_when=pybuiltins.False, length=4, lsb_order=pybuiltins.True -# ) -# py_array = pyimport("awkward").Array(maskedarray) +@testset "convert # BitMaskedArray" begin + content = pyimport("awkward").operations.from_iter( + [[0.0, 1.1, 2.2], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]], highlevel=pybuiltins.False + ) + mask = pyimport("awkward").index.IndexU8(pyimport("numpy").array([66], dtype=pyimport("numpy").uint8)) + maskedarray = pyimport("awkward").contents.BitMaskedArray( + mask, content, valid_when=pybuiltins.False, length=4, lsb_order=pybuiltins.True + ) + py_array = pyimport("awkward").Array(maskedarray) -# array = pyconvert(Any, py_array) -# @test array isa AwkwardArray.BitMaskedArray -# end + array = pyconvert(Any, py_array) + @test array isa AwkwardArray.BitMaskedArray +end @testset "convert # UnmaskedArray" begin unmaskedarray = pyimport("awkward").contents.UnmaskedArray( @@ -199,5 +198,3 @@ end array = pyconvert(Any, py_array) @test array isa AwkwardArray.UnionArray end - -#end From 1cc71e5c3317d1a9c41c87ef4f5575e48802a0fb Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 24 Jan 2024 14:45:12 +0100 Subject: [PATCH 14/16] feat: convert to an awkward type --- test/runpytests.jl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/runpytests.jl b/test/runpytests.jl index 4ab3398..a06085c 100644 --- a/test/runpytests.jl +++ b/test/runpytests.jl @@ -68,7 +68,7 @@ end py_array = pyimport("awkward").Array(layout) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.ListArray, py_array) @test array isa AwkwardArray.ListArray end @@ -82,7 +82,7 @@ end py_array = pyimport("awkward").Array(regulararray) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.RegularArray, py_array) @test array isa AwkwardArray.RegularArray end @@ -100,7 +100,7 @@ end py_array = pyimport("awkward").Array(recordarray) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.RecordArray, py_array) @test array isa AwkwardArray.RecordArray end @@ -109,7 +109,7 @@ end py_array = pyimport("awkward").Array(tuplearray) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.TupleArray, py_array) @test array isa AwkwardArray.TupleArray end @@ -122,7 +122,7 @@ end py_array = pyimport("awkward").Array(indexedarray) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.IndexedArray, py_array) @test array isa AwkwardArray.IndexedArray end @@ -133,7 +133,7 @@ end py_array = pyimport("awkward").Array(indexedoptionarray) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.IndexedOptionArray, py_array) @test array isa AwkwardArray.IndexedOptionArray end @@ -145,7 +145,7 @@ end ) py_array = pyimport("awkward").Array(layout) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.ByteMaskedArray, py_array) @test array isa AwkwardArray.ByteMaskedArray end @@ -159,7 +159,7 @@ end ) py_array = pyimport("awkward").Array(maskedarray) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.BitMaskedArray, py_array) @test array isa AwkwardArray.BitMaskedArray end @@ -171,7 +171,7 @@ end ) py_array = pyimport("awkward").Array(unmaskedarray) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.UnmaskedArray, py_array) @test array isa AwkwardArray.UnmaskedArray end @@ -192,9 +192,9 @@ end ["nest"], ), ], - ) + ) py_array = pyimport("awkward").Array(layout) - array = pyconvert(Any, py_array) + array = pyconvert(AwkwardArray.UnionArray, py_array) @test array isa AwkwardArray.UnionArray end From f193bf4bf31fe10c8108bfc78f7390d340e11b09 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 24 Jan 2024 15:02:07 +0100 Subject: [PATCH 15/16] fix: add dtypes --- test/runpytests.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/runpytests.jl b/test/runpytests.jl index a06085c..c2e6561 100644 --- a/test/runpytests.jl +++ b/test/runpytests.jl @@ -34,7 +34,7 @@ end # Test pyconvert Python Awkwar Array to Julia Awkward Array @testset "convert # PrimitiveArray" begin layout = pyimport("awkward").contents.NumpyArray( - pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]) + pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9], dtype=pyimport("numpy").float64) ) py_array = pyimport("awkward").Array(layout) @@ -59,11 +59,11 @@ end @testset "convert # ListArray" begin content = pyimport("awkward").contents.NumpyArray( - pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]) + pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9], dtype=pyimport("numpy").float64) ) - starts = pyimport("awkward").index.Index64(pyimport("numpy").array([0, 3, 3, 5, 6])) - stops = pyimport("awkward").index.Index64(pyimport("numpy").array([3, 3, 5, 6, 9])) - offsets = pyimport("awkward").index.Index64(pyimport("numpy").array([0, 3, 3, 5, 6, 9])) + starts = pyimport("awkward").index.Index64(pyimport("numpy").array([0, 3, 3, 5, 6], dtype=pyimport("numpy").int64)) + stops = pyimport("awkward").index.Index64(pyimport("numpy").array([3, 3, 5, 6, 9], dtype=pyimport("numpy").int64)) + offsets = pyimport("awkward").index.Index64(pyimport("numpy").array([0, 3, 3, 5, 6, 9], dtype=pyimport("numpy").int64)) layout = pyimport("awkward").contents.ListArray(starts, stops, content) py_array = pyimport("awkward").Array(layout) @@ -74,9 +74,9 @@ end @testset "convert # RegularArray" begin content = pyimport("awkward").contents.NumpyArray( - pyimport("numpy").array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]) + pyimport("numpy").array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9], dtype=pyimport("numpy").float64) ) - offsets = pyimport("awkward").index.Index64(pyimport("numpy").array([0, 3, 3, 5, 6, 10, 10])) + offsets = pyimport("awkward").index.Index64(pyimport("numpy").array([0, 3, 3, 5, 6, 10, 10], dtype=pyimport("numpy").int64)) listoffsetarray = pyimport("awkward").contents.ListOffsetArray(offsets, content) regulararray = pyimport("awkward").contents.RegularArray(listoffsetarray, 2, zeros_length=0) From 7d2c69664e68215ac993af0d6b5e2de0ead891ba Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 24 Jan 2024 15:11:05 +0100 Subject: [PATCH 16/16] fix: more dtypes --- test/runpytests.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/runpytests.jl b/test/runpytests.jl index c2e6561..bcdbd55 100644 --- a/test/runpytests.jl +++ b/test/runpytests.jl @@ -105,7 +105,7 @@ end end @testset "convert # TupleArray" begin - tuplearray = pyimport("awkward").contents.RecordArray([pyimport("awkward").contents.NumpyArray(pyimport("numpy").arange(10))], pybuiltins.None) + tuplearray = pyimport("awkward").contents.RecordArray([pyimport("awkward").contents.NumpyArray(pyimport("numpy").arange(10, dtype=pyimport("numpy").int64))], pybuiltins.None) py_array = pyimport("awkward").Array(tuplearray) @@ -114,7 +114,7 @@ end end @testset "convert # IndexedArray" begin - content = pyimport("awkward").contents.NumpyArray(pyimport("numpy").array([0.0, 1.1, 2.2, 3.3, 4.4])) + content = pyimport("awkward").contents.NumpyArray(pyimport("numpy").array([0.0, 1.1, 2.2, 3.3, 4.4], dtype=pyimport("numpy").float64)) ind = pyimport("numpy").array([2, 2, 0, 3, 4], dtype=pyimport("numpy").int32) index = pyimport("awkward").index.Index32(ind) @@ -127,7 +127,7 @@ end end @testset "convert # IndexedOptionArray" begin - content = pyimport("awkward").contents.NumpyArray(pyimport("numpy").array([0.0, 1.1, 2.2, 3.3, 4.4])) + content = pyimport("awkward").contents.NumpyArray(pyimport("numpy").array([0.0, 1.1, 2.2, 3.3, 4.4], dtype=pyimport("numpy").float64)) index = pyimport("awkward").index.Index64(pyimport("numpy").array([2, 2, 0, -1, 4], dtype=pyimport("numpy").int64)) indexedoptionarray = pyimport("awkward").contents.IndexedOptionArray(index, content) @@ -140,7 +140,7 @@ end @testset "convert # ByteMaskedArray" begin layout = pyimport("awkward").contents.ByteMaskedArray( pyimport("awkward").index.Index8(pyimport("numpy").array([0, 1, 0, 1, 0], dtype=pyimport("numpy").int8)), - pyimport("awkward").contents.NumpyArray(pyimport("numpy").arange(5)), + pyimport("awkward").contents.NumpyArray(pyimport("numpy").arange(5, dtype=pyimport("numpy").int64)), valid_when=pybuiltins.True, ) py_array = pyimport("awkward").Array(layout) @@ -178,7 +178,7 @@ end @testset "convert # UnionArray" begin layout = pyimport("awkward").contents.unionarray.UnionArray( pyimport("awkward").index.Index(pyimport("numpy").array([1, 1, 0, 0, 1, 0, 1], dtype=pyimport("numpy").int8)), - pyimport("awkward").index.Index(pyimport("numpy").array([4, 3, 0, 1, 2, 2, 4, 100])), + pyimport("awkward").index.Index(pyimport("numpy").array([4, 3, 0, 1, 2, 2, 4, 100], dtype=pyimport("numpy").int64)), [ pyimport("awkward").contents.recordarray.RecordArray( [pyimport("awkward").from_iter(["1", "2", "3"], highlevel=pybuiltins.False)], ["nest"] @@ -186,7 +186,7 @@ end pyimport("awkward").contents.recordarray.RecordArray( [ pyimport("awkward").contents.numpyarray.NumpyArray( - pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5]) + pyimport("numpy").array([1.1, 2.2, 3.3, 4.4, 5.5], dtype=pyimport("numpy").float64) ) ], ["nest"],