MCPcopy Create free account
hub / github.com/apache/arrow / test_export_cast_binary_view_all_inline

Function test_export_cast_binary_view_all_inline

python/pyarrow/tests/test_cffi.py:238–267  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

236
237@needs_cffi
238def test_export_cast_binary_view_all_inline():
239 # GH-49740: _export_to_c segmentation fault for binary_view array.
240 c_schema = ffi.new("struct ArrowSchema*")
241 ptr_schema = int(ffi.cast("uintptr_t", c_schema))
242 c_array = ffi.new("struct ArrowArray*")
243 ptr_array = int(ffi.cast("uintptr_t", c_array))
244
245 gc.collect() # Make sure no Arrow data dangles in a ref cycle
246 old_allocated = pa.total_allocated_bytes()
247
248 # The cast used to leave a null variadic buffer slot behind when all
249 # values were inline.
250 arr = pa.array([b"a", None, b"e"], type=pa.binary()).cast(pa.binary_view())
251 arr.validate(full=True)
252 py_value = arr.to_pylist()
253 arr._export_to_c(ptr_array, ptr_schema)
254
255 assert c_array.length == 3
256 # validity, views and the appended variadic buffer sizes
257 assert c_array.n_buffers == 3
258
259 del arr
260 arr_new = pa.Array._import_from_c(ptr_array, ptr_schema)
261 assert arr_new.to_pylist() == py_value
262 assert arr_new.type == pa.binary_view()
263 del arr_new
264 assert pa.total_allocated_bytes() == old_allocated
265 # Now released
266 with assert_schema_released:
267 pa.Array._import_from_c(ptr_array, ptr_schema)
268
269
270@needs_cffi

Callers

nothing calls this directly

Calls 4

newMethod · 0.45
castMethod · 0.45
arrayMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected