Skip to content

Commit

Permalink
Fix issue with data type, and remove 'decoration' characters when sto…
Browse files Browse the repository at this point in the history
…ring logs in array (#25)

* Force panda datatype as str

* Better logs for python script maybe?

* Revert these ones

* typo
  • Loading branch information
mboudet authored Mar 27, 2023
1 parent a05133a commit 6a885a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
16 changes: 7 additions & 9 deletions checkcel/checkcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -115,15 +113,15 @@ 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:
return False

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

Expand All @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions checkcel/checkplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6a885a3

Please sign in to comment.