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

raulcd 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 012fd17fa5 GH-49108: [Python] SparseCOOTensor.__repr__ missing 
f-string prefix (#49109)
012fd17fa5 is described below

commit 012fd17fa5dc77f94c95bac8bfbedd91349f3df9
Author: ChiLin Chiu <[email protected]>
AuthorDate: Mon Feb 2 20:21:20 2026 +0800

    GH-49108: [Python] SparseCOOTensor.__repr__ missing f-string prefix (#49109)
    
    ### Rationale for this change
    
    `SparseCOOTensor.__repr__` outputs literal `{self.type}` and `{self.shape}` 
instead of actual values due to missing f-string prefix.
    
    ### What changes are included in this PR?
    
    Add f prefix to the string in `SparseCOOTensor.__repr__`.
    
    ### Are these changes tested?
    
    Yes, work after adding. f-string prefix:
    ```python3
    >>> import pyarrow as pa
    >>> import numpy as np
    >>> dense_tensor = np.array([[0, 1, 0], [2, 0, 3]], dtype=np.float32)
    >>> sparse_coo = pa.SparseCOOTensor.from_dense_numpy(dense_tensor)
    >>> sparse_coo
    <pyarrow.SparseCOOTensor>
    type: float
    shape: (2, 3)
    ```
    
    ### Are there any user-facing changes?
    
    a bug that caused incorrect or invalid data to be produced:
    
    ```python3
    >>> import pyarrow as pa
    >>> import numpy as np
    >>> dense_tensor = np.array([[0, 1, 0], [2, 0, 3]], dtype=np.float32)
    >>> sparse_coo = pa.SparseCOOTensor.from_dense_numpy(dense_tensor)
    >>> sparse_coo
    <pyarrow.SparseCOOTensor>
    type: {self.type}
    shape: {self.shape}
    ```
    
    * GitHub Issue: #49108
    
    Authored-by: Chilin <[email protected]>
    Signed-off-by: Raúl Cumplido <[email protected]>
---
 python/pyarrow/tensor.pxi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/python/pyarrow/tensor.pxi b/python/pyarrow/tensor.pxi
index 73715c0609..cad09cb7ba 100644
--- a/python/pyarrow/tensor.pxi
+++ b/python/pyarrow/tensor.pxi
@@ -359,7 +359,7 @@ cdef class SparseCOOTensor(_Weakrefable):
         self.type = pyarrow_wrap_data_type(self.stp.type())
 
     def __repr__(self):
-        return """<pyarrow.SparseCOOTensor>
+        return f"""<pyarrow.SparseCOOTensor>
 type: {self.type}
 shape: {self.shape}"""
 

Reply via email to