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

Function test_roundtrip_device_array_capsule

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

Source from the content-addressed store, hash-verified

613 ),
614], ids=['array', 'record_batch'])
615def test_roundtrip_device_array_capsule(arr, schema_accessor, bad_type, good_type):
616 gc.collect() # Make sure no Arrow data dangles in a ref cycle
617 old_allocated = pa.total_allocated_bytes()
618
619 import_array = type(arr)._import_from_c_device_capsule
620
621 schema_capsule, capsule = arr.__arrow_c_device_array__()
622 assert PyCapsule_IsValid(schema_capsule, b"arrow_schema") == 1
623 assert PyCapsule_IsValid(capsule, b"arrow_device_array") == 1
624 arr_out = import_array(schema_capsule, capsule)
625 assert arr_out.equals(arr)
626
627 assert pa.total_allocated_bytes() > old_allocated
628 del arr_out
629
630 assert pa.total_allocated_bytes() == old_allocated
631
632 capsule = arr.__arrow_c_array__()
633
634 assert pa.total_allocated_bytes() > old_allocated
635 del capsule
636 assert pa.total_allocated_bytes() == old_allocated
637
638 with pytest.raises(ValueError,
639 match=r"Could not cast.* string to requested .* int32"):
640 arr.__arrow_c_device_array__(bad_type.__arrow_c_schema__())
641
642 schema_capsule, array_capsule = arr.__arrow_c_device_array__(
643 good_type.__arrow_c_schema__())
644 arr_out = import_array(schema_capsule, array_capsule)
645 assert schema_accessor(arr_out) == good_type
646
647
648@pytest.mark.parametrize('constructor', [

Callers

nothing calls this directly

Calls 6

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