sda.misc.utils#
Util functions.
Attributes#
Classes#
Changes current directory for an action, then comes back to initial directory. |
Functions#
|
Check if a column exists in a DataFrame. |
|
Check if a list of columns exists in a DataFrame. |
|
Return the full path of the |
|
Return path of file in the sda/tests/data directory. |
|
Compare two values and print a message if they are not equal. |
Module Contents#
- sda.misc.utils.ROOT_FOLDER_PATH#
- sda.misc.utils.check_column_exists(df, column_name)#
Check if a column exists in a DataFrame.
Fails with an explicit KeyError and the closest name found in the DataFrame.
- Parameters:
df (
pd.DataFrame) – The DataFrame to check.column_name (
str) – The name of the column to check.
- sda.misc.utils.check_columns_exist(df, column_names)#
Check if a list of columns exists in a DataFrame.
Fails with an explicit KeyError and the closest name found in the DataFrame
- Parameters:
df (
pd.DataFrame) – The DataFrame to check.column_names (
list[str]) – The list of column names to check.
- sda.misc.utils.get_root()#
Return the full path of the
sdafolder underpathlib.Pathformat.Used not to worry about the project architecture.
- Returns:
the abspath to root folder (should end with ‘/sda’)
- Return type:
Examples
>>> from sda.misc.utils import get_root >>> path = get_root() / "tests" / "data" / "spectrum.txt"
- sda.misc.utils.get_test_file(file)#
Return path of file in the sda/tests/data directory.
- sda.misc.utils.test_equal(a, b, info='')#
Compare two values and print a message if they are not equal.
- class sda.misc.utils.Chdir(newPath)#
Changes current directory for an action, then comes back to initial directory.
It is used to change the working directory to get into the SDA folder to find the Git files and version, when imported from another program. This class then ensures we get back in the correct directory.
Examples
cd = Chdir(os.path.dirname(__file__)) try: (...) except: (...) finally: (...) cd.__del__()
- savedPath#