From cbcaf9b156d1cbceb8badc2c8b1f5ed0bbccc642 Mon Sep 17 00:00:00 2001 From: shenwei41 Date: Tue, 11 May 2021 20:28:08 +0800 Subject: [PATCH] Modify error info --- mindspore/mindrecord/shardutils.py | 10 +++++++--- mindspore/mindrecord/tools/tfrecord_to_mr.py | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mindspore/mindrecord/shardutils.py b/mindspore/mindrecord/shardutils.py index 84c893c9a0a..cb95339dd04 100644 --- a/mindspore/mindrecord/shardutils.py +++ b/mindspore/mindrecord/shardutils.py @@ -63,7 +63,7 @@ class ExceptionThread(threading.Thread): self.exception = e self.exc_traceback = ''.join(traceback.format_exception(*sys.exc_info())) -def check_filename(path): +def check_filename(path, arg_name=""): """ check the filename in the path. @@ -77,8 +77,12 @@ def check_filename(path): Returns: Bool, whether filename is valid. """ + if arg_name == "": + arg_name = "File path" + else: + arg_name = "'{}'".format(arg_name) if not path: - raise ParamValueError('File path is not allowed None or empty!') + raise ParamValueError('{} is not allowed None or empty!'.format(arg_name)) if not isinstance(path, str): raise ParamValueError("File path: {} is not string.".format(path)) if path.endswith("/"): @@ -113,7 +117,7 @@ def populate_data(raw, blob, columns, blob_fields, schema): MRMUnsupportedSchemaError: If schema is invalid. """ if raw: - # remove dummy fileds + # remove dummy fields raw = {k: v for k, v in raw.items() if k in schema} else: raw = {} diff --git a/mindspore/mindrecord/tools/tfrecord_to_mr.py b/mindspore/mindrecord/tools/tfrecord_to_mr.py index 54571f8871d..52aa0d19dd5 100644 --- a/mindspore/mindrecord/tools/tfrecord_to_mr.py +++ b/mindspore/mindrecord/tools/tfrecord_to_mr.py @@ -136,6 +136,9 @@ class TFRecordToMR: else: if len(val.shape) != 1: raise ValueError("Parameter len(feature_dict[{}].shape) should be 1.") + if not isinstance(val.shape[0], int): + raise ValueError("Invalid parameter feature_dict, value and type mismatch, " + + "please check item of feature_dict[\"{}\"].".format(key)) if val.shape[0] < 1: raise ValueError("Parameter feature_dict[{}].shape[0] should > 0".format(key)) if val.dtype == self.tf.string: @@ -149,11 +152,11 @@ class TFRecordToMR: """Validation check for inputs of init method""" if not isinstance(source, str): raise ValueError("Parameter source must be string.") - check_filename(source) + check_filename(source, "source") if not isinstance(destination, str): raise ValueError("Parameter destination must be string.") - check_filename(destination) + check_filename(destination, "destination") if feature_dict is None or not isinstance(feature_dict, dict): raise ValueError("Parameter feature_dict is None or not dict.")