Skip to content

Commit 012fd17

Browse files
authored
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 <chilin.cs07@nycu.edu.tw> Signed-off-by: Raúl Cumplido <raulcumplido@gmail.com>
1 parent 644ec57 commit 012fd17

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

python/pyarrow/tensor.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ cdef class SparseCOOTensor(_Weakrefable):
359359
self.type = pyarrow_wrap_data_type(self.stp.type())
360360

361361
def __repr__(self):
362-
return """<pyarrow.SparseCOOTensor>
362+
return f"""<pyarrow.SparseCOOTensor>
363363
type: {self.type}
364364
shape: {self.shape}"""
365365

0 commit comments

Comments
 (0)