Skip to content

Commit

Permalink
Python bindings: GetArrowStreamAsNumPy(): fix reading fixed width bin…
Browse files Browse the repository at this point in the history
…ary that were misusing the offset (affects Parquet)
  • Loading branch information
rouault committed Sep 22, 2023
1 parent 9b06a20 commit a655fa6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions autotest/ogr/ogr_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,12 @@ def test_ogr_parquet_arrow_stream_numpy():
assert numpy.array_equal(batches[1]["list_uint8"][0], numpy.array([0, 4, 5]))
assert numpy.array_equal(batches[1]["list_uint8"][1], numpy.array([0, 7, 8, 9]))

assert batches[0]["fixed_size_binary"][0] == b"\x00\x01"
assert batches[0]["fixed_size_binary"][1] == b"\x00\x00"
assert batches[0]["fixed_size_binary"][2] == b"\x01\x01"
assert batches[1]["fixed_size_binary"][0] == b"\x01\x00"
assert batches[1]["fixed_size_binary"][1] == b"\x00\x01"

assert numpy.array_equal(
batches[0]["fixed_size_list_uint8"][0], numpy.array([0, 1])
)
Expand Down
2 changes: 1 addition & 1 deletion swig/include/gdal_array.i
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ PyObject* _RecordBatchAsNumpy(VoidPtrAsLong recordBatchPtr,
for( npy_intp j = 0; j < dims; j++ )
{
PyObject* subObj = PyBytes_FromStringAndSize(
((const char*)arrayField->buffers[1]) + static_cast<size_t>(arrayField->offset) + j * nLength,
((const char*)arrayField->buffers[1]) + static_cast<size_t>(arrayField->offset + j) * nLength,
nLength);
memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
&subObj,
Expand Down

0 comments on commit a655fa6

Please sign in to comment.