From 7f810f8ce13d3ccb31ef25f788c7461a7ebf4e90 Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Thu, 13 Nov 2025 00:22:17 +0100 Subject: [PATCH 1/3] Fix arguments for `ArrayValue.__array__()` --- src/JlWrap/array.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JlWrap/array.jl b/src/JlWrap/array.jl index a52a62de..9b0a1f76 100644 --- a/src/JlWrap/array.jl +++ b/src/JlWrap/array.jl @@ -353,7 +353,7 @@ function init_array() @property def __array_interface__(self): return self._jl_callmethod($(pyjl_methodnum(pyjlarray_array_interface))) - def __array__(self, dtype=None): + def __array__(self, dtype=None, copy=None): # convert to an array-like object arr = self if not (hasattr(arr, "__array_interface__") or hasattr(arr, "__array_struct__")): @@ -365,7 +365,7 @@ function init_array() except ImportError: numpy = None if numpy is not None: - return numpy.array(arr, dtype=dtype, copy=copy, order=order) + return numpy.array(arr, dtype=dtype, copy=copy) return arr def to_numpy(self, dtype=None, copy=True, order="K"): import numpy From 9ac67bd73771d82dd8d47cebd8b923b38ade4f2a Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Thu, 13 Nov 2025 10:00:38 +0100 Subject: [PATCH 2/3] fixup! Fix arguments for `ArrayValue.__array__()` --- src/JlWrap/array.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/JlWrap/array.jl b/src/JlWrap/array.jl index 9b0a1f76..0cd2f57a 100644 --- a/src/JlWrap/array.jl +++ b/src/JlWrap/array.jl @@ -365,6 +365,10 @@ function init_array() except ImportError: numpy = None if numpy is not None: + # Numpy <2 does not support `copy=None` argument, so we have to check the version + major_version = int(numpy.__version__.split(".")[0]) + if major_version < 2 and copy is None: + copy = False return numpy.array(arr, dtype=dtype, copy=copy) return arr def to_numpy(self, dtype=None, copy=True, order="K"): From 31e9a8c77dce2c65a78ca74c6f5756ab1ff9e9b3 Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Thu, 13 Nov 2025 11:18:33 +0100 Subject: [PATCH 3/3] fixup! Fix arguments for `ArrayValue.__array__()` --- src/JlWrap/array.jl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/JlWrap/array.jl b/src/JlWrap/array.jl index 0cd2f57a..3da92f4e 100644 --- a/src/JlWrap/array.jl +++ b/src/JlWrap/array.jl @@ -357,8 +357,14 @@ function init_array() # convert to an array-like object arr = self if not (hasattr(arr, "__array_interface__") or hasattr(arr, "__array_struct__")): - # the second attempt collects into a PyObjectArray - arr = self._jl_callmethod($(pyjl_methodnum(pyjlarray_array__pyobjectarray))) + if copy is False: + raise ValueError("copy=False is not supported when collecting ArrayValue data") + # the first attempt collects into an Array + arr = self._jl_callmethod($(pyjl_methodnum(pyjlarray_array__array))) + if not (hasattr(arr, "__array_interface__") or hasattr(arr, "__array_struct__")): + # the second attempt collects into a PyObjectArray + arr = self._jl_callmethod($(pyjl_methodnum(pyjlarray_array__pyobjectarray))) + # convert to a numpy array if numpy is available try: import numpy @@ -369,7 +375,7 @@ function init_array() major_version = int(numpy.__version__.split(".")[0]) if major_version < 2 and copy is None: copy = False - return numpy.array(arr, dtype=dtype, copy=copy) + arr = numpy.array(arr, dtype=dtype, copy=copy) return arr def to_numpy(self, dtype=None, copy=True, order="K"): import numpy