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

Function test_roundtrip_array_capsule

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

Source from the content-addressed store, hash-verified

604 ),
605], ids=['array', 'record_batch'])
606def test_roundtrip_array_capsule(arr, schema_accessor, bad_type, good_type):
607 gc.collect() # Make sure no Arrow data dangles in a ref cycle
608 old_allocated = pa.total_allocated_bytes()
609
610 import_array = type(arr)._import_from_c_capsule
611
612 schema_capsule, capsule = arr.__arrow_c_array__()
613 assert PyCapsule_IsValid(schema_capsule, b"arrow_schema") == 1
614 assert PyCapsule_IsValid(capsule, b"arrow_array") == 1
615 arr_out = import_array(schema_capsule, capsule)
616 assert arr_out.equals(arr)
617
618 assert pa.total_allocated_bytes() > old_allocated
619 del arr_out
620
621 assert pa.total_allocated_bytes() == old_allocated
622
623 capsule = arr.__arrow_c_array__()
624
625 assert pa.total_allocated_bytes() > old_allocated
626 del capsule
627 assert pa.total_allocated_bytes() == old_allocated
628
629 with pytest.raises(ValueError,
630 match=r"Could not cast.* string to requested .* int32"):
631 arr.__arrow_c_array__(bad_type.__arrow_c_schema__())
632
633 schema_capsule, array_capsule = arr.__arrow_c_array__(
634 good_type.__arrow_c_schema__())
635 arr_out = import_array(schema_capsule, array_capsule)
636 assert schema_accessor(arr_out) == good_type
637
638
639@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