|
|
|
@ -38,7 +38,7 @@ from .iterators import DictIterator, TupleIterator
|
|
|
|
|
from .validators import check, check_batch, check_shuffle, check_map, check_repeat, check_zip, check_rename, \
|
|
|
|
|
check_project, check_imagefolderdatasetv2, check_mnist_cifar_dataset, check_manifestdataset, \
|
|
|
|
|
check_tfrecorddataset, check_vocdataset, check_celebadataset, check_minddataset, check_generatordataset, \
|
|
|
|
|
check_zip_dataset, check_add_column, check_columns
|
|
|
|
|
check_zip_dataset
|
|
|
|
|
from ..core.datatypes import mstype_to_detype, mstypelist_to_detypelist
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -2334,20 +2334,13 @@ class Schema:
|
|
|
|
|
self.dataset_type = ''
|
|
|
|
|
self.num_rows = 0
|
|
|
|
|
else:
|
|
|
|
|
if not os.path.isfile(schema_file) or not os.access(schema_file, os.R_OK):
|
|
|
|
|
raise ValueError("The file %s does not exist or permission denied!" % schema_file)
|
|
|
|
|
try:
|
|
|
|
|
with open(schema_file, 'r') as load_f:
|
|
|
|
|
json_obj = json.load(load_f)
|
|
|
|
|
self.from_json(json_obj)
|
|
|
|
|
except json.decoder.JSONDecodeError:
|
|
|
|
|
raise RuntimeError("Schema file failed to load.")
|
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
|
raise RuntimeError("Schema file failed to decode.")
|
|
|
|
|
except Exception:
|
|
|
|
|
raise RuntimeError("Schema file failed to open.")
|
|
|
|
|
self.from_json(json_obj)
|
|
|
|
|
raise RuntimeError("Schema file failed to load")
|
|
|
|
|
|
|
|
|
|
@check_add_column
|
|
|
|
|
def add_column(self, name, de_type, shape=None):
|
|
|
|
|
"""
|
|
|
|
|
Add new column to the schema.
|
|
|
|
@ -2366,8 +2359,10 @@ class Schema:
|
|
|
|
|
if isinstance(de_type, typing.Type):
|
|
|
|
|
de_type = mstype_to_detype(de_type)
|
|
|
|
|
new_column["type"] = str(de_type)
|
|
|
|
|
else:
|
|
|
|
|
elif isinstance(de_type, str):
|
|
|
|
|
new_column["type"] = str(DataType(de_type))
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError("Unknown column type")
|
|
|
|
|
|
|
|
|
|
if shape is not None:
|
|
|
|
|
new_column["shape"] = shape
|
|
|
|
@ -2404,7 +2399,6 @@ class Schema:
|
|
|
|
|
RuntimeError: If column's name field is missing.
|
|
|
|
|
RuntimeError: If column's type field is missing.
|
|
|
|
|
"""
|
|
|
|
|
check_columns(columns, columns)
|
|
|
|
|
self.columns = []
|
|
|
|
|
for col in columns:
|
|
|
|
|
name = None
|
|
|
|
@ -2449,8 +2443,6 @@ class Schema:
|
|
|
|
|
RuntimeError: if dataset type is missing in the object.
|
|
|
|
|
RuntimeError: if columns are missing in the object.
|
|
|
|
|
"""
|
|
|
|
|
if not isinstance(json_obj, dict) or json_obj is None:
|
|
|
|
|
raise ValueError("Expected non-empty dict.")
|
|
|
|
|
for k, v in json_obj.items():
|
|
|
|
|
if k == "datasetType":
|
|
|
|
|
self.dataset_type = v
|
|
|
|
|