-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
35 lines (26 loc) · 1.18 KB
/
util.py
File metadata and controls
35 lines (26 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import time
from pathlib import Path
import pandas as pd
from enums import Color, Operation
class Util:
STATE_COLOR_MAP: dict[Operation, Color] = {Operation.New: Color.Green, Operation.Edited: Color.Orange,
Operation.Deleted: Color.Red}
STATE_STR = "state"
@staticmethod
def colored_text(text: str, state: Operation):
""" This is as per the scheme supported by streamlit framework"""
return f':{Util.STATE_COLOR_MAP[state]}[{text}]'
@staticmethod
def is_none_or_empty_df(df: pd.DataFrame) -> bool:
return df is None or df.shape[0] == 0 or df.dropna(how='all').shape[0] == 0
@staticmethod
def flash_message(handler, message: str, icon: str = "🚨", seconds: int = 5):
alert = handler(message, icon=icon)
time.sleep(seconds)
alert.empty()
@staticmethod
def file_must_exist(file_path: Path) -> None:
if not isinstance(file_path, Path):
raise TypeError(f"'{file_path}' [{type(file_path)}] is not a Path object")
if not file_path.exists() or not file_path.is_file():
raise FileNotFoundError(f"'{file_path}' file does not exist")