sda.misc.utils ============== .. py:module:: sda.misc.utils .. autoapi-nested-parse:: Util functions. Attributes ---------- .. autoapisummary:: sda.misc.utils.ROOT_FOLDER_PATH Classes ------- .. autoapisummary:: sda.misc.utils.Chdir Functions --------- .. autoapisummary:: sda.misc.utils.check_column_exists sda.misc.utils.check_columns_exist sda.misc.utils.get_root sda.misc.utils.get_test_file sda.misc.utils.test_equal Module Contents --------------- .. py:data:: ROOT_FOLDER_PATH .. py:function:: 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. :param df: The DataFrame to check. :type df: :py:class:`pd.DataFrame` :param column_name: The name of the column to check. :type column_name: :py:class:`str` .. py:function:: 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 :param df: The DataFrame to check. :type df: :py:class:`pd.DataFrame` :param column_names: The list of column names to check. :type column_names: :py:class:`list[str]` .. py:function:: get_root() Return the full path of the ``sda`` folder under :py:class:`pathlib.Path` format. Used not to worry about the project architecture. :returns: the abspath to root folder (should end with '/sda') :rtype: :py:class:`str` .. rubric:: Examples >>> from sda.misc.utils import get_root >>> path = get_root() / "tests" / "data" / "spectrum.txt" .. py:function:: get_test_file(file) Return path of file in the sda/tests/data directory. .. py:function:: test_equal(a, b, info='') Compare two values and print a message if they are not equal. .. py:class:: 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. .. rubric:: Examples :: cd = Chdir(os.path.dirname(__file__)) try: (...) except: (...) finally: (...) cd.__del__() .. py:attribute:: savedPath