Module panama.utils.utils
Functions
def check_list_len(reference: List[str], to_check: List[str], reference_label: str = 'values', to_check_label: str = 'serie types') ‑> Optional[bool]-
Function used to check the length of a list compared to another.
Args
reference:List[str]- reference list.
to_check:List[str]- list to check
reference_label:str, optional- name of the reference list. Used in error message. Defaults to "values".
to_check_label:str, optional- name of the list to check. Used in error message. Defaults to "serie types".
Raises
ValueError- f"inconsistent number of values: found {n_reference} {reference_label} and {n_to_check} {to_check_label}."
Returns
Union[bool, None]- if the check is passed, it contains whether a change of the list to check is required.
def list_value_append(*args: Union[Any, Sequence[Any]], drop_null: bool = True) ‑> List[Any]-
Append all values or lists into a list.
Args
drop_null:bool, optional- if True, the None args are not considered. Defaults to True.
Returns
List[str]- the final list.
def time_converter(unix_timestamp) ‑> time.struct_time-
Function used to convert a unix_timestamp to a struct_time.
Args
unix_timestamp:float- unix timestamp.
Returns
struct_time- time object with datetime information.
def timestamp_str_to_datetime(timestamp: str) ‑> datetime.datetime-
Convert a timestamp string to a datetime. Allowed formats are '%Y-%m-%d' and '%Y-%m-%d %H:%M:%S'. If the first format is found, the time is assumed to be 23:59:59.
Args
timestamp:str- timestamp to be converted.
Returns
datetime- timestamp as a datetime object
def wrap_in_list(obj: Union[Any, Iterable[Any]]) ‑> List[Any]-
Function used to wrap an item in a list. If an Iterable that is not a string is passed, a list holding iterable data is returned
Args
obj:Union[Any, Iterable[Any]]- object to wrap.
Returns
List[Any]- wrapped object.