Skip to content

Commit 4a82fdd

Browse files
committed
prevented flaky behavior in graph mode for serial_ops.py by preemptively raising an exception if graph mode is detected.
1 parent 94419bf commit 4a82fdd

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

tensorflow_io/core/python/experimental/serial_ops.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ def dataset_to_examples(ds):
156156
WARNING: Only compatible with "dictionary-style" datasets {key: val, key2:val2,..., keyN, valN}.
157157
WARNING: Must run in eager mode!"""
158158
# TODO handle tuples and flat datasets as well.
159+
160+
if not tf.executing_eagerly():
161+
raise ValueError("dataset_to_examples() must run in eager mode!")
162+
159163
for x in ds:
160164
# Each individual tensor is converted to a known serializable type.
161165
features = {key: np_value_to_feature(value.numpy()) for key, value in x.items()}

tests/test_serial_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ def graph_save_fail():
8484

8585
def test_ensure_graph_fail():
8686
"""Test that super_serial fails in graph mode."""
87-
with pytest.raises(tf.errors.NotFoundError):
87+
with pytest.raises(ValueError):
8888
graph_save_fail()

0 commit comments

Comments
 (0)