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:648–678  ·  view source on GitHub ↗
(arr, schema_accessor, bad_type, good_type)

Source from the content-addressed store, hash-verified

646 ),
647], ids=['array', 'record_batch'])
648def test_roundtrip_device_array_capsule(arr, schema_accessor, bad_type, good_type):
649 gc.collect() # Make sure no Arrow data dangles in a ref cycle
650 old_allocated = pa.total_allocated_bytes()
651
652 import_array = type(arr)._import_from_c_device_capsule
653
654 schema_capsule, capsule = arr.__arrow_c_device_array__()
655 assert PyCapsule_IsValid(schema_capsule, b"arrow_schema") == 1
656 assert PyCapsule_IsValid(capsule, b"arrow_device_array") == 1
657 arr_out = import_array(schema_capsule, capsule)
658 assert arr_out.equals(arr)
659
660 assert pa.total_allocated_bytes() > old_allocated
661 del arr_out
662
663 assert pa.total_allocated_bytes() == old_allocated
664
665 capsule = arr.__arrow_c_array__()
666
667 assert pa.total_allocated_bytes() > old_allocated
668 del capsule
669 assert pa.total_allocated_bytes() == old_allocated
670
671 with pytest.raises(ValueError,
672 match=r"Could not cast.* string to requested .* int32"):
673 arr.__arrow_c_device_array__(bad_type.__arrow_c_schema__())
674
675 schema_capsule, array_capsule = arr.__arrow_c_device_array__(
676 good_type.__arrow_c_schema__())
677 arr_out = import_array(schema_capsule, array_capsule)
678 assert schema_accessor(arr_out) == good_type
679
680
681@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