Skip to content

Commit a6f2668

Browse files
committed
Add special format for FeaturesDict.__repr__
`tensorflow_datasets.scripts.document_datasets.pprint_features_dict` converted to public function and add types parameter.
1 parent 2d24ef6 commit a6f2668

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

tensorflow_datasets/core/features/features_dict.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from tensorflow_datasets.core import utils
2727
from tensorflow_datasets.core.features import feature as feature_lib
2828
from tensorflow_datasets.core.features import top_level_feature
29+
from tensorflow_datasets.scripts.document_datasets import pprint_features_dict
2930

3031

3132
class FeaturesDict(top_level_feature.TopLevelFeature):
@@ -138,7 +139,7 @@ def __iter__(self):
138139

139140
def __repr__(self):
140141
"""Display the feature dictionary."""
141-
return '{}({})'.format(type(self).__name__, self._feature_dict)
142+
return pprint_features_dict(self._feature_dict, types='FeaturesDict')
142143

143144
def get_tensor_info(self):
144145
"""See base class for details."""

tensorflow_datasets/scripts/document_datasets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,19 @@ def make_module_to_builder_dict(datasets=None):
311311
return module_to_builder
312312

313313

314-
def _pprint_features_dict(features_dict, indent=0, add_prefix=True):
314+
def pprint_features_dict(features_dict, indent=0, add_prefix=True, types=None):
315315
"""Pretty-print tfds.features.FeaturesDict."""
316316
first_last_indent_str = " " * indent
317317
indent_str = " " * (indent + 4)
318318
first_line = "%s%s({" % (
319319
first_last_indent_str if add_prefix else "",
320-
type(features_dict).__name__,
320+
type(features_dict).__name__ if type is None else types,
321321
)
322322
lines = [first_line]
323323
for k in sorted(list(features_dict.keys())):
324324
v = features_dict[k]
325325
if hasattr(v, 'keys'):
326-
v_str = _pprint_features_dict(v, indent + 4, False)
326+
v_str = pprint_features_dict(v, indent + 4, False)
327327
else:
328328
v_str = str(v)
329329
lines.append("%s'%s': %s," % (indent_str, k, v_str))
@@ -333,7 +333,7 @@ def _pprint_features_dict(features_dict, indent=0, add_prefix=True):
333333

334334
def make_feature_information(info):
335335
"""Make feature information table."""
336-
return FEATURE_BLOCK % _pprint_features_dict(info.features)
336+
return FEATURE_BLOCK % pprint_features_dict(info.features)
337337

338338

339339
def make_citation(citation):

0 commit comments

Comments
 (0)