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
9 changes: 8 additions & 1 deletion src/torchcodec/_core/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ class StreamMetadata:
def __repr__(self):
s = self.__class__.__name__ + ":\n"
for field in dataclasses.fields(self):
s += f"{SPACES}{field.name}: {getattr(self, field.name)}\n"
attr = getattr(self, field.name)
if isinstance(attr, Fraction):
# Fractions are displayed as integers when possible,
# but we want to always display num/den. Once we
# require Python >=3.13 we can use format(.., "#").
s += f"{SPACES}{field.name}: {attr.numerator}/{attr.denominator}\n"
else:
s += f"{SPACES}{field.name}: {attr}\n"
return s


Expand Down
2 changes: 1 addition & 1 deletion test/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_repr():
num_frames_from_header: 390
num_frames_from_content: 390
average_fps_from_header: 29.97003
pixel_aspect_ratio: 1
pixel_aspect_ratio: 1/1
duration_seconds: 13.013
begin_stream_seconds: 0.0
end_stream_seconds: 13.013
Expand Down
Loading