From 6a885a3c2cc4d17e43b8463777281df10cc8362a Mon Sep 17 00:00:00 2001 From: mboudet Date: Mon, 27 Mar 2023 10:15:40 +0200 Subject: [PATCH] Fix issue with data type, and remove 'decoration' characters when storing logs in array (#25) * Force panda datatype as str * Better logs for python script maybe? * Revert these ones * typo --- checkcel/checkcel.py | 16 +++++++--------- checkcel/checkplate.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/checkcel/checkcel.py b/checkcel/checkcel.py index 97e9f1d..bd2f81e 100644 --- a/checkcel/checkcel.py +++ b/checkcel/checkcel.py @@ -88,21 +88,19 @@ def _log_missing(self, missing_items): ) def validate(self): - self.info( - "\nValidating {}{}".format(self.__class__.__name__, "(source={})".format(self.source) if self.source else "") - ) + self.info("\nValidating {}{}".format(self.__class__.__name__, "(source={})".format(self.source) if self.source else "")) if self.source: if self.format == "spreadsheet": with warnings.catch_warnings(): warnings.simplefilter("ignore") - df = pandas.read_excel(self.source, sheet_name=self.sheet, keep_default_na=False, skiprows=self.row) + df = pandas.read_excel(self.source, sheet_name=self.sheet, keep_default_na=False, skiprows=self.row, dtype=str) else: df = pandas.read_csv(self.source, sep=self.delimiter, skiprows=self.row) if len(df) == 0: self.info( - "\033[1;33m" + "Source file has no data" + "\033[0m" + "\033[1;33m", "Source file has no data", "\033[0m" ) return False @@ -115,7 +113,7 @@ def validate(self): validator_set = set(self.validators) self.missing_validators = self.column_set - validator_set if self.missing_validators: - self.info("\033[1;33m" + "Missing..." + "\033[0m") + self.info("\033[1;33m", "Missing...", "\033[0m") self._log_missing_validators() if not self.ignore_missing_validators: @@ -123,7 +121,7 @@ def validate(self): self.missing_fields = validator_set - self.column_set if self.missing_fields: - self.info("\033[1;33m" + "Missing..." + "\033[0m") + self.info("\033[1;33m", "Missing...", "\033[0m") self._log_missing_fields() return False @@ -136,12 +134,12 @@ def validate(self): df.apply(lambda row: self._validate(row), axis=1) if self.failures: - self.info("\033[0;31m" + "Failed" + "\033[0m") + self.info("\033[0;31m", "Failed", "\033[0m") self._log_debug_failures() self._log_validator_failures() return False else: - self.info("\033[0;32m" + "Passed" + "\033[0m") + self.info("\033[0;32m", "Passed", "\033[0m") return True def _validate(self, row): diff --git a/checkcel/checkplate.py b/checkcel/checkplate.py index 473cebc..9f584b7 100644 --- a/checkcel/checkplate.py +++ b/checkcel/checkplate.py @@ -34,20 +34,20 @@ def __init__(self, validators={}, empty_ok=False, ignore_case=False, ignore_spac for validator in self.validators.values(): validator._set_attributes(self.empty_ok, self.ignore_case, self.ignore_space, self.na_ok, self.unique, self.skip_generation, self.skip_validation) - def debug(self, message): - self.logger.debug(message) + def debug(self, message, prefix="", suffix=""): + self.logger.debug("{}{}{}".format(prefix, message, suffix)) self.logs.append("Debug: {}".format(message)) - def info(self, message): - self.logger.info(message) + def info(self, message, prefix="", suffix=""): + self.logger.info("{}{}{}".format(prefix, message, suffix)) self.logs.append("Info: {}".format(message)) - def warn(self, message): - self.logger.warn(message) + def warn(self, message, prefix="", suffix=""): + self.logger.warn("{}{}{}".format(prefix, message, suffix)) self.logs.append("Warning: {}".format(message)) - def error(self, message): - self.logger.error(message) + def error(self, message, prefix="", suffix=""): + self.logger.error("{}{}{}".format(prefix, message, suffix)) self.logs.append("Error: {}".format(message)) def load_from_python_file(self, file_path):