tfdv.set_domain
Stay organized with collections
Save and categorize content based on your preferences.
Sets the domain for the input feature in the schema.
tfdv.set_domain(
schema: schema_pb2.Schema,
feature_path: 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.
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.
|
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>
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-18 UTC.
[null,null,["Last updated 2024-10-18 UTC."],[],[],null,["# tfdv.set_domain\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/data-validation/blob/v1.16.1/tensorflow_data_validation/utils/schema_util.py#L116-L179) |\n\nSets the domain for the input feature in the schema. \n\n tfdv.set_domain(\n schema: schema_pb2.Schema,\n feature_path: ../tfdv/FeaturePath,\n domain: Any\n ) -\u003e None\n\nIf the input feature already has a domain, it is overwritten with the newly\nprovided input domain. This method cannot be used to add a new global domain.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `schema` | A Schema protocol buffer. |\n| `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\" -\\\u003e types.FeaturePath(\\[\"my_feature\"\\]) |\n| `domain` | A domain protocol buffer or the name of a global string domain present in the input schema. |\n\n\u003cbr /\u003e\n\nExample: \\`\\`\\`python \\\u003e\\\u003e\\\u003e from tensorflow_metadata.proto.v0 import schema_pb2 \n\n ```\n \u003e\u003e\u003e import tensorflow_data_validation as tfdv \u003e\u003e\u003e schema =\n schema_pb2.Schema() \u003e\u003e\u003e schema.feature.add(name='feature') # Setting a int\n domain. \u003e\u003e\u003e int_domain = schema_pb2.IntDomain(min=3, max=5) \u003e\u003e\u003e\n tfdv.set_domain(schema, \"feature\", int_domain) # Setting a string domain.\n \u003e\u003e\u003e str_domain = schema_pb2.StringDomain(value=['one', 'two', 'three']) \u003e\u003e\u003e\n tfdv.set_domain(schema, \"feature\", str_domain) ```\n\n\n \u003c!-- Tabular view --\u003e\n \u003ctable class=\"responsive fixed orange\"\u003e\n \u003ccolgroup\u003e\u003ccol width=\"214px\"\u003e\u003ccol\u003e\u003c/colgroup\u003e\n \u003ctr\u003e\u003cth colspan=\"2\"\u003e\u003ch2 class=\"add-link\"\u003eRaises\u003c/h2\u003e\u003c/th\u003e\u003c/tr\u003e\n\n \u003ctr\u003e\n \u003ctd\u003e\n `TypeError`\u003ca id=\"TypeError\"\u003e\u003c/a\u003e\n \u003c/td\u003e\n \u003ctd\u003e\n If the input schema or the domain is not of the expected type.\n \u003c/td\u003e\n \u003c/tr\u003e\u003ctr\u003e\n \u003ctd\u003e\n `ValueError`\u003ca id=\"ValueError\"\u003e\u003c/a\u003e\n \u003c/td\u003e\n \u003ctd\u003e\n If an invalid global string domain is provided as input.\n \u003c/td\u003e\n \u003c/tr\u003e\n \u003c/table\u003e"]]