1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Fri Sep 27 14:20:58 2019
- @author: tanya
- """
- import os
- import sys
- import pandas as pd
- sys.path.append(os.getcwd())
- class ClassLogging:
- '''
- '''
- def __init__(self, log_name: str = None):
- '''
- '''
- from libraries.log import Log
- self._log = Log(log_name)
- def log_and_raise(self, message):
- '''
- '''
- self._log.error(message)
- raise Exception(message)
- def log_and_warn(self, message):
- '''
- '''
- self._log.warning(message)
- def check_is_file(self, path):
- '''
- '''
- if not os.path.isfile(path):
- err = "File {} not found".format(path)
- self._log.error(err)
- raise FileNotFoundError(err)
- def _check_column_abscence(self, columns: (str, list), data: pd.DataFrame,
- error_or_warning: str):
- '''
- '''
- if isinstance(columns, str):
- columns = [columns]
- for column in columns:
- if column not in data.columns:
- err = ("{} is not an internal column name".format(column))
- getattr(self._log, error_or_warning)(err)
- if error_or_warning == "error":
- raise Exception(err)
- def error_column_abscence(self, columns: (str, list), data: pd.DataFrame):
- '''
- '''
- return self._check_column_abscence(columns=columns,
- data=data,
- error_or_warning="error")
- def warn_column_abscence(self, columns: (str, list), data: pd.DataFrame):
- '''
- '''
- return self._check_column_abscence(columns=columns,
- data=data,
- error_or_warning="warning")
|