Skip to content

Commit 2cd3d44

Browse files
pwohlhartThe TensorFlow Datasets Authors
authored andcommitted
Better tensor feature assert shape message.
PiperOrigin-RevId: 642890606
1 parent 8ab19aa commit 2cd3d44

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tensorflow_datasets/core/features/tensor_feature.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ def encode_example(self, example_data):
237237

238238
shape = example_data.shape
239239

240-
utils.assert_shape_match(shape, self._serialized_shape)
240+
try:
241+
utils.assert_shape_match(shape, self._serialized_shape)
242+
except (AssertionError, ValueError) as e:
243+
raise ValueError(
244+
f'Shape {shape} does not match {self._serialized_shape} for feature '
245+
f'with doc {self.doc} ({e})'
246+
) from e
241247

242248
# Eventually encode the data
243249
if self._encoded_to_bytes:

0 commit comments

Comments
 (0)