Skip to content

Commit 727106f

Browse files
authored
GH-48608: [Python] Fix interpolate actual values in Message.__repr__ f-string (#48656)
### Rationale for this change `Message.__repr__` showed format placeholders (`{self.type}`) instead of actual values. ### What changes are included in this PR? Add missing `f` prefix to f-string in `Message.__repr__` (pyarrow/lib.pxi). ### Are these changes tested? Yes: added test verifying string representation shows actual values. ### Are there any user-facing changes? Yes (bug fix): `str(message)` now shows values like `type: RecordBatch` instead of placeholders. related to issue #48608 * GitHub Issue: #48608 Authored-by: aokizy <[email protected]> Signed-off-by: Rok Mihevc <[email protected]>
1 parent a9f0a4a commit 727106f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

python/pyarrow/ipc.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ cdef class Message(_Weakrefable):
479479
body = self.body
480480
body_len = 0 if body is None else body.size
481481

482-
return """pyarrow.Message
482+
return f"""pyarrow.Message
483483
type: {self.type}
484484
metadata length: {metadata_len}
485485
body length: {body_len}"""

python/pyarrow/tests/test_ipc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,18 @@ def test_message_serialize_read_message(example_messages):
779779
pa.ipc.read_message(reader)
780780

781781

782+
def test_message_repr_shows_actual_values(example_messages):
783+
_, messages = example_messages
784+
785+
for msg in messages:
786+
s = str(msg)
787+
788+
assert '{self.type}' not in s
789+
assert '{metadata_len}' not in s
790+
assert '{body_len}' not in s
791+
assert f'type: {msg.type}' in s
792+
793+
782794
@pytest.mark.gzip
783795
def test_message_read_from_compressed(example_messages):
784796
# Part of ARROW-5910

0 commit comments

Comments
 (0)