Skip to content

Commit 025d315

Browse files
author
The TensorFlow Datasets Authors
committed
Add description to feature repr.
PiperOrigin-RevId: 670151846
1 parent 7312de7 commit 025d315

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

tensorflow_datasets/core/features/feature.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,10 @@ def _nest(self, list_x):
973973

974974
def _additional_repr_info(self):
975975
"""Override to return additional info to go into __repr__."""
976-
return {}
976+
additional_repr_info = {}
977+
if description := self.doc.desc:
978+
additional_repr_info['description'] = description
979+
return additional_repr_info
977980

978981
def __repr__(self):
979982
"""Display the feature dictionary."""

tensorflow_datasets/core/features/feature_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ def test_convert_feature_name_to_filename(feature_name, parent_name, expected):
184184
)
185185

186186

187+
def test_feature_repr():
188+
json = {
189+
"description": "Image encoded as JPEG.",
190+
"image": {
191+
"dtype": "uint8",
192+
"encodingFormat": "jpeg",
193+
"shape": {"dimensions": ["-1", "-1", "3"]},
194+
},
195+
"pythonClassName": (
196+
"tensorflow_datasets.core.features.image_feature.Image"
197+
),
198+
}
199+
feature_connector = feature.FeatureConnector.from_json(json)
200+
expected_feature_connector_repr = (
201+
"Image(shape=(None, None, 3), dtype=uint8, description=Image encoded as"
202+
" JPEG.)"
203+
)
204+
assert str(feature_connector) == expected_feature_connector_repr
205+
206+
187207
def test_tensor_info_repr():
188208
tensor_info = feature.TensorInfo(
189209
shape=(), dtype=np.int32, minimum=1, maximum=42

0 commit comments

Comments
 (0)