Skip to content
Snippets Groups Projects

MAINT: enhance output when table cannot be parsed

Merged Henrik tom Wörden requested to merge f-better-output into dev
All threads resolved!
1 file
+ 14
8
Compare changes
  • Side-by-side
  • Inline
@@ -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)
Loading