
    hp                    P	   S SK Jr  S SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJrJrJrJr  S SKJr  S S	KJrJrJrJrJrJr  S SKJr  S S
KJr  S SKJr   S SK!J"r"J#r#  S SK$J%r%J&r&  S SK'J(r(J)r)J*r*  S SK+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5  S SK6J7r7J8r8J9r9  S SK:J;r;J<r<J=r=  S SK>J?r?  S SK@JArAJBrB  S SKCJDrD  \(       a  S SKJErE  S SKFJGrGJHrHJIrI  SIS jrJSJS jrK      SKS jrL\SSSSSSSSSSSSSS.                               SLS jj5       rM\SSSSSSSSSSSSSSS.                               SMS  jj5       rM\SSSSSSSSSSSSS!.                               SNS" jj5       rM\SSSSSSSSSSSSSS#.                               SOS$ jj5       rM\SSSSSSSSSSSSSS#.                               SPS% jj5       rM\SSSSSSSSSSSSSS.                               SQS& jj5       rM\%" S'SS(S)9\%" S*SS+S)9SSSS,SSS-SS\,SS-S-S-S..                               SRS/ jj5       5       rM\SSSSSSSSSS0.	                       SSS1 jj5       rN\SSSSSSSSSSS2.
                       STS3 jj5       rN\SSSSSSSSS4.                       SUS5 jj5       rN\SSSSSSSSSS6.	                       SVS7 jj5       rN\SSSSSSSSSS6.	                       SWS8 jj5       rN\SSSSSSSSSS0.	                       SXS9 jj5       rNSSS-SS\,SS-S-S-S2.
                       SYS: jjrNSSS\,SSS-S-S-S-S;.
                               SZS< jjrO            S[S= jrP          S\S> jrQ        S]S? jrR                S^S@ jrSS-S-SA.         S_SB jjrTS`SC jrU      SaSD jrVSSE.                   SbSF jjrWSSE.                   SbSG jjrXSSE.                   SbSH jjrYg)c    )annotationsN)defaultdict)Sequence)time)glob)BufferedReaderBytesIOStringIOTextIOWrapper)Path)IOTYPE_CHECKINGAnyCallableNoReturnoverload)
from_arrow)	functions)_PYARROW_AVAILABLEimport_optional)deprecate_renamed_parameterissue_deprecation_warning)deduplicate_namesnormalize_filepathparse_version)
N_INFER_DEFAULTBooleanDateDatetimeDurationInt64NullStringTimeUInt8)FLOAT_DTYPESINTEGER_DTYPESNUMERIC_DTYPES)ModuleUpgradeRequiredErrorNoDataErrorParameterCollisionError)concat)looks_like_urlprocess_file_url)read_csv)Literal)ExcelSpreadsheetEngine
FileSource
SchemaDictc                   Sn/ n[        U [        5      (       a  U R                  5       n [        U [        5      (       a  [        U [        [
        45      (       a  SnU /n U  GH  n[        U[
        [        R                  45      (       a  [        U5      R                  5       (       d  [        R                  R                  [        U5      5      n[        U5      (       a  UR                  U5        M  UR                  [        USS9=n5        U(       d  SU< 3n[!        U5      eSnM  [        U[        R                  5      (       a  [        U5      nUR                  U5        GM     X!4$ )z1Unpack any glob patterns, standardise file paths.TF)	recursivezno workbook found at path )
isinstance
memoryviewtobytesr   bytesstrosPathLiker   existspath
expanduserr-   appendextendr   FileNotFoundError)sourceread_multiple_workbookssourcessrcfilesmsgs         Y/home/james-whalen/.local/lib/python3.13/site-packages/polars/io/spreadsheet/functions.py_sourcesrJ   3   s   "G&*%%!fh'':fucl+K+K"'cC-..tCy7G7G7I7I''$$SX.Cc""s#NND$==5>23':',,&*##r{{++#hNN3   ++    c                .    [         R                  " SSU S9$ )z/Standardize columns with '_duplicated_n' names.z_duplicated_(\d+)z\1)replstring)resub)ss    rI   _standardize_duplicatesrR   Q   s    66&U1==rK   c          
        U (       d  Sn[        U5      eU(       d  U S   $ [        U S   [        R                  5      (       a
  [	        U SS9$ [        [        5      nU  H/  nUR                  5        H  u  pVX5   R                  U5        M     M1     UR                  5        VVs0 s H  u  pxU[	        USS9_M     snn$ s  snnf )Nz3no data found in the given workbook(s) and sheet(s)r   vertical_relaxed)how)	r*   r6   pl	DataFramer,   r   listitemsr@   )	framesrD   rH   sheet_framesressheetdfkvs	            rI   _unpack_read_resultsra   V   s    
 C#"ay&)R\\**f"455 #4(C YY[	#**2. )  BNASASAUVAU6!!344AUVVVs   $B?.)sheet_id
table_nameengineengine_optionsread_options
has_headercolumnsschema_overridesinfer_schema_lengthinclude_file_pathsdrop_empty_rowsdrop_empty_colsraise_if_emptyre   rf   c                   g N rC   rb   
sheet_namerc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   s                  rI   
read_excelrt   o       $ rK   )rb   rs   rc   rd   re   rg   rf   rh   ri   rj   rk   rl   rm   rn   c                   g rp   rq   )rC   rb   rs   rc   rd   re   rg   rf   rh   ri   rj   rk   rl   rm   rn   s                  rI   rt   rt      ru   rK   )rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   c                   g rp   rq   rr   s                  rI   rt   rt      s    $ rK   )rs   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   c                   g rp   rq   rr   s                  rI   rt   rt          $ "rK   c                   g rp   rq   rr   s                  rI   rt   rt      ru   rK   c                   g rp   rq   rr   s                  rI   rt   rt      ry   rK   xlsx2csv_optionsz0.20.6versionread_csv_optionsz0.20.7calamineT)rb   rs   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   c                   [        U 5      u  nnU Vs/ s H  n[        UUUUUUUU	U
UUUUUUS9PM     nn[        UUS9$ s  snf )ap  
Read Excel spreadsheet data into a DataFrame.

.. versionadded:: 1.20
    Support loading data from named table objects with `table_name` parameter.
.. versionadded:: 1.18
    Support loading data from a list (or glob pattern) of multiple workbooks.
.. versionchanged:: 1.0
    Default engine is now "calamine" (was "xlsx2csv").
.. versionchanged:: 0.20.7
    The `read_csv_options` parameter was renamed `read_options`.
.. versionchanged:: 0.20.6
    The `xlsx2csv_options` parameter was renamed `engine_options`.

Parameters
----------
source
    Path(s) to a file or a file-like object (by "file-like object" we refer to
    objects that have a `read()` method, such as a file handler like the builtin
    `open` function, or a `BytesIO` instance). For file-like objects, the stream
    position may not be updated after reading.
sheet_id
    Sheet number(s) to convert (set `0` to load all sheets as DataFrames) and
    return a `{sheetname:frame,}` dict. (Defaults to `1` if neither this nor
    `sheet_name` are specified). Can also take a sequence of sheet numbers.
sheet_name
    Sheet name(s) to convert; cannot be used in conjunction with `sheet_id`. If
    more than one is given then a `{sheetname:frame,}` dict is returned.
table_name
    Name of a specific table to read; note that table names are unique across
    the workbook, so additionally specifying a sheet id or name is optional;
    if one of those parameters *is* specified, an error will be raised if
    the named table is not found in that particular sheet.
engine : {'calamine', 'openpyxl', 'xlsx2csv'}
    Library used to parse the spreadsheet file; defaults to "calamine".

    * "calamine": this engine can be used for reading all major types of Excel
      Workbook (`.xlsx`, `.xlsb`, `.xls`) and is dramatically faster than the
      other options, using the `fastexcel` module to bind the Rust-based Calamine
      parser.
    * "openpyxl": this engine is significantly slower than both `calamine` and
      `xlsx2csv`, but can provide a useful fallback if you are otherwise unable
      to read data from your workbook.
    * "xlsx2csv": converts the data to an in-memory CSV before using the native
      polars `read_csv` method to parse the result.
engine_options
    Additional options passed to the underlying engine's primary parsing
    constructor (given below), if supported:

    * "calamine": n/a (can only provide `read_options`)
    * "openpyxl": `load_workbook <https://openpyxl.readthedocs.io/en/stable/api/openpyxl.reader.excel.html#openpyxl.reader.excel.load_workbook>`_
    * "xlsx2csv": `Xlsx2csv <https://github.com/dilshod/xlsx2csv/blob/f35734aa453d65102198a77e7b8cd04928e6b3a2/xlsx2csv.py#L157>`_
read_options
    Options passed to the underlying engine method that reads the sheet data.
    Where supported, this allows for additional control over parsing. The
    specific read methods associated with each engine are:

    * "calamine": `load_sheet_by_name <https://fastexcel.toucantoco.dev/fastexcel.html#ExcelReader.load_sheet_by_name>`_
      (or `load_table <https://fastexcel.toucantoco.dev/fastexcel.html#ExcelReader.load_table>`_
      if using the `table_name` parameter).
    * "openpyxl": n/a (can only provide `engine_options`)
    * "xlsx2csv": see :meth:`read_csv`
has_header
    Indicate if the first row of the table data is a header or not. If False,
    column names will be autogenerated in the following format: `column_x`, with
    `x` being an enumeration over every column in the dataset, starting at 1.
columns
    Columns to read from the sheet; if not specified, all columns are read. Can
    be given as a sequence of column names or indices, or a single column name.
schema_overrides
    Support type specification or override of one or more columns.
infer_schema_length
    The maximum number of rows to scan for schema inference. If set to `None`, the
    entire dataset is scanned to determine the dtypes, which can slow parsing for
    large workbooks. Note that only the "calamine" and "xlsx2csv" engines support
    this parameter.
include_file_paths
    Include the path of the source file(s) as a column with this name.
drop_empty_rows
    Indicate whether to omit empty rows when reading data into the DataFrame.
drop_empty_cols
    Indicate whether to omit empty columns (with no headers) when reading data into
    the DataFrame (note that empty column identification may vary depending on the
    underlying engine being used).
raise_if_empty
    When there is no data in the sheet,`NoDataError` is raised. If this parameter
    is set to False, an empty DataFrame (with no columns) is returned instead.

Returns
-------
DataFrame
    If reading a single sheet.
dict
    If reading multiple sheets, a "{sheetname: DataFrame, ...}" dict is returned.

See Also
--------
read_ods

Notes
-----
* Where possible, prefer the default "calamine" engine for reading Excel Workbooks,
  as it is significantly faster than the other options.
* When using the `xlsx2csv` engine the target Excel sheet is first converted
  to CSV using `xlsx2csv.Xlsx2csv(source).convert()` and then parsed with Polars'
  :func:`read_csv` function. You can pass additional options to `read_options`
  to influence this part of the parsing pipeline.
* If you want to read multiple sheets and set *different* options (`read_options`,
  `schema_overrides`, etc), you should make separate calls as the options are set
  globally, not on a per-sheet basis.

Examples
--------
Read the "data" worksheet from an Excel file into a DataFrame.

>>> pl.read_excel(
...     source="test.xlsx",
...     sheet_name="data",
... )  # doctest: +SKIP

If the correct dtypes can't be determined, use the `schema_overrides` parameter
to specify them, or increase the inference length with `infer_schema_length`.

>>> pl.read_excel(
...     source="test.xlsx",
...     schema_overrides={"dt": pl.Date},
...     infer_schema_length=None,
... )  # doctest: +SKIP

Using the `xlsx2csv` engine, read table data from sheet 3 in an Excel workbook as a
DataFrame while skipping empty lines in the sheet. As sheet 3 does not have a header
row, you can pass the necessary additional settings for this to the `read_options`
parameter; these will be passed to :func:`read_csv`.

>>> pl.read_excel(
...     source="test.xlsx",
...     sheet_id=3,
...     engine="xlsx2csv",
...     engine_options={"skip_empty_lines": True},
...     read_options={"has_header": False, "new_columns": ["a", "b", "c"]},
... )  # doctest: +SKIP
)rb   rs   rc   rd   re   rf   ri   rj   rk   rn   rg   rh   rl   rm   rZ   rD   rJ   _read_spreadsheetra   )rC   rb   rs   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   rE   rD   rF   rZ   s                      rI   rt   rt      s    D (0'7$G$& %B$ C# 	!!)%- 31)!++	
" %  B(   7 )Bs   !A )	rb   rg   rh   ri   rj   rk   rl   rm   rn   c       
            g rp   rq   rC   rb   rs   rg   rh   ri   rj   rk   rl   rm   rn   s              rI   read_odsr          rK   )
rb   rs   rg   rh   ri   rj   rk   rl   rm   rn   c       
            g rp   rq   r   s              rI   r   r     r   rK   )rg   rh   ri   rj   rk   rl   rm   rn   c       
            g rp   rq   r   s              rI   r   r     s     rK   )	rs   rg   rh   ri   rj   rk   rl   rm   rn   c       
            g rp   rq   r   s              rI   r   r          "rK   c       
            g rp   rq   r   s              rI   r   r     r   rK   c       
            g rp   rq   r   s              rI   r   r     r   rK   c       
            [        U 5      u  pU Vs/ s H  n[        UUUSS0 SUUUU
UU	UUS9PM     nn[        UUS9$ s  snf )a
  
Read OpenOffice (ODS) spreadsheet data into a DataFrame.

Parameters
----------
source
    Path to a file or a file-like object (by "file-like object" we refer to objects
    that have a `read()` method, such as a file handler like the builtin `open`
    function, or a `BytesIO` instance). For file-like objects, the stream position
    may not be updated accordingly after reading.
sheet_id
    Sheet number(s) to convert, starting from 1 (set `0` to load *all* worksheets
    as DataFrames) and return a `{sheetname:frame,}` dict. (Defaults to `1` if
    neither this nor `sheet_name` are specified). Can also take a sequence of sheet
    numbers.
sheet_name
    Sheet name(s) to convert; cannot be used in conjunction with `sheet_id`. If
    more than one is given then a `{sheetname:frame,}` dict is returned.
has_header
    Indicate if the first row of the table data is a header or not. If False,
    column names will be autogenerated in the following format: `column_x`, with
    `x` being an enumeration over every column in the dataset, starting at 1.
columns
    Columns to read from the sheet; if not specified, all columns are read. Can
    be given as a sequence of column names or indices.
schema_overrides
    Support type specification or override of one or more columns.
infer_schema_length
    The maximum number of rows to scan for schema inference. If set to `None`, the
    entire dataset is scanned to determine the dtypes, which can slow parsing for
    large workbooks.
include_file_paths
    Include the path of the source file(s) as a column with this name.
drop_empty_rows
    Indicate whether to omit empty rows when reading data into the DataFrame.
drop_empty_cols
    Indicate whether to omit empty columns (with no headers) when reading data into
    the DataFrame (note that empty column identification may vary depending on the
    underlying engine being used).
raise_if_empty
    When there is no data in the sheet,`NoDataError` is raised. If this parameter
    is set to False, an empty DataFrame (with no columns) is returned instead.

Returns
-------
DataFrame, or a `{sheetname: DataFrame, ...}` dict if reading multiple sheets.

See Also
--------
read_excel

Examples
--------
Read the "data" worksheet from an OpenOffice spreadsheet file into a DataFrame.

>>> pl.read_ods(
...     source="test.ods",
...     sheet_name="data",
... )  # doctest: +SKIP

If the correct dtypes can't be determined, use the `schema_overrides` parameter
to specify them, or increase the inference length with `infer_schema_length`.

>>> pl.read_ods(
...     source="test.ods",
...     sheet_id=3,
...     schema_overrides={"dt": pl.Date},
...     raise_if_empty=False,
... )  # doctest: +SKIP
Nr   )rb   rs   rc   rd   re   rf   ri   rj   rk   rn   rl   rm   rg   rh   r   r   )rC   rb   rs   rg   rh   ri   rj   rk   rl   rm   rn   rE   rD   rF   rZ   s                  rI   r   r     s    h (0'7$G& %B$ C# 	!- 31)++!	
" %  B(   7 )Bs   !?)
re   rf   ri   rj   rk   rh   rg   rn   rl   rm   c                  [        U [        5      (       a&  [        U 5      n [        U 5      (       a  [	        U 5      n [        U
[        5      (       a  U
/n
[        UUU
UUS9nU=(       d    0 R                  5       n[        U=(       d    0 5      n[        X@U5      u  nnn [        XUU5      u  nnU Vs0 s H  nUU" UUUUUU
UUUS9	_M     nn[        US5      (       a  UR                  5         U(       d"  Uc  SU4OSU4u  nnSU SU< 3n[        U5      eU	(       aq  [        U [        5      (       a  U OSnUR                  5        VVs0 s H;  u  nnUUR                  [        R                   " U5      R#                  U	5      5      _M=     nnnU(       a  U$ [%        ['        UR)                  5       5      5      $ s  snf ! [        US5      (       a  UR                  5         f f = fs  snnf )	N)rd   rh   rg   rj   )	parserrs   ri   rf   rn   rh   rc   rl   rm   closeidnamez%no matching sheets found when `sheet_z` is zin-mem)r6   r:   r   r-   r.   _get_read_optionscopydict_initialise_spreadsheet_parser_get_sheet_nameshasattrr   
ValueErrorrY   with_columnsFlitaliasnextitervalues)rC   rb   rs   rc   rd   re   rf   ri   rj   rk   rh   rg   rn   rl   rm   	reader_fnr   
worksheetssheet_namesreturn_multiple_sheetsr   parsed_sheetsparamvaluerH   workbookframes                              rI   r   r     s   $ &##F+&!!%f-F'3)$/L %*002N,23 %C%!Ivz.>*j/
++ $
 $ )!1)-% / /
 
 $ 	 
 67##LLN+5+=h'FJCWu5eWE%Ko'446(  -224
4e %$$QUU8_%:%:;M%NOO4 	 
 ]))+,--?
 67##LLN $
s%   G  3F;G  AG';G   $G$c                  U =(       d    0 R                  5       n US:X  aq  SU ;   a  U(       a  Sn[        U5      eU R                  S5      b  USL a  Sn[        U5      eSU ;   a  U[        :w  a  S	n[        U5      eX0S'   USL a  SU ;  a  SU S'   U $ US
:X  ab  SU ;   a  U(       a  Sn[        U5      eSU ;   a  U S   ULa  Sn[        U5      eSU ;   a  U[        :w  a  Sn[        U5      eX0S'   SU ;  a  X@S'   U $ X0S'   X@S'   U $ )zFNormalise top-level parameters to engine-specific 'read_options' dict.r   use_columnsz?cannot specify both `columns` and `read_options["use_columns"]`
header_rowNFzNthe values of `has_header` and `read_options["header_row"]` are not compatibleschema_sample_rowszRcannot specify both `infer_schema_length` and `read_options["schema_sample_rows"]`xlsx2csvrh   z;cannot specify both `columns` and `read_options["columns"]`rg   zNthe values of `has_header` and `read_options["has_header"]` are not compatiblerj   zScannot specify both `infer_schema_length` and `read_options["infer_schema_length"]`)r   r+   getr   )rf   rd   rh   rj   rg   rH   s         rI   r   r     sO    !&B,,.L\)wSC)#..l+7J%<ObC)#.."l2?2fC)#..-@)*<|#C)-L&2 / 
:	%7OC)#..L(\**<bC)#..#|3?2gC)#...A*+|+)3&
  /B*+%/\"rK   c                   U b  Ub  SU< SU < S3n[        U5      e/ nU c*  Uc'  U(       a  SOUS   S   nUR                  U5        SnXW4$ U S:X  a  UR                  S U 5       5        S	nXW4$ [        U[        5      =(       a    [        U[
        5      (       + =(       d    [        U [        5      =(       d    U S:H  n[        U[
        5      (       a  U4O
U=(       d    S
=n(       aG  U V	s1 s H  oS   iM	     n
n	U H*  nXj;  a  SU< 3n[        U5      eUR                  U5        M,     XW4$ [        U [        5      (       a  U 4O
U =(       d    S
n[        USS9 VV	s0 s H$  u  pU S:X  d  U	S   U;   d  U	S   U;   d  M  XS   _M&     nnn	U H8  nUR                  U5      =nc  SU 3n[        U5      eUR                  U5        M:     XW4$ s  sn	f s  sn	nf )zEEstablish sheets to read; indicate if we are returning a dict frames.Nz"cannot specify both `sheet_name` (z) and `sheet_id` ()r   r   Fc              3  *   #    U  H	  oS    v   M     g7f)r   Nrq   ).0wss     rI   	<genexpr>#_get_sheet_names.<locals>.<genexpr>  s     ;
"f:
s   Trq   z-no matching sheet found when `sheet_name` is    )startindexz+no matching sheet found when `sheet_id` is )	r   r@   rA   r6   r   r:   int	enumerater   )rb   rs   rc   r   rH   r   r   r   namesr   known_sheet_namesidsidxsheet_names_by_idxs                 rI   r   r     s"    
 62:.@RS[R^^_`oKJ.!tz!}V'<4 !&@ ..? 
Q;
;;!%: ..5 
H-QjS6Q2Q (H-1} 	 (
C88ZMj>NB
5 
 7A AjFj A0I$RC$S/)""4(	 $ .. ",Hc!:!:8+BC  )1="=GCMR[C%72f:;N  Z=  "
 .22377D@GuMC$S/)""4(	  ..' !B"s   ,GG	Gc                   [        U[        5      (       a)  [        U5      R                  5       (       d  [	        U5      eU S:X  a  [        S5      nSSSSS.R                  5        H  u  pEUR                  XE5        M     [        U[        5      (       a  [        U5      nUR                  " U40 UD6nUR                  R                  n[        Xg4$ U S:X  aw  [        S5      n[        U[        5      (       a  [        U5      nUR                  " U4SS0UD6n[        U5       V	V
s/ s H  u  pU	S-   U
R                   S	.PM     nn	n
["        Xg4$ U S
:X  GaQ  [        SSS9n[        U[        5      [        U[        5      pU(       d  U(       a,  [%        UR&                  =n5      S:  a  SU S3n[)        U5      eU(       a  UR+                  5       nO[        U[,        [.        45      (       ap  SUR0                  ;  a  SUR2                  < S3n[5        U5      eUR2                  =n(       a!  [        U5      R                  5       (       a  UnOUR7                  5       nUR8                  " U40 UD6n[        UR:                  5       V	Vs/ s H  u  n	nU	S-   US	.PM     nn	n[<        Xg4$ SU < 3n[?        U5      es  sn
n	f s  snn	f )zNInstantiate the indicated spreadsheet parser and establish related properties.r   Fz%f)exclude_hidden_sheetsskip_empty_linesskip_hidden_rowsfloatformatopenpyxl	data_onlyTr   )r   r   r   	fastexcelz0.7.0)min_versionr   
   z5`fastexcel` >= 0.10 is required to read bytes; found r   bzfile z must be opened in binary modezunrecognized engine: ) r6   r:   r   r=   rB   r   rY   
setdefaultr9   r	   Xlsx2csvr   sheets_read_spreadsheet_xlsx2csvload_workbookr   title_read_spreadsheet_openpyxlr   __version__r)   getvaluer   r   moder   OSErrorreadrt   r   _read_spreadsheet_calamineNotImplementedError)rd   rC   re   r   optionr   r   r   r   ir   r   reading_bytesioreading_bytesmodule_versionrH   filenamenms                     rI   r   r   8  s    &#tF|':':'<'<''":. &+ % %	

 %'MF %%f4 fe$$V_F""6<^<'')699	:	":.fe$$V_F''Q$Q.QBKFBSTBSAE2884BST)699	:	#KWE	vw'vu% ' }-'333N3
3 J.IYYZ[C,S11__&F ?@@&++%fkk_,JKcl"$kk)()tH~/D/D/F/F!%%f??6?@R@R6S
6SUQa!eR(6S 	 
 *699!&
,C
c
""C U6
s   $J6J<c               >   U R                  5       S:X  a  [        U5      $ U R                  S5        Uc  0 n/ nU(       a  UR                  S0 5      =n(       a
  [	        SSS9  UR                  SU5      n	[        U	5      R                  U5      (       a  Sn
[        U
5      e0 U	EUE0 p;UR                  5        H&  u  pU[        :w  a  XU'   M  UR                  U5        M(     UR                  5       nX2S'   [        [        U 4SU0UD6UUUS	9nU(       a  0 UR                  nnU H\  nUU   [        :X  d  M  [         R"                  " U5      R$                  R'                  S
S5      R$                  R)                  5       X'   M^     U(       a  UR*                  " S0 UD6nU$ )zCTranslate StringIO buffer containing delimited data as a DataFrame.r   dtypesz_the `dtypes` parameter for `read_csv` is deprecated. It has been renamed to `schema_overrides`.z0.20.31r}   ri   zNcannot specify columns in both `schema_overrides` and `read_options['dtypes']`	separator)r^   rn   rl   rm   (?:[ T]00:00:00(?:\.0+)?)$ rq   )tell_empty_frameseekr   r   setintersectionr+   rY   r   r@   r   _drop_null_datar/   schemar#   r   colr:   replaceto_dater   )csvr   rf   ri   rl   rm   rn   	date_cols
csv_dtypescsv_schema_overridesrH   	overridesr   dtyper^   
date_castsr   s                    rI   _csv_buffer_to_framer   ~  s    xxzQN++ HHQKI%))(B77:7%q!
  ,//0BJO#$112BCCbC)#..&R)=&RAQ&RTV#"*IB}',$  $	 + $((*+;'(	

 

 &''	
B F
BbzV#EE"IS!>CS   .:.BIrK   )rl   rm   c                  / nU(       a  U R                    H  nUS:X  d  [        R                  " SU5      (       d  M'  X   nUR                  [        :X  dd  UR                  5       U R                  :X  dF  UR                  [        ;   d  Ms  UR                  SS5      R                  5       U R                  :X  d  M  UR                  U5        M     U(       a  U R                  " U6 n U R                  U R                  s=:X  a  S:X  a  O  O[        U5      $ U(       aG  U R                  [        R                  " [        R                   " 5       R#                  5       5      ) 5      $ U $ )zFIf DataFrame contains columns/rows that contain only nulls, drop them.r   z(_duplicated_|__UNNAMED__)\d+$r   N)rh   rO   matchr   r"   
null_countheightr(   r   r@   dropwidthr   filterr   all_horizontalallis_null)r^   rn   rl   rm   	null_colscol_namer   s          rI   r   r     s     I

H 2~*KX!V!VlII%~~'2994		^3KK40;;=J $$X. # )$B	yyBHH!!N++yy!**1557??+<==>>IrK   c                T    U (       a  Sn[        U5      e[        R                  " 5       $ )Nz^empty Excel sheet

If you want to read this as an empty DataFrame, set `raise_if_empty=False`.)r*   rV   rW   )rn   rH   s     rI   r   r     s)    ^ 	 #<<>rK   c                    U(       a;  SSK JnJn  [        US   [        5      (       a  U" U6 OU" U6 nU R                  U5      n U $ )Nr   )by_indexby_name)polars.selectorsr	  r
  r6   r   select)r^   rh   r	  r
  colss        rI   _reorder_columnsr    s=     6%/
C%@%@x!gwFWYYt_IrK   )rc   c               "   [        S5      n	[        U	R                  =n
5      nUS:  a  SU;   a  SU
 S3n[        U5      eUS:  a  SU;   a  SU
 S3n[        U5      eU(       a  US	:  a  S
U
 S3n[	        U5      eU(       a$  [        U[        5      (       d  [        U5      nXBS'   U=(       d    0 nUR                  S5      S:X  a.  US	 US:  a  SO[        R                  [        S5      S5      US'   OU(       a  US:  a  UR                  S0 5      nUR                  5        Hl  u  pX;  d  M  UR                  5       =n[        ;   a  SX'   M,  U[        ;   a  SX'   M<  U[        :X  a  SX'   ML  U[         :X  a  SX'   M\  U["        :X  d  Mh  SX'   Mn     XS'   US:  a%  U R$                  " S&SU0UD6nUR'                  5       nOU(       aP  U R(                  " U40 UD6nU(       a%  UUR*                  :w  a  SU< SU< 3n[-        U5      eUR'                  5       nOH[.        (       a  U R0                  " U40 UD6n[3        U5      nOU R4                  " U40 UD6n[3        U5      nUR                  SS5      cH  UR                  S5      (       d2  [        SUR6                  S-   5       Vs/ s H  nSU 3PM
     snUl        [;        UUUUS9nU(       Ga  UR=                  5       UR>                  nn/ 0 nnUR                  5        GH.  u  nnUU   [        :w  a  UUU'   M  U[@        :X  aU  URC                  [D        RF                  " U5      RH                  RK                  [M        USS 5      [M        US S 5      S!95        Mz  U[N        :X  a[  [D        RF                  " U5      RH                  RQ                  S"S#5      nURC                  URH                  RS                  5       5        M  U[T        :X  a@  URC                  [D        RF                  " U5      RH                  RW                  5       5        GM)  UUU'   GM1     U(       a  URX                  " U6 nU(       a  UR[                  US$9nUR]                  5       nUR_                  5       (       a  UR[                  [`        [        05      n/ nUR>                  R                  5        GHO  u  nnUU;  d  M  U[        ;   a  [D        RF                  " U5      Rc                  5       Re                  [D        RF                  " U5      5      [D        RF                  " U5      Rg                  5       -  [D        RF                  " U5      R[                  [h        5      /nURC                  U5        M  U[@        :X  d  M  [D        RF                  " U5      Rj                  Rm                  5       Ro                  [m        SSS5      5      [D        RF                  " U5      R[                  [N        5      /nURC                  U5        GMR     U(       am  URq                  S% U 5       5      Rs                  S5      n [u        U U5       V!V"V#s/ s H  u  n!u  n"n#U!(       d  M  U#PM     sn#n"n!=n$(       a  URX                  " U$6 nU$ s  snf s  sn#n"n!f )'Nr   )r   	   r   zYa more recent version of `fastexcel` is required for 'schema_sample_rows' (>= 0.9; found r   )r   r      r   zUa more recent version of `fastexcel` is required for 'use_columns' (>= 0.10.2; found )r      zTa more recent version of `fastexcel` is required for 'table_name' (>= 0.12.0; found r   )r   r  r   rN   i @  r   r   r   floatdurationboolean)r      r  r   table named  not found in sheet r   Fcolumn_namesr   column_rn   rl   rm   	time_unit	time_zoner  r  r   r   )r   c              3  D   #    U  H  oS    R                  SS9v   M     g7f)r   T)ignore_nullsN)r  )r   ds     rI   r   -_read_spreadsheet_calamine.<locals>.<genexpr>  s     PKqtxxTx:Ks    rq   );r   r   r   r)   r   r6   rX   r   r   fromkeysrangerY   	base_typer'   r&   r#   r    r   load_sheet_by_name	to_polars
load_tablers   RuntimeErrorr   load_sheet_eagerr   
load_sheetr   rh   r   lazyr   r   r@   r   r   r:   to_datetimegetattrr   r   r   r$   to_timer   castcollectis_emptyr"   floor
eq_missing
is_not_nanr!   dtr   eqr  rowzip)%r   rs   rf   ri   rh   rc   rl   rm   rn   r   original_versionfastexcel_versionrH   parser_dtypesr   r   
base_dtyper   r^   xl_tablews_arrowr   lfr   str_to_temporalupdated_overridesr   tpdt_strtype_checksc
check_cast
apply_castapply_r0  downcasts%                                        rI   r   r     s     ,I%):O:O&O&6P6!&:l&Jijzi{{|}(--:%-<*Gefvewwxy(--''1deudvvwxo'4((7mG&-]#'-2,-2-. !J. uU|X6 	X
 
/7:$((26+113KD("'//"33JF*/M'</*1M'6)*2M'8+*4M'7**3M' 4 "/X:%&&GJG,G\\^((D|DHjH,?,??$ZN2FznU"3''##%B..zJ\JHH%B((D|DHH%BL%08AQAQB
 B
 27q"((Q,1GH1GAGA3-1GHBJ	
%''	
B WWY		F-/*&,,.FBbzV#(*!"%x&&EE"IMM--")"k4"@")"k4"@ .  tr../LbQ&&vzz'9'9';<t&&quuRy}}'<'<'>?(*!"%! /$ /2B 12BZZ\ 
{{}}WWdF^$ KIIOO%5$$$EE!HNN$//a9AEE!H<O<O<QQEE!HMM%(
 "":.("EE!HKK$$&))$q!Q-8EE!HMM$'
 "":. &" YYPKPPTTUVW
),Z)E
)E%UIQD)E
 
8 
 (+BII I~
s   %ZZ
"Z
c          
     4	   UR                  SS5      n	UR                  SS5      n
U=(       d    0 nU	S:H  n/ nU(       ak  U(       dd  Su  pU R                   H%  nUS-  nX^R                  ;   d  M  XR                  p  O   Uc'  U(       a
  SU< S	U< 3O
S
U< SU< S3n[	        U5      eOX   n[        WSS5      =n(       a  U(       a  UU   O![        [        UR                  5       5      5      n[        UUR                     5      nU(       d  [        U5      $ U
(       a(  UR                  S UR                  S5       5       5        O1UR                  S [        S[        US   5      S-   5       5       5        UR                  (       a  USUR                  *  nUnOU(       a  S
U< SU< S3n[	        U5      eU
(       d\  [        UR!                  5       5      =n(       d  [        U5      $ [        US   5      n[        SUS-   5       Vs/ s H  nSU 3PM
     nnO_UR!                  5       nU HI  nU Vs/ s H  nUR"                  PM     nn[%        S U 5       5      (       d  M8  UR                  U5          O   U(       a  [&        OSn/ n[)        U[)        U6 5       GH  u  nnU(       d	  U(       a  M  U Vs/ s H  nUR"                  PM     nnU(       d  UR+                  U5      =n[&        :X  a   U Vs/ s H  nUb  [-        U5      OUPM     nnUR+                  U5      =n [.        [0        [2        4;   a  [4        R6                  " UUSS9n!U!R8                  [&        :X  a  U [0        :X  a1  U!R,                  R;                  [        U SS5      [        U SS5      S9n!O{U [.        :X  a5  U!R,                  R=                  SS5      R,                  R?                  5       n!O<U [2        :X  a  U!R,                  RA                  5       n!O[4        R6                  " UUUSS9n!URC                  U!5        GM     [E        S U 5       5      n"[4        RF                  " [I        [)        U"U5      5      UU	SS9n#[K        U#UUUS9n#[M        U#U5      n#U#$ s  snf s  snf s  snf s  snf )zAUse the 'openpyxl' library to read data from the given worksheet.rj   Nrg   Tr   )Nr   r   r  r  zno named tables found in sheet z (looking for r   tablesc              3  8   #    U  H  oR                   v   M     g 7frp   )r   )r   cells     rI   r   -_read_spreadsheet_openpyxl.<locals>.<genexpr>  s     =**   c              3  ,   #    U  H
  nS U 3v   M     g7f)r  Nrq   )r   ns     rI   r   rP    s     L1KAGA3-1Ks   r  c              3  (   #    U  H  oS Lv   M
     g 7frp   rq   )r   r`   s     rI   r   rP    s     9j}js   F)strictr  r  r  r   r   )r   rU  c              3  8   #    U  H  oR                   v   M     g 7frp   )r   )r   rQ   s     rI   r   rP    s     :kffkrQ  )ri   rj   rU  r  )'popr   rM  r   r)  r.  r   r   r   rX   refr   rA   r$  lentotalsRowCount	iter_rowsr   anyr#   r9  r   r:   r   r   r$   rV   Seriesr   r-  r   r   r/  r@   r   rW   r   r   r  )$r   rs   rf   ri   rh   rc   rl   rm   rn   rj   rg   no_inferenceheadern_tablesr]   r   rH   rM  tablerows	rows_itern_colsrS  r8  rO  
row_valuesr   series_datar   column_datar   r`   rC  rQ   r   r^   s$                                       rI   r   r     s=    '**+@$G!!,5J'-2&!+L!F*&
&&EMH\\)!&J	 '
   zn,@O6znNS]R``ab 
 s##   Xt,,v,&0z"d4;P6QBuyyM"//MM=!==MMLq#d1g,:J1KLL/5///0D		/
~^J>YZ[3!%blln!55I5#N331&F-21fqj-AB-Asm-AFBFI 589STdjjS
99j999MM*-	 ! #FEK i9k-89[Tdjj[F9)9)=)=d)C CN EKKFqQ]#a&:FK&**400dHd5KKIIdF5977f$X~EE--&-b+t&D&-b+t&D .  tEEMM92#ggi  tEEMMOIIdF%Fq!1 :4 :k::E	S$%)/	
B 

%''	
B 
"g	&BIg C : : Ls   R6R:R8Rc          
        U(       a  Sn	[        U	5      e[        5       n
[        R                  " 5          [        R                  " S[
        S9  U R                  XS9  SSS5        UR                  SS5        U(       a  XBS'   / nU(       ae  UR                  5        HQ  u  pU[        :X  d  M  [        X<'   UR                  [        R                  " U5      R                  [        5      5        MS     [        U
S	UUUUUS
9nU(       a  UR                   " U6 nUR#                  [$        5      n['        X5      $ ! , (       d  f       N= f)zAUse the 'xlsx2csv' library to read data from the given worksheet.zDthe `table_name` parameter is not supported by the 'xlsx2csv' engineignore)category)outfile	sheetnameNtruncate_ragged_linesTrh   ,)r   rf   ri   rn   rl   rm   )r   r
   warningscatch_warningsfilterwarningsDeprecationWarningconvertr   rY   r   r%   r@   r   r   r0  r   r   renamerR   r  )r   rs   rf   ri   rh   rc   rl   rm   rn   rH   
csv_buffercast_to_booleanr   r   r^   s                  rI   r   r     s    ToJ		 	 	" 	3EFz@	 
# 3T:")YO*002JC(- %&&quuSzw'?@ 3
 
!)%''
B __o.	*	+BB((= 
#	"s   )D55
E)rC   r2   returnztuple[Any, bool])rQ   r:   rw  r:   )rZ   z2list[pl.DataFrame] | list[dict[str, pl.DataFrame]]rD   boolrw  r   ) rC   r2   rb   Noners   r:   rc   
str | Nonerd   r1   re   dict[str, Any] | Nonerf   r{  rg   rx  rh   *Sequence[int] | Sequence[str] | str | Noneri   SchemaDict | Nonerj   
int | Nonerk   rz  rl   rx  rm   rx  rn   rx  rw  pl.DataFrame) rC   r2   rb   ry  rs   ry  rc   rz  rd   r1   re   r{  rg   rx  rf   r{  rh   r|  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r  ) rC   r2   rb   r   rs   r:   rc   rz  rd   r1   re   r{  rf   r{  rg   rx  rh   r|  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r   ) rC   r2   rb   Literal[0] | Sequence[int]rs   ry  rc   rz  rd   r1   re   r{  rf   r{  rg   rx  rh   r|  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  dict[str, pl.DataFrame]) rC   r2   rb   r   rs   ry  rc   rz  rd   r1   re   r{  rf   r{  rg   rx  rh   r|  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r  ) rC   r2   rb   ry  rs   list[str] | tuple[str]rc   rz  rd   r1   re   r{  rf   r{  rg   rx  rh   r|  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r  ) rC   r2   rb   int | Sequence[int] | Noners   #str | list[str] | tuple[str] | Nonerc   rz  rd   r1   re   r{  rf   r{  rg   rx  rh   r|  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  &pl.DataFrame | dict[str, pl.DataFrame])rC   r2   rb   ry  rs   r:   rg   rx  rh   $Sequence[int] | Sequence[str] | Noneri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r  )rC   r2   rb   ry  rs   ry  rg   rx  rh   r  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r  )rC   r2   rb   r   rs   r:   rg   rx  rh   r  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r   )rC   r2   rb   r  rs   ry  rg   rx  rh   r  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r  )rC   r2   rb   r   rs   ry  rg   rx  rh   r  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r  )rC   r2   rb   ry  rs   r  rg   rx  rh   r  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r  )rC   r2   rb   r  rs   r  rg   rx  rh   r  ri   r}  rj   r~  rk   rz  rl   rx  rm   rx  rn   rx  rw  r  ) rC   str | IO[bytes] | bytesrb   r  rs   str | Sequence[str] | Nonerc   rz  rd   r1   re   r{  rf   r{  ri   r}  rj   r~  rk   rz  rh   r|  rg   rx  rn   rx  rl   rx  rm   rx  rw  r  )rf   r{  rd   r1   rh   r  rj   r~  rg   rx  rw  dict[str, Any])
rb   r  rs   r  rc   rz  r   zlist[dict[str, Any]]rw  ztuple[list[str], bool])rd   rz  rC   r  re   r  rw  z=tuple[Callable[..., pl.DataFrame], Any, list[dict[str, Any]]])r   r
   r   r:   rf   r  ri   r}  rl   rx  rm   rx  rn   rx  rw  r  )
r^   r  rn   rx  rl   rx  rm   rx  rw  r  )rn   rx  rw  r  )r^   r  rh   r  rw  r  )r   r   rs   rz  rf   r  ri   r}  rh   r  rc   rz  rl   rx  rm   rx  rn   rx  rw  r  )Z
__future__r   r;   rO   ro  collectionsr   collections.abcr   datetimer   r   ior   r	   r
   r   pathlibr   typingr   r   r   r   r   r   polars._reexport	_reexportrV   polarsr   r   r   polars._dependenciesr   r   polars._utils.deprecationr   r   polars._utils.variousr   r   r   polars.datatypesr   r   r   r   r    r!   r"   r#   r$   r%   polars.datatypes.groupr&   r'   r(   polars.exceptionsr)   r*   r+   polars.functionsr,   polars.io._utilsr-   r.   polars.io.csv.functionsr/   r0   polars._typingr1   r2   r3   rJ   rR   ra   rt   r   r   r   r   r   r   r   r   r  r   r   r   rq   rK   rI   <module>r     s   " 	 	  # $   ? ?  G G   ! D W V   P O 
 $ = ,MM,<>
W>W "W 		W2 
  %(,/*-:=*-&)%(!  	
  # * (  8 ( $ #    !" # 
( 
  %(,/*-:=*-&)%(!  	
  # *  ( 8 ( $ #    !" # 
( 
 !%(,/*-:=*-&)%(!  	
  # * (  8 ( $ #    !" # 
, 

  %(,/*-:=*-&)%(!"" )" 	"
 " #" *" (" " 8" (" $" #" " "  !"" #" 
"( 

  %(,/*-:=*-&)%(!  	
  # * (  8 ( $ #    !" # 
( 
  %(,/*-:=*-&)%(!"" " '	"
 " #" *" (" " 8" (" $" #" " "  !"" #" 
"( /1A8T/R ,06:!%/,0*.:>*.&5%)  !xx )x 4	x
 x #x *x (x x 8x (x $x #x x x  !x" ,#x S Uxv 
 47*-&)%(  	
  2 ( $ #     
  
 47*-&)%(  	
  2 ( $ #     
  
 47*-&)%(  	
  2 ( $ #     
  

 47*-&)%("" )" 	"
 " 2" (" $" #" " " " " 
"  

 47*-&)%(  	
  2 ( $ #     
  
 47*-&)%("" " '	"
 " 2" (" $" #" " " " " 
"& ,06:48*.&5%)  ll )l 4	l
 l 2l (l $l #l l l l ,ll -1*.*.&5%):>  !L.#L. )L. +	L.
 L. #L. *L. (L. (L. $L. #L. 8L. L. L. L.  !L." ,#L.^3'3 #3 2	3
 $3 3 3l//(//*// // %	//
 //dC#C##C# #C# C	C#LA	A A !	A
 (A A A A AP !   	
  DC$ "SS S !	S
 (S 2S S S S S Sz "mm m !	m
 (m 2m m m m m mn "0)0) 0) !	0)
 (0) 20) 0) 0) 0) 0) 0)rK   