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

FIX: use filter in table_importer

parent 15d51179
No related branches found
No related tags found
1 merge request!22Release 0.3
......@@ -22,7 +22,7 @@ class SuppressKnown(logging.Filter):
when they are known.
"""
def __init__(self, db_file=None, logger=None):
def __init__(self, db_file=None):
if db_file:
self.db_file = db_file
else:
......
......@@ -22,7 +22,7 @@ import logging
import numpy as np
import pandas as pd
from caosadvancedtools.suppressable import Suppressable
from caosadvancedtools.suppressKnown import SuppressKnown
logger = logging.getLogger("caosadvancedtools")
......@@ -61,7 +61,7 @@ class XLS_Importer(object):
obligatory_columns: list of column names, optional
each listed column must not have missing values
"""
self.sup = Suppressable(logger=logger)
self.sup = SuppressKnown()
self.required_columns = list(converters.keys())
self.obligatory_columns = obligatory_columns
self.unique_columns = unique_columns
......@@ -89,9 +89,9 @@ class XLS_Importer(object):
def check_columns(self, df, filename=None):
for col in self.required_columns:
if col not in df.columns:
errmssg = "Column '{}' missing in ".format(col)
errmssg += "{}.".format(filename) if filename else "the file."
raise ValueError(errmssg)
errmsg = "Column '{}' missing in ".format(col)
errmsg += "{}.".format(filename) if filename else "the file."
raise ValueError(errmsg)
def check_unique(self, df, filename=None):
df = df.copy()
......@@ -101,15 +101,15 @@ class XLS_Importer(object):
element = tuple(row.loc[key] for key in self.unique_columns)
if element in uniques:
errmssg = (
errmsg = (
"The {}. row contains the values '{}'.\nThis value "
"combination should be unique, but was used in a previous "
"row in\n").format(index+1, element)
errmssg += "{}.".format(filename) if filename else "the file."
errmssg += "\nThis row will be ignored!"
errmsg += "{}.".format(filename) if filename else "the file."
errmsg += "\nThis row will be ignored!"
self.sup.warning(errmssg, identifier=filename,
category="inconsistency")
logger.warning(errmsg, extra={'identifier':filename,
'category':"inconsistency"})
df = df.drop(index)
else:
uniques.append(element)
......@@ -134,13 +134,13 @@ class XLS_Importer(object):
for key in self.obligatory_columns:
if pd.isnull(row.loc[key]):
errmssg = (
errmsg = (
"Required information is missing ({}) in {}. row"
" (without header) of "
"file:\n{}".format(key, index+1, filename))
self.sup.warning(errmssg, identifier=filename,
category="inconsistency")
logger.warning(errmsg, extra={'identifier':filename,
'category':"inconsistency"})
df = df.drop(index)
continue
......
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