Skip to content
Snippets Groups Projects
Commit a3d1b08d authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: enhance output when table cannot be parsed

parent 52826846
No related branches found
No related tags found
1 merge request!25MAINT: enhance output when table cannot be parsed
Pipeline #15823 passed
This commit is part of merge request !25. Comments created here will be created in the context of that merge request.
......@@ -51,7 +51,7 @@ def assure_name_format(name):
name = str(name)
if len(name.split(",")) != 2:
raise ValueError("Name field should be 'LastName, FirstName'."
raise ValueError("The field value should be 'LastName, FirstName'. "
"The supplied value was '{}'.".format(name))
return name
......@@ -303,14 +303,20 @@ class TableImporter(object):
"""
for key, datatype in self.datatypes.items():
for idx, val in df.loc[pd.notnull(df.loc[:, key]), key].iteritems():
for idx, val in df.loc[
pd.notnull(df.loc[:, key]), key].iteritems():
if not isinstance(val, datatype):
raise DataInconsistencyError(
"In row no. {rn} and column {c} of file '{fi}' the "
msg = (
"In row no. {rn} and column '{c}' of file '{fi}' the "
"datatype was {was} but it should be "
"{expected}".format(rn=idx, c=key, fi=filename,
was=type(val), expected=datatype)
was=str(type(val)).strip("<>"),
expected=str(datatype).strip("<>"))
)
logger.warning(msg, extra={'identifier': filename,
'category': "inconsistency"})
raise DataInconsistencyError(msg)
def check_missing(self, df, filename=None):
"""
......@@ -394,7 +400,7 @@ class XLSImporter(TableImporter):
df = xls_file.parse(converters=self.converters, **kwargs)
except Exception as e:
logger.warning(
"Cannot parse {}.".format(filename),
"Cannot parse {}.\n{}".format(filename, e),
extra={'identifier': str(filename),
'category': "inconsistency"})
raise DataInconsistencyError(*e.args)
......@@ -411,7 +417,7 @@ class CSVImporter(TableImporter):
**kwargs)
except ValueError as ve:
logger.warning(
"Cannot parse {}.".format(filename),
"Cannot parse {}.\n{}".format(filename, ve),
extra={'identifier': str(filename),
'category': "inconsistency"})
raise DataInconsistencyError(*ve.args)
......@@ -428,7 +434,7 @@ class TSVImporter(TableImporter):
**kwargs)
except ValueError as ve:
logger.warning(
"Cannot parse {}.".format(filename),
"Cannot parse {}.\n{}".format(filename, ve),
extra={'identifier': str(filename),
'category': "inconsistency"})
raise DataInconsistencyError(*ve.args)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment