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

Function test_roundtrip_array_capsule

python/pyarrow/tests/test_cffi.py:573–603  ·  view source on GitHub ↗
(arr, schema_accessor, bad_type, good_type)

Source from the content-addressed store, hash-verified

571 ),
572], ids=['array', 'record_batch'])
573def test_roundtrip_array_capsule(arr, schema_accessor, bad_type, good_type):
574 gc.collect() # Make sure no Arrow data dangles in a ref cycle
575 old_allocated = pa.total_allocated_bytes()
576
577 import_array = type(arr)._import_from_c_capsule
578
579 schema_capsule, capsule = arr.__arrow_c_array__()
580 assert PyCapsule_IsValid(schema_capsule, b"arrow_schema") == 1
581 assert PyCapsule_IsValid(capsule, b"arrow_array") == 1
582 arr_out = import_array(schema_capsule, capsule)
583 assert arr_out.equals(arr)
584
585 assert pa.total_allocated_bytes() > old_allocated
586 del arr_out
587
588 assert pa.total_allocated_bytes() == old_allocated
589
590 capsule = arr.__arrow_c_array__()
591
592 assert pa.total_allocated_bytes() > old_allocated
593 del capsule
594 assert pa.total_allocated_bytes() == old_allocated
595
596 with pytest.raises(ValueError,
597 match=r"Could not cast.* string to requested .* int32"):
598 arr.__arrow_c_array__(bad_type.__arrow_c_schema__())
599
600 schema_capsule, array_capsule = arr.__arrow_c_array__(
601 good_type.__arrow_c_schema__())
602 arr_out = import_array(schema_capsule, array_capsule)
603 assert schema_accessor(arr_out) == good_type
604
605
606@pytest.mark.parametrize('arr,schema_accessor,bad_type,good_type', [

Callers

nothing calls this directly

Calls 5

equalsMethod · 0.80
PyCapsule_IsValidFunction · 0.70
typeEnum · 0.50
__arrow_c_array__Method · 0.45
__arrow_c_schema__Method · 0.45

Tested by

no test coverage detected