An Optional can represent the result of an operation that may fail as a
value, rather than raising an exception and halting execution. For example,
tf.data.experimental.get_next_as_optional returns an Optional that either
contains the next value from a tf.compat.v1.data.Iterator if one exists, or
a "none" value that indicates the end of the sequence has been reached.
Optional can only be used by values that are convertible to Tensor or
CompositeTensor.
If this optional does not have a value (i.e. self.has_value() evaluates
to False), this operation will raise tf.errors.InvalidArgumentError
at runtime.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.data.experimental.Optional\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/ops/optional_ops.py#L36-L121) |\n\nWraps a value that may/may not be present at runtime.\n\n#### View aliases\n\n\n**Main aliases**\n\n\\`tf.contrib.data.Optional\\`\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.data.experimental.Optional`](/api_docs/python/tf/experimental/Optional), \\`tf.compat.v2.data.experimental.Optional\\`\n\n\u003cbr /\u003e\n\nAn `Optional` can represent the result of an operation that may fail as a\nvalue, rather than raising an exception and halting execution. For example,\n[`tf.data.experimental.get_next_as_optional`](../../../tf/data/experimental/get_next_as_optional) returns an `Optional` that either\ncontains the next value from a [`tf.compat.v1.data.Iterator`](../../../tf/data/Iterator) if one exists, or\na \"none\" value that indicates the end of the sequence has been reached.\n\n`Optional` can only be used by values that are convertible to `Tensor` or\n`CompositeTensor`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|-------------------|---------------------------------------------------|\n| `value_structure` | The structure of the components of this optional. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_value`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/ops/optional_ops.py#L87-L105) \n\n @staticmethod\n from_value(\n value\n )\n\nReturns an `Optional` that wraps the given value.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|----------------------------------------------------------------------------------|\n| `value` | A value to wrap. The value must be convertible to `Tensor` or `CompositeTensor`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| An `Optional` that wraps `value`. ||\n\n\u003cbr /\u003e\n\n### `get_value`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/ops/optional_ops.py#L61-L75) \n\n @abc.abstractmethod\n get_value(\n name=None\n )\n\nReturns the value wrapped by this optional.\n\nIf this optional does not have a value (i.e. `self.has_value()` evaluates\nto `False`), this operation will raise [`tf.errors.InvalidArgumentError`](../../../tf/errors/InvalidArgumentError)\nat runtime.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------|-----------------------------------------------|\n| `name` | (Optional.) A name for the created operation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The wrapped value. ||\n\n\u003cbr /\u003e\n\n### `has_value`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/ops/optional_ops.py#L49-L59) \n\n @abc.abstractmethod\n has_value(\n name=None\n )\n\nReturns a tensor that evaluates to `True` if this optional has a value.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------|-----------------------------------------------|\n| `name` | (Optional.) A name for the created operation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A scalar [`tf.Tensor`](../../../tf/Tensor) of type [`tf.bool`](../../../tf#bool). ||\n\n\u003cbr /\u003e\n\n### `none_from_structure`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/ops/optional_ops.py#L107-L121) \n\n @staticmethod\n none_from_structure(\n value_structure\n )\n\nReturns an `Optional` that has no value.\n| **Note:** This method takes an argument that defines the structure of the value that would be contained in the returned `Optional` if it had a value.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------------|-------------------------------------------------------------------------------------|\n| `value_structure` | A `Structure` object representing the structure of the components of this optional. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| An `Optional` that has no value. ||\n\n\u003cbr /\u003e"]]