# tf.data.DatasetSpec

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/data/ops/dataset_ops.py#L4514-L4669) |

Type specification for [`tf.data.Dataset`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/data/Dataset).

Inherits From: [`TypeSpec`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/TypeSpec), [`TraceType`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/types/experimental/TraceType)

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.data.DatasetSpec`](https://www.tensorflow.org/api_docs/python/tf/data/DatasetSpec), [`tf.compat.v1.data.experimental.DatasetStructure`](https://www.tensorflow.org/api_docs/python/tf/data/DatasetSpec)

<br />

    tf.data.DatasetSpec(
        element_spec, dataset_shape=()
    )

See [`tf.TypeSpec`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/TypeSpec) for more information about TensorFlow type specifications.

    dataset = tf.data.Dataset.range(3)
    tf.data.DatasetSpec.from_value(dataset)
    DatasetSpec(TensorSpec(shape=(), dtype=tf.int64, name=None), TensorShape([]))

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `element_spec` | The inner element spec. |
| `value_type` | The Python type for values that are compatible with this TypeSpec. <br /> In particular, all values that are compatible with this TypeSpec must be an instance of this type. |

<br />

## Methods

### `experimental_as_proto`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/type_spec.py#L213-L218)

    experimental_as_proto() -> struct_pb2.TypeSpecProto

Returns a proto representation of the TypeSpec instance.

Do NOT override for custom non-TF types.

### `experimental_from_proto`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/type_spec.py#L200-L211)

    @classmethod
    experimental_from_proto(
        proto: struct_pb2.TypeSpecProto
    ) -> 'TypeSpec'

Returns a TypeSpec instance based on the serialized proto.

Do NOT override for custom non-TF types.

<br />

<br />

<br />

| Args ||
|---|---|
| `proto` | Proto generated using 'experimental_as_proto'. |

<br />

### `experimental_type_proto`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/type_spec.py#L192-L198)

    @classmethod
    experimental_type_proto() -> Type[struct_pb2.TypeSpecProto]

Returns the type of proto associated with TypeSpec serialization.

Do NOT override for custom non-TF types.

### `from_value`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/data/ops/dataset_ops.py#L4633-L4636)

    @staticmethod
    from_value(
        value
    )

Creates a `DatasetSpec` for the given [`tf.data.Dataset`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/data/Dataset) value.

### `is_compatible_with`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/type_spec.py#L263-L284)

    is_compatible_with(
        spec_or_value
    )

Returns true if `spec_or_value` is compatible with this TypeSpec.

Prefer using "is_subtype_of" and "most_specific_common_supertype" wherever
possible.

<br />

<br />

<br />

| Args ||
|---|---|
| `spec_or_value` | A TypeSpec or TypeSpec associated value to compare against. |

<br />

### `is_subtype_of`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/data/ops/dataset_ops.py#L4542-L4566)

    is_subtype_of(
        other
    )

See base class.

### `most_specific_common_supertype`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/data/ops/dataset_ops.py#L4568-L4605)

    most_specific_common_supertype(
        others
    )

See base class.

### `most_specific_compatible_type`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/type_spec.py#L286-L304)

    most_specific_compatible_type(
        other: 'TypeSpec'
    ) -> 'TypeSpec'

Returns the most specific TypeSpec compatible with `self` and `other`. (deprecated)

> [!WARNING]
> **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use most_specific_common_supertype instead.

Deprecated. Please use `most_specific_common_supertype` instead.
Do not override this function.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | A `TypeSpec`. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If there is no TypeSpec that is compatible with both `self` and `other`. |

<br />

### `__eq__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/data/ops/dataset_ops.py#L4666-L4669)

    __eq__(
        other
    )

Return self==value.

### `__ne__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/type_spec.py#L513-L514)

    __ne__(
        other
    ) -> bool

Return self!=value.