Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -2390,12 +2390,15 @@ cdef class Array(_PandasConvertible):
)
# Note: from March 2025 onwards, it's okay to raise BufferError here.
# Still we keep the V0 version as the V1 was only added in August 2026.
legacy_tensor = GetResultValue(ExportArrayToDLPack(self.sp_array))
# Wrap the exported tensor in its capsule before warning so that a
# warning escalated to an error cannot leak the tensor.
capsule = PyCapsule_New(legacy_tensor, 'dltensor', dlpack_pycapsule_deleter)
warnings.warn(
"Exporting an unversioned DLPack capsule is deprecated, "
"pass max_version=(1, 0) or higher.",
DeprecationWarning, stacklevel=2)
legacy_tensor = GetResultValue(ExportArrayToDLPack(self.sp_array))
return PyCapsule_New(legacy_tensor, 'dltensor', dlpack_pycapsule_deleter)
return capsule

# Currently no major version other than legacy 0 and current 1.3
dlm_tensor = GetResultValue(
Expand Down
7 changes: 5 additions & 2 deletions python/pyarrow/tensor.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,15 @@ strides: {self.strides}"""
)
# Note: from March 2025 onwards, it's okay to raise BufferError here.
# Still we keep the V0 version as the V1 was only added in August 2026.
legacy_tensor = GetResultValue(ExportTensorToDLPack(self.sp_tensor))
# Wrap the exported tensor in its capsule before warning so that a
# warning escalated to an error cannot leak the tensor.
capsule = PyCapsule_New(legacy_tensor, 'dltensor', dlpack_pycapsule_deleter)
warnings.warn(
"Exporting an unversioned DLPack capsule is deprecated, "
"pass max_version=(1, 0) or higher.",
DeprecationWarning, stacklevel=2)
legacy_tensor = GetResultValue(ExportTensorToDLPack(self.sp_tensor))
return PyCapsule_New(legacy_tensor, 'dltensor', dlpack_pycapsule_deleter)
return capsule

# Currently no major version other than legacy 0 and current 1.3
dlm_tensor = GetResultValue(
Expand Down
8 changes: 8 additions & 0 deletions python/pyarrow/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,10 @@ def test_array_from_list_of_timestamps(unit):


@pytest.mark.numpy
@pytest.mark.filterwarnings(
"ignore:The 'generic' unit for NumPy timedelta is deprecated:"
"DeprecationWarning"
)
def test_array_from_timestamp_with_generic_unit():
if Version(np.__version__) >= Version("2.5.0"):
pytest.skip("generic units of timedelta64 deprecated")
Expand Down Expand Up @@ -2779,6 +2783,10 @@ def test_array_from_numpy_timedelta(dtype, type):


@pytest.mark.numpy
@pytest.mark.filterwarnings(
"ignore:The 'generic' unit for NumPy timedelta is deprecated:"
"DeprecationWarning"
)
def test_array_from_numpy_timedelta_incorrect_unit():
# generic (no unit)
if Version(np.__version__) < Version("2.5.0"):
Expand Down
10 changes: 5 additions & 5 deletions python/pyarrow/tests/test_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def test_dlpack_versioned_capsule(obj, max_version, copy):
@check_bytes_allocated
@pytest.mark.parametrize('obj', dlpack_objects())
def test_dlpack_versioned_roundtrip(obj):
expected = np.from_dlpack(DLPackForwarder(obj, max_version=None))
expected = np.from_dlpack(DLPackForwarder(obj, max_version=(1, 0)))
for copy in [None, False, True]:
result = np.from_dlpack(
DLPackForwarder(obj, max_version=(1, 0), copy=copy))
Expand Down Expand Up @@ -335,24 +335,24 @@ def test_dlpack_not_supported():
arr = pa.array([1, None, 3])
with pytest.raises(TypeError, match="Can only use DLPack "
"on arrays with no nulls."):
np.from_dlpack(arr)
np.from_dlpack(DLPackForwarder(arr, max_version=(1, 0)))

arr = pa.array(
[[0, 1], [3, 4]],
type=pa.list_(pa.int32())
)
with pytest.raises(TypeError, match="DataType is not compatible with DLPack spec"):
np.from_dlpack(arr)
np.from_dlpack(DLPackForwarder(arr, max_version=(1, 0)))

arr = pa.array([])
with pytest.raises(TypeError, match="DataType is not compatible with DLPack spec"):
np.from_dlpack(arr)
np.from_dlpack(DLPackForwarder(arr, max_version=(1, 0)))

# DLPack doesn't support bit-packed boolean values
arr = pa.array([True, False, True])
with pytest.raises(TypeError, match="Bit-packed boolean data type "
"not supported by DLPack."):
np.from_dlpack(arr)
np.from_dlpack(DLPackForwarder(arr, max_version=(1, 0)))


def test_dlpack_cuda_not_supported():
Expand Down