Skip to content

Commit cd25e16

Browse files
tomvdwThe TensorFlow Datasets Authors
authored andcommitted
Add split name to error when no examples were generated with Beam
The error currently is: `ValueError: The total number of generated examples is 0. This should be >0!` However, it would be handy to know what split has this problem. PiperOrigin-RevId: 649297162
1 parent 9982226 commit cd25e16

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

tensorflow_datasets/core/writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ def _serialize_example(
445445
def _check_num_examples(self, num_examples: int) -> int:
446446
if num_examples <= 0:
447447
raise ValueError(
448-
f"The total number of generated examples is {num_examples}. This"
449-
" should be >0!"
448+
f"The total number of generated examples is {num_examples} for split"
449+
f" {self._filename_template.split}. This should be >0!"
450450
)
451451
return num_examples
452452

tensorflow_datasets/core/writer_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from tensorflow_datasets.core import naming
3232
from tensorflow_datasets.core import writer as writer_lib
3333
from tensorflow_datasets.core.utils import shard_utils
34-
from tensorflow_datasets.core.writer import _ShardSpec
3534

3635

3736
class GetShardSpecsTest(testing.TestCase):
@@ -55,7 +54,7 @@ def test_1bucket_6shards(self):
5554
specs,
5655
[
5756
# Shard#, path, from_bucket, examples_number, reading instructions.
58-
_ShardSpec(
57+
writer_lib._ShardSpec(
5958
0,
6059
'/bar-train.tfrecord-00000-of-00006',
6160
'/bar-train.tfrecord-00000-of-00006_index.json',
@@ -66,7 +65,7 @@ def test_1bucket_6shards(self):
6665
),
6766
],
6867
),
69-
_ShardSpec(
68+
writer_lib._ShardSpec(
7069
1,
7170
'/bar-train.tfrecord-00001-of-00006',
7271
'/bar-train.tfrecord-00001-of-00006_index.json',
@@ -77,7 +76,7 @@ def test_1bucket_6shards(self):
7776
),
7877
],
7978
),
80-
_ShardSpec(
79+
writer_lib._ShardSpec(
8180
2,
8281
'/bar-train.tfrecord-00002-of-00006',
8382
'/bar-train.tfrecord-00002-of-00006_index.json',
@@ -88,7 +87,7 @@ def test_1bucket_6shards(self):
8887
),
8988
],
9089
),
91-
_ShardSpec(
90+
writer_lib._ShardSpec(
9291
3,
9392
'/bar-train.tfrecord-00003-of-00006',
9493
'/bar-train.tfrecord-00003-of-00006_index.json',
@@ -99,7 +98,7 @@ def test_1bucket_6shards(self):
9998
),
10099
],
101100
),
102-
_ShardSpec(
101+
writer_lib._ShardSpec(
103102
4,
104103
'/bar-train.tfrecord-00004-of-00006',
105104
'/bar-train.tfrecord-00004-of-00006_index.json',
@@ -110,7 +109,7 @@ def test_1bucket_6shards(self):
110109
),
111110
],
112111
),
113-
_ShardSpec(
112+
writer_lib._ShardSpec(
114113
5,
115114
'/bar-train.tfrecord-00005-of-00006',
116115
'/bar-train.tfrecord-00005-of-00006_index.json',
@@ -141,7 +140,7 @@ def test_4buckets_2shards(self):
141140
specs,
142141
[
143142
# Shard#, path, examples_number, reading instructions.
144-
_ShardSpec(
143+
writer_lib._ShardSpec(
145144
0,
146145
'/bar-train.tfrecord-00000-of-00002',
147146
'/bar-train.tfrecord-00000-of-00002_index.json',
@@ -155,7 +154,7 @@ def test_4buckets_2shards(self):
155154
),
156155
],
157156
),
158-
_ShardSpec(
157+
writer_lib._ShardSpec(
159158
1,
160159
'/bar-train.tfrecord-00001-of-00002',
161160
'/bar-train.tfrecord-00001-of-00002_index.json',
@@ -520,7 +519,8 @@ def test_write_tfrecord_with_ignored_duplicates(self):
520519
def test_empty_split(self):
521520
with self.assertRaisesWithPredicateMatch(
522521
ValueError,
523-
'The total number of generated examples is 0. This should be >0!',
522+
'The total number of generated examples is 0 for split train. This'
523+
' should be >0!',
524524
):
525525
self._write(to_write=[])
526526

0 commit comments

Comments
 (0)