Utils
class
rackio_AI.Utils()Encapsulates only static methods useful in any class
check_default_kwargs(default_kw, kw)Given any keyword arguments kw, check if their keys are in default keyword arguments default_kw
- If any key in kw is in default_kw replace kw's key value in default_kw's key
- Otherwise default_kw keeps it key value.
Parameters
- :param defult_kw: (dict) Default keyword arguments.
- :param kw: (dict) Keyword arguments to check.
returns
- kw: (dict) Keyword arguments checked
get_column_names(df)Get columns names given a dataframe
Parameters
- :param df: (pd.DataFrame)
returns
column_names (list)
load_json(filename)Accepts file object, parses the JSON data, populates a Python dictionary with the data and returns it back to you.
Parameters
- :param filename: (str) json filename
returns
json file object parsed
check_extension_files(root_directory, ext='.tpl')This is an utility method which you can check if in any directory exist files with :param ext extension
Parameters
- :param root_directory: (str) directory to look for files
- :param ext (str) default='.tpl' extension file to look for
:return:
- bool: If True, exist ext in root_directory}
Snippet code
>>> from rackio_AI import get_directory, Utils
>>> directory = os.path.join(get_directory('Leak'))
>>> files = Utils.check_extension_files(directory)
check_path(pathname, ext='.tpl')Checks if a pathname is a directory or a file
Parameters
- :param pathname: (str)
- :param ext: (str) file extension to look for
returns
- (filenames, ext): (tuple)
round(value, decimals=0, down=True)Round down or up a value
Parameters
- :param value: (float) value to round
- :param decimals: (int) decimals to round
- :param down: (bool)
- If True round down
- Otherwise round up
returns
- value (float) value rounded down
Snippet code
>>> from rackio_AI import Utils
>>> value = 12.3456
>>> Utils.round(value, decimals=2)
12.34
>>> Utils.round(value, decimals=2, down=False)
12.35
is_between(min_value, value, max_value)Check if a value is between a min and a max value
Parameters
- :param min_value: (float) lower value
- :param value: (float) value to check this conditional
- :param max_value: (float) higher value
returns
bool
Snippet code
>>> from rackio_AI import Utils
>>> Utils.is_between(1, 5.6, 10)
True
>>> Utils.is_between(3.9, 2, 10.5)
False