
    Pi                         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	m
Z
 dededej        fdZi 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        dej        Zeeef         ed<   ej        ej        ej        ej        ej        dZeeef         ed<   d
ddiiZeeeeeez  f         f         ed<   d Ze	j        dd!d"eded#e	d$ededz  dej        ee ez  ej        f         z  fd%Z!d&ededz  d#e	de"ee	f         fd'Z#d(edededz  de$fd)Z%d&ed$edefd*Z&dS )+    N)Callable)Any)PolarsFrameTypedataset_download	sql_querypathreturnc                     t          j        |          5 }t          j        | |          }|cd d d            S # 1 swxY w Y   d S N)sqlite3connectplread_database)r   r   conndfs       m/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/kagglehub/polars_datasets.pywrapped_read_databaser      s    			 $i..                 s   9= =.csv.tsvz.json.jsonl.parquet.featherz.sqlitez.sqlite3z.dbz.db3z.s3dbz.dl3z.xlsz.xlsxz.xlsbz.xlsmz.ods%SUPPORTED_READ_FUNCTIONS_BY_EXTENSION)r   r   r   r   r   %SUPPORTED_SCAN_FUNCTIONS_BY_EXTENSION	separator	STATIC_KWARGS_BY_EXTENSIONz/Loading from a SQLite file requires a SQL query)polars_frame_typepolars_kwargshandler   r   c                b   |i n|}t           j                            |          d         }t          |||          \  }}t	          | |          }	  |t          |||          i t          ||          }	n'# t          $ r}
d|
 }t          |          |
d}
~
ww xY w|t          j
        u r|t          j        u rut          |	t                    rL|	                                D ]6\  }}t          |t          j                  r|                                |	|<   7n|	                                }	|	S )a  Creates polars LazyFrame(s) or DataFrame(s) from a file in the dataset

    Args:
        handle: (string) The dataset handle
        path: (string) Path to a file within the dataset
        polars_frame_type:
            (PolarsFrameType) Optional control for which Frame to return: LazyFrame or DataFrame. The default is
            PolarsFrameType.LAZY_FRAME.

            PolarsFrameType.LAZY_FRAME: We attempt to use a scan_* method if it's available for the provided file
            extension. Otherwise, we use a read_* method to produce a DataFrame and return the result after calling
            .lazy() on it. This satisfies the requested polars_frame_type as a LazyFrame, but does require loading the
            file in memory.

            PolarsFrameType.DATA_FRAME: We use whatever read_* method corresponds to the provided file extension and
            return the resulting DatFrame.
        polars_kwargs:
            (dict) Optional set of kwargs to pass to the polars `read_*` method while constructing the DataFrame(s)
        sql_query:
            (string) Argument to be used for SQLite files. Required when reading a SQLite file. See polars documentation
            for details: https://docs.pola.rs/api/python/stable/reference/api/polars.read_database.html

    Returns:
        - dict[int | str, LazyFrame] or dict[int | str, DataFrame] for Excel-like files with multiple sheets
        - A polars LazyFrame or 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_io_functionr   _build_args_build_kwargs	Exception
ValueErrorr   
DATA_FRAME
LAZY_FRAME
isinstancedictitemsr   	DataFramelazy)r    r   r   r   r   file_extensionio_functionio_frame_typefilepathresulteread_error_messagekeyvalues                 r   load_polars_datasetr:   I   sZ   J (/BB]MW%%d++A.N!6~yRc!d!dK  --H4h	::
NM::
 
  4 4 47A77+,,!34 2227HOLf7f7ffd## 	#$llnn / /
U eR\22 /"'**,,F3K	/ [[]]FMs   %A7 7
BBBr1   c                 l   | t           vrBd|  dd                    t                                                      }t          |          d t           |          }|t          u r|st          t
                    |t          j        u s	| t          vr|t          j        fS t          |          t          j	        fS )NzUnsupported file extension: 'z"'. Supported file extensions are: z, )
r   joinkeysr)   r   MISSING_SQL_QUERY_ERROR_MESSAGEr   r*   r   r+   )r1   r   r   extension_error_messageread_functions        r   r%   r%      s     BBBhN h h.2ii8]8b8b8d8d.e.eh h 	  011t;9.IM---i-8999 O666.Pu:u:u9::1.A?C]^^    r@   c                 &    | t           k    r|gn||gS r   )r   )r@   r   r   s      r   r&   r&      s    "&;;;D66)TARRrA   c                 >    | t           vri nt           |          }i ||S r   )r   )r1   r   static_kwargss      r   r'   r'      s2    $>>>D^_mDn 
 .m-}--rA   )'r#   r   collections.abcr   typingr   polarsr   kagglehub.datasetsr   r   strr/   r   read_csv	read_jsonread_ndjsonread_parquetread_ipc
read_excelr   r-   __annotations__scan_csvscan_ndjsonscan_parquetscan_ipcr   r   boolr>   r+   intr:   tupler%   listr&   r'    rA   r   <module>rZ      sV   					  $ $ $ $ $ $           @ @ @ @ @ @ @ @
S      >
BK>
BK> R\> bn	>
 > > $> %> 
 > !> "> !>$ BM%>& R]'>( R])>. R]/>2 BM3> %tCM':   B KKn> > %tCM':    AGVZH[?\ Dd3d
?&;!;< \ \ \"S  *9)C@ @ @@
@ '	@
 @ Tz@ \DsBL011@ @ @ @F__$'$J_CR_
8_$%_ _ _ _*Sx Ss SsTz Sd S S S S
.# .c .d . . . . . .rA   