src/pds_doi_service/core/input/input_util.py
def _validate_spreadsheet(self, pd_sheet):
        """
        Validates a spreadsheet (XLS or CSV) parsed to a pandas DataFrame to
        ensure the columns are defined as expected.

        Parameters
        ----------
        pd_sheet : pandas.DataFrame
            The spreadsheet to validate.

        Returns
        -------
        pd_sheet : pandas.DataFrame
            The validated spreadsheet with column names standardized as expected
            by the parser.

        Raises
        ------
        InputFormatException
            If the provided spreadsheet's columns are invalid in some way
            (missing columns, incorrect column names, etc.).

        """
        # Save the column names before we modify them, for error reporting
        orig_columns = list(pd_sheet.columns)

        # Trim leading/trailing whitespace from column names
        pd_sheet = pd_sheet.rename(columns=lambda column: column.strip())

        # Standardize column names on lowercase
        pd_sheet = pd_sheet.rename(columns=lambda column: column.lower())

        # Rename columns in a simpler way, accounting for both Linux and Windows
        # line-feeds
        pd_sheet = pd_sheet.rename(
            columns={
                "titles": "title",
                "publication_date (yyyy-mm-dd)": "publication_date",
                "product_type_specific\r\n(pds4 bundle | pds4 collection | pds4 document)": "product_type_specific",
                "product_type_specific\n(pds4 bundle | pds4 collection | pds4 document)": "product_type_specific",
                "related_resource\nlidvid": "related_resource",
                "related_resource\r\nlidvid": "related_resource",
            }
        )

        num_cols = len(pd_sheet.columns)
        num_rows = len(pd_sheet.index)

        logger.debug("num_cols: %d", num_cols)
        logger.debug("num_rows: %d", num_rows)
        logger.debug("data columns: %s", str(list(pd_sheet.columns)))

        if num_cols < self.EXPECTED_NUM_COLUMNS:
            msg = (
                f"Expected {self.EXPECTED_NUM_COLUMNS} columns in the "
                f"provided spreadsheet file, but only found {num_cols} column(s).\n"
                f"Please ensure the all of the following columns are defined before "
                f"resubmitting: {self.MANDATORY_COLUMNS}."
            )

            logger.error(msg)
            raise InputFormatException(msg)

        if not all(column_name in pd_sheet.columns for column_name in self.MANDATORY_COLUMNS):
            msg = (
                f"Expected the following columns to be defined in the provided "
                f"spreadsheet: {self.MANDATORY_COLUMNS}\n"
                f"Received the following columns: {orig_columns}\n"
                f"Please assign the correct column names before resubmitting."
            )
            logger.error(msg)
            raise InputFormatException(msg)

        return pd_sheet

        Validates a spreadsheet (XLS or CSV) parsed to a pandas DataFrame to
        ensure the columns are defined as expected.

        Parameters
        ----------
        pd_sheet : pandas.DataFrame
            The spreadsheet to validate.

        Returns
        -------
        pd_sheet : pandas.DataFrame
            The validated spreadsheet with column names standardized as expected
            by the parser.

        Raises
        ------
        InputFormatException
            If the provided spreadsheet's columns are invalid in some way
            (missing columns, incorrect column names, etc.).

        
Validates a spreadsheet (XLS or CSV) parsed to a pandas DataFrame to
ensure the columns are defined as expected.

Parameters

pd_sheet : pandas.DataFrame
The spreadsheet to validate.

Returns

pd_sheet : pandas.DataFrame
The validated spreadsheet with column names standardized as expected
by the parser.

Raises

InputFormatException
If the provided spreadsheet's columns are invalid in some way
(missing columns, incorrect column names, etc.).
Validates a spreadsheet ( XLS or CSV ) parsed to a pandas DataFrame to ensure the columns are defined as expected . Parameters pd_sheet : pandas . DataFrame The spreadsheet to validate . Returns pd_sheet : pandas . DataFrame The validated spreadsheet with column names standardized as expected by the parser . Raises InputFormatException If the provided spreadsheet ' s columns are invalid in some way ( missing columns incorrect column names etc . ) .
def _validate_spreadsheet(self, pd_sheet):
        orig_columns = list(pd_sheet.columns)
        pd_sheet = pd_sheet.rename(columns=lambda column: column.strip())
        pd_sheet = pd_sheet.rename(columns=lambda column: column.lower())
        pd_sheet = pd_sheet.rename(
            columns={
                "titles": "title",
                "publication_date (yyyy-mm-dd)": "publication_date",
                "product_type_specific\r\n(pds4 bundle | pds4 collection | pds4 document)": "product_type_specific",
                "product_type_specific\n(pds4 bundle | pds4 collection | pds4 document)": "product_type_specific",
                "related_resource\nlidvid": "related_resource",
                "related_resource\r\nlidvid": "related_resource",
            }
        )
        num_cols = len(pd_sheet.columns)
        num_rows = len(pd_sheet.index)
        logger.debug("num_cols: %d", num_cols)
        logger.debug("num_rows: %d", num_rows)
        logger.debug("data columns: %s", str(list(pd_sheet.columns)))
        if num_cols < self.EXPECTED_NUM_COLUMNS:
            msg = (
                f"Expected {self.EXPECTED_NUM_COLUMNS} columns in the "
                f"provided spreadsheet file, but only found {num_cols} column(s).\n"
                f"Please ensure the all of the following columns are defined before "
                f"resubmitting: {self.MANDATORY_COLUMNS}."
            )
            logger.error(msg)
            raise InputFormatException(msg)
        if not all(column_name in pd_sheet.columns for column_name in self.MANDATORY_COLUMNS):
            msg = (
                f"Expected the following columns to be defined in the provided "
                f"spreadsheet: {self.MANDATORY_COLUMNS}\n"
                f"Received the following columns: {orig_columns}\n"
                f"Please assign the correct column names before resubmitting."
            )
            logger.error(msg)
            raise InputFormatException(msg)
        return pd_sheet
def _validate_spreadsheet ( self , pd_sheet ) : orig_columns = list ( pd_sheet . columns ) pd_sheet = pd_sheet . rename ( columns = lambda column : column . strip ( ) ) pd_sheet = pd_sheet . rename ( columns = lambda column : column . lower ( ) ) pd_sheet = pd_sheet . rename ( columns = { "titles" : "title" , "publication_date (yyyy-mm-dd)" : "publication_date" , "product_type_specific\r\n(pds4 bundle | pds4 collection | pds4 document)" : "product_type_specific" , "product_type_specific\n(pds4 bundle | pds4 collection | pds4 document)" : "product_type_specific" , "related_resource\nlidvid" : "related_resource" , "related_resource\r\nlidvid" : "related_resource" , } ) num_cols = len ( pd_sheet . columns ) num_rows = len ( pd_sheet . index ) logger . debug ( "num_cols: %d" , num_cols ) logger . debug ( "num_rows: %d" , num_rows ) logger . debug ( "data columns: %s" , str ( list ( pd_sheet . columns ) ) ) if num_cols < self . EXPECTED_NUM_COLUMNS : msg = ( f"Expected {self.EXPECTED_NUM_COLUMNS} columns in the " f"provided spreadsheet file, but only found {num_cols} column(s).\n" f"Please ensure the all of the following columns are defined before " f"resubmitting: {self.MANDATORY_COLUMNS}." ) logger . error ( msg ) raise InputFormatException ( msg ) if not all ( column_name in pd_sheet . columns for column_name in self . MANDATORY_COLUMNS ) : msg = ( f"Expected the following columns to be defined in the provided " f"spreadsheet: {self.MANDATORY_COLUMNS}\n" f"Received the following columns: {orig_columns}\n" f"Please assign the correct column names before resubmitting." ) logger . error ( msg ) raise InputFormatException ( msg ) return pd_sheet
Validates a spreadsheet (XLS or CSV) parsed to a pandas DataFrame to
ensure the columns are defined as expected.
Validates a spreadsheet ( XLS or CSV ) parsed to a pandas DataFrame to ensure the columns are defined as expected .
"""
        Validates a spreadsheet (XLS or CSV) parsed to a pandas DataFrame to
        ensure the columns are defined as expected.

        Parameters
        ----------
        pd_sheet : pandas.DataFrame
            The spreadsheet to validate.

        Returns
        -------
        pd_sheet : pandas.DataFrame
            The validated spreadsheet with column names standardized as expected
            by the parser.

        Raises
        ------
        InputFormatException
            If the provided spreadsheet's columns are invalid in some way
            (missing columns, incorrect column names, etc.).

        """ # Save the column names before we modify them, for error reporting # Trim leading/trailing whitespace from column names # Standardize column names on lowercase # Rename columns in a simpler way, accounting for both Linux and Windows # line-feeds
self
pd_sheet