<commit_before>"""
Retrieve data from EPA's Integrated Planning Model (IPM) v6

Unlike most of the PUDL data sources, IPM is not an annual timeseries. This file
assumes that only v6 will be used as an input, so there are a limited number
of files.
"""

import logging
from pathlib import Path
import pandas as pd
from pudl.settings import SETTINGS
import pudl.constants as pc

logger = logging.getLogger(__name__)

datadir = Path(SETTINGS['epaipm_data_dir'])
pudl_datadir = Path(SETTINGS['pudl_data_dir'])


def get_epaipm_name(file):
    """
    Return the appopriate EPA IPM excel file.

    Args:
        file (str): The file that we're trying to read data for.
    Returns:
        path to EPA IPM spreadsheet.
    """
    if sorted(datadir.glob(file)):
        name = sorted(datadir.glob(file))[0]
    elif sorted(pudl_datadir.glob(file)):
        name = name = sorted(pudl_datadir.glob(file))[0]
    else:
        raise FileNotFoundError(
            f'No files matching the pattern "{file}" were found.'
        )

    return name


def get_epaipm_file(filename, read_file_args):
    """
    Read in files to create dataframes. No need to use ExcelFile
    objects with the IPM files because each file is only a single sheet.

    Args:
        filename: ['single_transmission', 'joint_transmission']
        read_file_args: dictionary of arguments for pandas read_*

    Returns:
        xlsx file of EPA IPM data
    """
    epaipm_file = {}
    pattern = pc.files_dict_epaipm[filename]
    logger.info(
        f"Extracting data from EPA IPM {filename} spreadsheet.")

    full_filename = get_epaipm_name(pattern)
    suffix = full_filename.suffix

    if suffix == '.xlsx':<commit_msg>Remove double assignment of variable<commit_after>"""
Retrieve data from EPA's Integrated Planning Model (IPM) v6

Unlike most of the PUDL data sources, IPM is not an annual timeseries. This file
assumes that only v6 will be used as an input, so there are a limited number
of files.
"""

import logging
from pathlib import Path
import pandas as pd
from pudl.settings import SETTINGS
import pudl.constants as pc

logger = logging.getLogger(__name__)

datadir = Path(SETTINGS['epaipm_data_dir'])
pudl_datadir = Path(SETTINGS['pudl_data_dir'])


def get_epaipm_name(file):
    """
    Return the appopriate EPA IPM excel file.

    Args:
        file (str): The file that we're trying to read data for.
    Returns:
        path to EPA IPM spreadsheet.
    """
    if sorted(datadir.glob(file)):
        name = sorted(datadir.glob(file))[0]
    elif sorted(pudl_datadir.glob(file)):
        name = sorted(pudl_datadir.glob(file))[0]
    else:
        raise FileNotFoundError(
            f'No files matching the pattern "{file}" were found.'
        )

    return name


def get_epaipm_file(filename, read_file_args):
    """
    Read in files to create dataframes. No need to use ExcelFile
    objects with the IPM files because each file is only a single sheet.

    Args:
        filename: ['single_transmission', 'joint_transmission']
        read_file_args: dictionary of arguments for pandas read_*

    Returns:
        xlsx file of EPA IPM data
    """
    epaipm_file = {}
    pattern = pc.files_dict_epaipm[filename]
    logger.info(
        f"Extracting data from EPA IPM {filename} spreadsheet.")

    full_filename = get_epaipm_name(pattern)
    suffix = full_filename.suffix

    if suffix == '.xlsx':
{'fraction_non_alphanumeric': 0.08362676056338028, 'fraction_numerical': 0.002347417840375587, 'mean_word_length': 3.1828220858895704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '774554', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1056, 'n_words': 360}