# tfdv.set_domain

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/data-validation/blob/v1.16.1/tensorflow_data_validation/utils/schema_util.py#L116-L179) |

Sets the domain for the input feature in the schema.

    tfdv.set_domain(
        schema: schema_pb2.Schema,
        feature_path: https://www.tensorflow.org/tfx/data_validation/api_docs/python/tfdv/FeaturePath,
        domain: Any
    ) -> None

If the input feature already has a domain, it is overwritten with the newly
provided input domain. This method cannot be used to add a new global domain.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `schema` | A Schema protocol buffer. |
| `feature_path` | The name of the feature whose domain needs to be set. If a FeatureName is passed, a one-step FeaturePath will be constructed and used. For example, "my_feature" -\> types.FeaturePath(\["my_feature"\]) |
| `domain` | A domain protocol buffer or the name of a global string domain present in the input schema. |

<br />

Example: \`\`\`python \>\>\> from tensorflow_metadata.proto.v0 import schema_pb2

    ```
    >>> import tensorflow_data_validation as tfdv >>> schema =
    schema_pb2.Schema() >>> schema.feature.add(name='feature') # Setting a int
    domain. >>> int_domain = schema_pb2.IntDomain(min=3, max=5) >>>
    tfdv.set_domain(schema, "feature", int_domain) # Setting a string domain.
    >>> str_domain = schema_pb2.StringDomain(value=['one', 'two', 'three']) >>>
    tfdv.set_domain(schema, "feature", str_domain) ```


    <!-- Tabular view -->
     <table class="responsive fixed orange">
    <colgroup><col width="214px"><col></colgroup>
    <tr><th colspan="2"><h2 class="add-link">Raises</h2></th></tr>

    <tr>
    <td>
    `TypeError`<a id="TypeError"></a>
    </td>
    <td>
    If the input schema or the domain is not of the expected type.
    </td>
    </tr><tr>
    <td>
    `ValueError`<a id="ValueError"></a>
    </td>
    <td>
    If an invalid global string domain is provided as input.
    </td>
    </tr>
    </table>