From 2eb13b1286123b92fd072be2a0ee94ba25c87e84 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Fri, 12 Sep 2025 13:51:06 +0200 Subject: [PATCH 1/2] fix to_arrow datetime conversion --- src/awkward/contents/numpyarray.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index bec4c6b170..ff28dd9fc0 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -1205,13 +1205,20 @@ def _to_arrow( return self.to_RegularArray()._to_arrow( pyarrow, mask_node, validbytes, length, options ) - (nparray,) = maybe_materialize(self._raw(numpy)) storage_type = pyarrow.from_numpy_dtype(nparray.dtype) - if issubclass(nparray.dtype.type, (bool, np.bool_)): nparray = numpy.packbits(nparray, bitorder="little") + if ( + np.issubdtype(nparray.dtype, np.datetime64) + and nparray.dtype.name == "datetime64[D]" + ): + nparray = nparray.astype("timedelta64[D]").astype(np.int32) + storage_type = pyarrow.date32() + else: + storage_type = pyarrow.from_numpy_dtype(nparray.dtype) + return pyarrow.Array.from_buffers( ak._connect.pyarrow.to_awkwardarrow_type( storage_type, From c749a4754c5ec0df27cf3a2ad4880be80e633312 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Sun, 14 Sep 2025 13:37:07 +0200 Subject: [PATCH 2/2] follow Andres' suggestion --- src/awkward/contents/numpyarray.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index cbc64e3019..e8bb1341ee 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -1211,9 +1211,6 @@ def _to_arrow( pyarrow, mask_node, validbytes, length, options ) (nparray,) = maybe_materialize(self._raw(numpy)) - storage_type = pyarrow.from_numpy_dtype(nparray.dtype) - if issubclass(nparray.dtype.type, (bool, np.bool_)): - nparray = numpy.packbits(nparray, bitorder="little") if ( np.issubdtype(nparray.dtype, np.datetime64) @@ -1224,6 +1221,9 @@ def _to_arrow( else: storage_type = pyarrow.from_numpy_dtype(nparray.dtype) + if issubclass(nparray.dtype.type, (bool, np.bool_)): + nparray = numpy.packbits(nparray, bitorder="little") + return pyarrow.Array.from_buffers( ak._connect.pyarrow.to_awkwardarrow_type( storage_type,