mindspore/docs/api/api_python/dataset/mindspore.dataset.Schema.rst

72 lines
2.0 KiB
ReStructuredText
Raw Normal View History

2021-11-27 16:09:05 +08:00
mindspore.dataset.Schema
=========================
.. py:class:: mindspore.dataset.Schema(schema_file=None)
2021-11-23 15:00:48 +08:00
2022-01-05 16:22:27 +08:00
用于解析和存储数据列属性的类。
2021-11-23 15:00:48 +08:00
2021-11-27 16:09:05 +08:00
**参数:**
2022-01-05 16:22:27 +08:00
- **schema_file** (str): schema文件的路径默认值None。
2021-11-27 16:09:05 +08:00
**返回:**
2021-11-23 15:00:48 +08:00
2021-11-27 16:09:05 +08:00
schema对象关于数据集的行列配置的策略信息。
2021-11-23 15:00:48 +08:00
2021-11-27 16:09:05 +08:00
**异常:**
2021-11-23 15:00:48 +08:00
2021-12-02 20:06:28 +08:00
**RuntimeError** 模式文件加载失败。
2021-11-27 16:09:05 +08:00
2022-01-29 11:50:17 +08:00
.. py:method:: add_column(name, de_type, shape=None)
2022-01-22 11:25:00 +08:00
2021-11-23 15:00:48 +08:00
向schema中添加新列。
2021-11-27 16:09:05 +08:00
**参数:**
- **name** (str): 列的新名称。
- **de_type** (str): 列的数据类型。
2022-01-05 16:22:27 +08:00
- **shape** (list[int], 可选): 列shape默认值None-1表示该维度的shape是未知的。
2021-11-23 15:00:48 +08:00
2021-11-27 16:09:05 +08:00
**异常:**
2022-02-14 14:34:37 +08:00
**ValueError** 列类型未知。
2021-11-23 15:00:48 +08:00
2022-01-29 11:50:17 +08:00
.. py:method:: from_json(json_obj)
2021-11-23 15:00:48 +08:00
从JSON对象获取schema文件。
2021-11-27 16:09:05 +08:00
**参数:**
2021-12-04 20:36:47 +08:00
- **json_obj** (dictionary): 解析的JSON对象。
2021-11-27 16:09:05 +08:00
**异常:**
2021-11-23 15:00:48 +08:00
2022-02-14 14:34:37 +08:00
- **RuntimeError** 对象中存在未知的项。
- **RuntimeError** 对象中缺少数据集类型。
- **RuntimeError** 对象中缺少列。
2022-01-29 11:50:17 +08:00
.. py:method:: parse_columns(columns)
2021-11-23 15:00:48 +08:00
解析传入的数据列的属性并将其添加到自身的schema中。
2021-11-27 16:09:05 +08:00
**参数:**
2021-11-23 15:00:48 +08:00
2021-11-27 16:09:05 +08:00
- **columns** (Union[dict, list[dict], tuple[dict]]): 数据集属性信息从schema文件解码。
2021-11-23 15:00:48 +08:00
2022-01-29 11:50:17 +08:00
- **list** [dict]'name'和'type'必须为key值'shape'可选。
- **dict** columns.keys()作为名称columns.values()是dict其中包含'type''shape'可选。
2021-11-23 15:00:48 +08:00
2021-11-27 16:09:05 +08:00
**异常:**
2021-11-23 15:00:48 +08:00
2022-02-11 15:23:20 +08:00
- **RuntimeError** - 解析列失败。
- **RuntimeError** - 列name字段缺失。
- **RuntimeError** - 列type字段缺失。
2021-11-27 16:09:05 +08:00
2022-01-29 11:50:17 +08:00
.. py:method:: to_json()
2021-11-23 15:00:48 +08:00
获取schema的JSON字符串。
2021-11-27 16:09:05 +08:00
**返回:**
str模式的JSON字符串。
2021-11-23 15:00:48 +08:00