Skip to content
Snippets Groups Projects
Commit 6ff421ed authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'f-better-output' into 'dev'

MAINT: enhance output when table cannot be parsed

See merge request !25
parents b3a7eb6c a3d1b08d
No related branches found
No related tags found
1 merge request!25MAINT: enhance output when table cannot be parsed
Pipeline #16667 failed
...@@ -51,7 +51,7 @@ def assure_name_format(name): ...@@ -51,7 +51,7 @@ def assure_name_format(name):
name = str(name) name = str(name)
if len(name.split(",")) != 2: 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)) "The supplied value was '{}'.".format(name))
return name return name
...@@ -303,14 +303,20 @@ class TableImporter(object): ...@@ -303,14 +303,20 @@ class TableImporter(object):
""" """
for key, datatype in self.datatypes.items(): 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): if not isinstance(val, datatype):
raise DataInconsistencyError( msg = (
"In row no. {rn} and column {c} of file '{fi}' the " "In row no. {rn} and column '{c}' of file '{fi}' the "
"datatype was {was} but it should be " "datatype was {was} but it should be "
"{expected}".format(rn=idx, c=key, fi=filename, "{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): def check_missing(self, df, filename=None):
""" """
...@@ -394,7 +400,7 @@ class XLSImporter(TableImporter): ...@@ -394,7 +400,7 @@ class XLSImporter(TableImporter):
df = xls_file.parse(converters=self.converters, **kwargs) df = xls_file.parse(converters=self.converters, **kwargs)
except Exception as e: except Exception as e:
logger.warning( logger.warning(
"Cannot parse {}.".format(filename), "Cannot parse {}.\n{}".format(filename, e),
extra={'identifier': str(filename), extra={'identifier': str(filename),
'category': "inconsistency"}) 'category': "inconsistency"})
raise DataInconsistencyError(*e.args) raise DataInconsistencyError(*e.args)
...@@ -411,7 +417,7 @@ class CSVImporter(TableImporter): ...@@ -411,7 +417,7 @@ class CSVImporter(TableImporter):
**kwargs) **kwargs)
except ValueError as ve: except ValueError as ve:
logger.warning( logger.warning(
"Cannot parse {}.".format(filename), "Cannot parse {}.\n{}".format(filename, ve),
extra={'identifier': str(filename), extra={'identifier': str(filename),
'category': "inconsistency"}) 'category': "inconsistency"})
raise DataInconsistencyError(*ve.args) raise DataInconsistencyError(*ve.args)
...@@ -428,7 +434,7 @@ class TSVImporter(TableImporter): ...@@ -428,7 +434,7 @@ class TSVImporter(TableImporter):
**kwargs) **kwargs)
except ValueError as ve: except ValueError as ve:
logger.warning( logger.warning(
"Cannot parse {}.".format(filename), "Cannot parse {}.\n{}".format(filename, ve),
extra={'identifier': str(filename), extra={'identifier': str(filename),
'category': "inconsistency"}) 'category': "inconsistency"})
raise DataInconsistencyError(*ve.args) raise DataInconsistencyError(*ve.args)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment