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

Function check_export_import_schema

python/pyarrow/tests/test_cffi.py:256–285  ·  view source on GitHub ↗
(schema_factory, expected_schema_factory=None)

Source from the content-addressed store, hash-verified

254
255
256def check_export_import_schema(schema_factory, expected_schema_factory=None):
257 if expected_schema_factory is None:
258 expected_schema_factory = schema_factory
259
260 c_schema = ffi.new("struct ArrowSchema*")
261 ptr_schema = int(ffi.cast("uintptr_t", c_schema))
262
263 gc.collect() # Make sure no Arrow data dangles in a ref cycle
264 old_allocated = pa.total_allocated_bytes()
265
266 schema_factory()._export_to_c(ptr_schema)
267 assert pa.total_allocated_bytes() > old_allocated
268 # Delete and recreate C++ object from exported pointer
269 schema_new = pa.Schema._import_from_c(ptr_schema)
270 assert schema_new == expected_schema_factory()
271 assert pa.total_allocated_bytes() == old_allocated
272 del schema_new
273 assert pa.total_allocated_bytes() == old_allocated
274 # Now released
275 with assert_schema_released:
276 pa.Schema._import_from_c(ptr_schema)
277
278 # Not a struct type
279 pa.int32()._export_to_c(ptr_schema)
280 with pytest.raises(ValueError,
281 match="ArrowSchema describes non-struct type"):
282 pa.Schema._import_from_c(ptr_schema)
283 # Now released
284 with assert_schema_released:
285 pa.Schema._import_from_c(ptr_schema)
286
287
288@needs_cffi

Calls 2

newMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected