o
    ̳iu                     @   s  U d dl Z d dlZd dlmZ d dlmZ d dlZd dlm	Z	 de
de
dejfdd	Zi d
ejdejdejdejdejdejdejdededededededejdejdejdejejejejdZee
ef ed< ddidd id!Zee
ee
e
eB f f ed"< d#Zdd$d%e
de
d&ede
dB dejeee
B ejf B f
d'd(Zd)e
de
dB defd*d+Zd,ede
de
dB defd-d.Zd)e
d&edefd/d0ZdS )1    N)Callable)Any)dataset_download	sql_querypathreturnc                 C   s>   t |}t| |}|W  d    S 1 sw   Y  d S N)sqlite3connectpdread_sql_query)r   r   conndf r   M/home/ubuntu/.local/lib/python3.10/site-packages/kagglehub/pandas_datasets.pywrapped_read_sql_query   s   $r   z.csv.tsvz.json.jsonlz.xmlz.parquetz.featherz.sqlitez.sqlite3z.dbz.db3z.s3dbz.dl3z.xlsz.xlsxz.xlsmz.xlsb)z.odfz.odsz.odt%SUPPORTED_READ_FUNCTIONS_BY_EXTENSIONsep	linesT)r   r   STATIC_KWARGS_BY_EXTENSIONz/Loading from a SQLite file requires a SQL query)pandas_kwargshandler   c          
   
   C   s   |du ri n|}t j|d }t||}t| |}z|t|||i t||}W |S  tyA } z
d| }	t|	|d}~ww )a  Creates pandas DataFrame(s) from a file in the dataset

    Args:
        handle: (string) The dataset handle
        path: (string) Path to a file within the dataset
        pandas_kwargs:
            (dict) Optional set of kwargs to pass to the pandas `read_*` method while constructing the DataFrame(s)
        sql_query:
            (string) Argument to be used for SQLite files. Required when reading a SQLite file. See pandas documentation
            for details: https://pandas.pydata.org/docs/reference/api/pandas.read_sql_query.html

    Returns:
        - dict[int | str, DataFrame] for Excel-like files with multiple sheets
        - A pandas DataFrame for all others

    Raises:
        ValueError: If the file extension is not supported or the file fails to read
    N   zError reading file: )	osr   splitext_validate_read_functionr   _build_args_build_kwargs	Exception
ValueError)
r   r   r   r   file_extensionread_functionfilepathresulteread_error_messager   r   r   load_pandas_dataset<   s    




r)   r#   c                 C   sL   | t vrd|  ddt   }t|d t |  }|tu r$|s$tt|S )NzUnsupported file extension: 'z"'. Supported file extensions are: z, )r   joinkeysr"   r   MISSING_SQL_QUERY_ERROR_MESSAGE)r#   r   extension_error_messager$   r   r   r   r   g   s   
r   r$   c                 C   s   | t kr|gS ||gS r   )r   )r$   r   r   r   r   r   r   v   s   r   c                 C   s    | t vri nt |  }i ||S r   )r   )r#   r   static_kwargsr   r   r   r    {   s   r    )r   r	   collections.abcr   typingr   pandasr   kagglehub.datasetsr   str	DataFramer   read_csv	read_jsonread_xmlread_parquetread_feather
read_excelr   dict__annotations__r   boolr,   intr)   r   listr   r    r   r   r   r   <module>   s~   
 	.
+