"""
DataIngestionHandler
Generated by Eden via recursive self-improvement
2025-11-01 10:49:04.155195
"""

import pandas as pd

class DataIngestionHandler:
    """
    This class is designed to handle the ingestion of data from different sources.
    It currently supports CSV, Excel, and SQL databases. The processed data is then returned in a Pandas DataFrame.
    
    Methods:
    - csv_to_dataframe: Converts CSV file content into a pandas DataFrame.
    - excel_to_dataframe: Converts Excel file content into a pandas DataFrame.
    - sql_to_dataframe: Fetches data from an SQL database and converts it into a pandas DataFrame.
    """

    @staticmethod
    def csv_to_dataframe(file_path):
        """
        Reads a CSV file and returns its contents as a pandas DataFrame.

        Args:
            file_path (str): The path to the CSV file.

        Returns:
            pd.DataFrame: A DataFrame containing the data from the CSV file.
        """
        return pd.read_csv(file_path)

    @staticmethod
    def excel_to_dataframe(file_path):
        """
        Reads an Excel file and returns its contents as a pandas DataFrame. Supports multiple sheets.

        Args:
            file_path (str): The path to the Excel file.

        Returns:
            pd.DataFrame: A DataFrame containing the data from the Excel file.
        """
        return pd.read_excel(file_path)

    @staticmethod
    def sql_to_dataframe(db_config, query):
        """
        Fetches data from an SQL database and returns it as a pandas DataFrame.

        Args:
            db_config (dict): Configuration for connecting to the SQL database. Expected keys: 'user', 'password', 'host', 'port', 'database'.
            query (str): The SQL query to execute.

        Returns:
            pd.DataFrame: A DataFrame containing the result of the executed query.
        """
        import sqlalchemy
        engine = sqlalchemy.create_engine(f"mysql+pymysql://{db_config['user']}:{db_config['password']}@{db_config['host']}:{db_config['port']}/{db_config['database']}")
        return pd.read_sql(query, engine)

# Example usage:
if __name__ == "__main__":
    # CSV example
    csv_data = DataIngestionHandler.csv_to_dataframe("path/to/csv_file.csv")
    print(csv_data.head())

    # Excel example
    excel_data = DataIngestionHandler.excel_to_dataframe("path/to/excel_file.xlsx")
    print(excel_data.head())

    # SQL example
    db_config = {
        'user': 'your_username',
        'password': 'your_password',
        'host': 'localhost',
        'port': 3306,
        'database': 'your_database'
    }
    sql_query = "SELECT * FROM your_table"
    sql_data = DataIngestionHandler.sql_to_dataframe(db_config, sql_query)
    print(sql_data.head())