This is an automated email from the ASF dual-hosted git repository.

AlenkaF pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 88e5154544b GH-51481: [Python] Fix dlpack related deprecation warnings 
(#54690)
88e5154544b is described below

commit 88e5154544b4d73d6298dad1eac6b75031d16313
Author: Alenka Frim <[email protected]>
AuthorDate: Wed Nov 25 09:11:28 2026 +0100

    GH-51481: [Python] Fix dlpack related deprecation warnings (#54690)
    
    ### Rationale for this change
    Deprecation warnings on our CI.
    
    ### What changes are included in this PR?
    Added filterwarning marks and updated two tests.
    
    ### Are these changes tested?
    Yes.
    
    ### Are there any user-facing changes?
    No.
    
    ### Was AI used for this PR?
    
    **PR code and description written by:**
    
    - [X] Human
    - [ ] AI
    
    **Reviewed before submission by:**
    
    - [X] Human
    - [ ] AI
    - [ ] Not reviewed
    
    * GitHub Issue: #51481
    
    Lead-authored-by: AlenkaF <[email protected]>
    Co-authored-by: Alenka Frim <[email protected]>
    Co-authored-by: Copilot Autofix powered by AI 
<[email protected]>
    Signed-off-by: AlenkaF <[email protected]>
---
 python/pyarrow/tests/test_dlpack.py | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/python/pyarrow/tests/test_dlpack.py 
b/python/pyarrow/tests/test_dlpack.py
index 0c3c082fd6e..6a8e12781bd 100644
--- a/python/pyarrow/tests/test_dlpack.py
+++ b/python/pyarrow/tests/test_dlpack.py
@@ -268,6 +268,8 @@ def immutable_tensor():
 
 @check_bytes_allocated
 @pytest.mark.parametrize('max_version', [None, (0, 8)])
+# Filter deprecation warning, already asserted in test_dlpack_legacy_capsule
[email protected]("ignore:Exporting an unversioned 
DLPack:DeprecationWarning")
 def test_dlpack_legacy_capsule_immutable_tensor(max_version):
     tensor = immutable_tensor()
     with pytest.raises(NotImplementedError,
@@ -306,6 +308,7 @@ def test_dlpack_versioned_capsule(obj, max_version, copy):
 @requires_numpy_version("2.1.0")
 @check_bytes_allocated
 @pytest.mark.parametrize('obj', dlpack_objects())
[email protected]("ignore:Exporting an unversioned 
DLPack:DeprecationWarning")
 def test_dlpack_versioned_roundtrip(obj):
     expected = np.from_dlpack(DLPackForwarder(obj, max_version=None))
     for copy in [None, False, True]:
@@ -331,30 +334,42 @@ def test_dlpack_copy_is_writeable():
     assert arr.to_pylist() == [1, 2, 3]
 
 
+def from_dlpack_numpy_compat(obj):
+    if Version(np.__version__) < Version("2.1.0"):
+        max_version_numpy = None
+    else:
+        max_version_numpy = (1, 0)
+    return np.from_dlpack(DLPackForwarder(obj, max_version=max_version_numpy))
+
+
[email protected](
+    "ignore:Exporting an unversioned DLPack:DeprecationWarning")
 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)
+        from_dlpack_numpy_compat(arr)
 
     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)
+        from_dlpack_numpy_compat(arr)
 
     arr = pa.array([])
     with pytest.raises(TypeError, match="DataType is not compatible with 
DLPack spec"):
-        np.from_dlpack(arr)
+        from_dlpack_numpy_compat(arr)
 
     # 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)
+        from_dlpack_numpy_compat(arr)
 
 
[email protected](
+    "ignore:Exporting an unversioned DLPack:DeprecationWarning")
 def test_dlpack_cuda_not_supported():
     cuda = pytest.importorskip("pyarrow.cuda", exc_type=ImportError)
 
@@ -369,7 +384,7 @@ def test_dlpack_cuda_not_supported():
     # CudaBuffers not yet supported
     with pytest.raises(NotImplementedError, match="DLPack support is 
implemented "
                        "only for buffers on CPU device."):
-        np.from_dlpack(carr)
+        from_dlpack_numpy_compat(carr)
 
     with pytest.raises(NotImplementedError, match="DLPack support is 
implemented "
                        "only for buffers on CPU device."):

Reply via email to