
    hH                    h   S SK Jr  S SKrS SK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  S SKJr  S SKJr  S SKJrJrJr  S SKJrJr  S S	KJrJrJrJ r J!r!  S S
K"J#r#  \RH                  " \%5         S SK&J'r'J(r(  S SK&J)r*  SSS5        \(       a  S SK+J,r,  S SK-J.r.J/r/J0r0  S SK1J2r2  S SK3J4r4  \" SSSS9\" SSSS9SSSSSSS SS.                   S&S jj5       5       r5SSSS SSS.               S'S jjr6\" SSSS9\" SSSS9SSSSSS SS.                 S(S jj5       5       r7SSSS SS.             S)S  jjr8S*S! jr)\" SSSS9\" SSSS9SSSSS SS"SS#SSSSSS$.                               S+S% jj5       5       r9g! , (       d  f       GN)= f),    )annotationsN)Path)IOTYPE_CHECKINGAnyLiteral)import_optional)deprecate_renamed_parameter)is_path_or_str_sequenceis_str_sequencenormalize_filepath)wrap_dfwrap_ldf)is_glob_patternis_local_fileparse_columns_argparse_row_index_argsprepare_file_arg)!_init_credential_provider_builder)PyDataFramePyLazyFrame)read_ipc_schema)Sequence)	DataFrameDataType	LazyFrame)
SchemaDict)CredentialProviderFunctionrow_count_namerow_index_namez0.20.4)versionrow_count_offsetrow_index_offsetFT)columnsn_rowsuse_pyarrow
memory_mapstorage_optionsr    r#   rechunkc               j   [        U =n	[        [        45      (       a  [        U	5      R                  S5      =n
(       d  [        R
                  " S5      S:X  a  U
(       a  U(       a  Sn[        U5      e[        U UUUUUS9nU(       aO  [        US   [        5      (       a&  UR                  [        R                  " U5      5      nOUR                  U5      nUR                  5       nU$ U(       a  U(       a  U(       d  Sn[        U5      e[        XUS9 nU(       an  [        S	S
SS9nUR                  UUUS9n[         R"                  R%                  UUS9nUb  UR'                  Xg5      nUb  UR)                  SU5      nUsSSS5        $ [+        UUUUUUUS9sSSS5        $ ! , (       d  f       g= f)a  
Read into a DataFrame from Arrow IPC (Feather v2) file.

See "File or Random Access format" on https://arrow.apache.org/docs/python/ipc.html.
Arrow IPC files are also known as Feather (v2) files.

.. versionchanged:: 0.20.4
    * The `row_count_name` parameter was renamed `row_index_name`.
    * The `row_count_offset` parameter was renamed `row_index_offset`.

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). If `fsspec` is installed, it will be used
    to open remote files. For file-like objects, the stream position may not be
    updated accordingly after reading.
columns
    Columns to select. Accepts a list of column indices (starting at zero) or a list
    of column names.
n_rows
    Stop reading from IPC file after reading `n_rows`.
    Only valid when `use_pyarrow=False`.
use_pyarrow
    Use pyarrow or the native Rust reader.
memory_map
    Try to memory map the file. This can greatly improve performance on repeated
    queries as the OS may cache pages.
    Only uncompressed IPC files can be memory mapped.
storage_options
    Extra options that make sense for `fsspec.open()` or a particular storage
    connection, e.g. host, port, username, password, etc.
row_index_name
    Insert a row index column with the given name into the DataFrame as the first
    column. If set to `None` (default), no row index column is created.
row_index_offset
    Start the row index at this offset. Cannot be negative.
    Only used if `row_index_name` is set.
rechunk
    Make sure that all data is contiguous.

Returns
-------
DataFrame

See Also
--------
scan_ipc : Lazily read from an IPC file or multiple files via glob patterns.

Warnings
--------
Calling `read_ipc().lazy()` is an antipattern as this forces Polars to materialize
a full csv file and therefore cannot push any optimizations into the reader.
Therefore always prefer `scan_ipc` if you want to work with `LazyFrame` s.

If `memory_map` is set, the bytes on disk are mapped 1:1 to memory.
That means that you cannot write to the same filename.
E.g. `pl.read_ipc("my_file.arrow").write_ipc("my_file.arrow")` will fail.
zhf://POLARS_FORCE_ASYNC1z4`use_pyarrow=True` is not supported for Hugging Face)r%   r(   r    r#   r)   r   zF`n_rows` cannot be used with `use_pyarrow=True` and `memory_map=False`r&   r(   zpyarrow.feather z8is required when using 'read_ipc(..., use_pyarrow=True)'
err_prefix
err_suffix)r'   r$   r)   Nr$   r%   r    r#   r)   r'   )
isinstancestrr   
startswithosgetenv
ValueErrorscan_ipcintselectFnthcollectr   r	   
read_tableplr   _from_arrowwith_row_indexslice_read_ipc_impl)sourcer$   r%   r&   r'   r(   r    r#   r)   vis_hfmsglfdfdatapyarrow_feathertbls                    Q/home/james-whalen/.local/lib/python3.13/site-packages/polars/io/ipc/functions.pyread_ipcrP   )   s   X 	;1d,, a&##G,	,	, 99)*c1 [HCS/!+)-
 '!*c**YYquuW~.YYw'ZZ\	vjVo	
	-!UO
 ",,% - C
 ))#w)?B)&&~H!XXa('
 
* )-!
+
 
 
s   A,F$F$$
F2r3   c          
        [        U [        [        45      (       a
  [        U SS9n [        U[        5      (       a  U/n[        U [        5      (       a  [	        U 5      (       ao  [        U 5      (       a_  [        U UUUUS9nUc  UR                  5       nU$ [        USS9(       a!  UR                  U5      R                  5       nU$ Sn	[        U	5      e[        U5      u  p[        R                  " U UU
U[        X45      US9n[        U5      $ )NFcheck_not_directory)r%   r)   r    r#   )	allow_strzccannot use glob patterns and integer based projection as `columns` argument

Use columns: List[str])r'   )r4   r5   r   r   r   r   r:   r?   r   r<   	TypeErrorr   r   rP   r   r   )rF   r$   r%   r    r#   r)   r'   scanrK   rI   
projectionpydfs               rO   rE   rE      s
    &3+&&#FF'3)&#?6#:#:}V?T?T)-
 ?B 	 W6W%--/B 		-  C.  ,G4J^>D 4=    )r$   r%   r&   r(   r    r#   r)   c          
        [        XUS9 nU(       a  [        SSSS9n	U	R                  U5       n
U
R                  5       n[        R
                  R                  XS9nUb  UR                  XV5      nUb  UR                  SU5      nUsSSS5        sSSS5        $ [        UUUUUUS	9sSSS5        $ ! , (       d  f       N%= f! , (       d  f       g= f)
a  
Read into a DataFrame from Arrow IPC record batch stream.

See "Streaming format" on https://arrow.apache.org/docs/python/ipc.html.

.. versionchanged:: 0.20.4
    * The `row_count_name` parameter was renamed `row_index_name`.
    * The `row_count_offset` parameter was renamed `row_index_offset`.

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). If `fsspec` is installed, it will be used
    to open remote files. For file-like objects, the stream position may not be
    updated accordingly after reading.
columns
    Columns to select. Accepts a list of column indices (starting at zero) or a list
    of column names.
n_rows
    Stop reading from IPC stream after reading `n_rows`.
    Only valid when `use_pyarrow=False`.
use_pyarrow
    Use pyarrow or the native Rust reader.
storage_options
    Extra options that make sense for `fsspec.open()` or a particular storage
    connection, e.g. host, port, username, password, etc.
row_index_name
    Insert a row index column with the given name into the DataFrame as the first
    column. If set to `None` (default), no row index column is created.
row_index_offset
    Start the row index at this offset. Cannot be negative.
    Only used if `row_index_name` is set.
rechunk
    Make sure that all data is contiguous.

Returns
-------
DataFrame
r-   zpyarrow.ipcr.   z?is required when using 'read_ipc_stream(..., use_pyarrow=True)'r/   r2   Nr   r$   r%   r    r#   r)   )
r   r	   RecordBatchStreamReaderread_allrA   r   rB   rC   rD   _read_ipc_stream_impl)rF   r$   r%   r&   r(   r    r#   r)   rL   pyarrow_ipcreaderrN   rK   s                rO   read_ipc_streamra      s    l 

	)\K
 44T:foo'\\--c-C!-**>LB%!V,B ;:
 
$ %)-
%
 
 ;:
 
s)   $CAB1	CC1
B?	;C
Cr[   c          
         [        U [        [        45      (       a
  [        U SS9n [        U[        5      (       a  U/n[	        U5      u  pa[
        R                  " U UUU[        X45      U5      n[        U5      $ )NFrR   )	r4   r5   r   r   r   r   ra   r   r   )rF   r$   r%   r    r#   r)   rW   rX   s           rO   r^   r^   ;  su     &3+&&#FF'3)+G4J&&^>D 4=rY   c                b    [        U [        [        45      (       a
  [        U SS9n [	        U 5      $ )a  
Get the schema of an IPC file without reading data.

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.

Returns
-------
dict
    Dictionary mapping column names to datatypes
FrR   )r4   r5   r   r   _read_ipc_schema)rF   s    rO   r   r   U  s,    " &3+&&#FFF##rY   auto   )r%   cacher)   r    r#   r(   credential_providerr'   retriesfile_cache_ttlhive_partitioninghive_schematry_parse_hive_datesinclude_file_pathsc                  / n[        U [        [        45      (       a  [        U SS9n OD[        U [        5      (       a/  [        U 5      (       a  U  V s/ s H  n [        U SS9PM     nn OU nSn Un[        XpUS5      nAU(       a  [	        UR                  5       5      nOSn[        R                  " U UUUU[        XE5      UUU	U
UUUUS9n[        U5      $ s  sn f )a  
Lazily read from an Arrow IPC (Feather v2) file or multiple files via glob patterns.

This allows the query optimizer to push down predicates and projections to the scan
level, thereby potentially reducing memory overhead.

.. versionchanged:: 0.20.4
    * The `row_count_name` parameter was renamed `row_index_name`.
    * The `row_count_offset` parameter was renamed `row_index_offset`.

Parameters
----------
source
    Path(s) to a file or directory
    When needing to authenticate for scanning cloud locations, see the
    `storage_options` parameter.
n_rows
    Stop reading from IPC file after reading `n_rows`.
cache
    Cache the result after reading.
rechunk
    Reallocate to contiguous memory when all chunks/ files are parsed.
row_index_name
    If not None, this will insert a row index column with give name into the
    DataFrame
row_index_offset
    Offset to start the row index column (only use if the name is set)
storage_options
    Options that indicate how to connect to a cloud provider.

    The cloud providers currently supported are AWS, GCP, and Azure.
    See supported keys here:

    * `aws <https://docs.rs/object_store/latest/object_store/aws/enum.AmazonS3ConfigKey.html>`_
    * `gcp <https://docs.rs/object_store/latest/object_store/gcp/enum.GoogleConfigKey.html>`_
    * `azure <https://docs.rs/object_store/latest/object_store/azure/enum.AzureConfigKey.html>`_
    * Hugging Face (`hf://`): Accepts an API key under the `token` parameter:           `{'token': '...'}`, or by setting the `HF_TOKEN` environment variable.

    If `storage_options` is not provided, Polars will try to infer the information
    from environment variables.
credential_provider
    Provide a function that can be called to provide cloud storage
    credentials. The function is expected to return a dictionary of
    credential keys along with an optional credential expiry time.

    .. warning::
        This functionality is considered **unstable**. It may be changed
        at any point without it being considered a breaking change.

memory_map
    Try to memory map the file. This can greatly improve performance on repeated
    queries as the OS may cache pages.
    Only uncompressed IPC files can be memory mapped.
retries
    Number of retries if accessing a cloud instance fails.
file_cache_ttl
    Amount of time to keep downloaded cloud files since their last access time,
    in seconds. Uses the `POLARS_FILE_CACHE_TTL` environment variable
    (which defaults to 1 hour) if not given.
hive_partitioning
    Infer statistics and schema from Hive partitioned URL and use them
    to prune reads. This is unset by default (i.e. `None`), meaning it is
    automatically enabled when a single directory is passed, and otherwise
    disabled.
hive_schema
    The column names and data types of the columns by which the data is partitioned.
    If set to `None` (default), the schema of the Hive partitions is inferred.

    .. warning::
        This functionality is considered **unstable**. It may be changed
        at any point without it being considered a breaking change.
try_parse_hive_dates
    Whether to try parsing hive values as date/datetime types.
include_file_paths
    Include the path of the source file(s) as a column with this name.
FrR   Nscan_parquet)cloud_optionsrh   ri   rj   rk   rl   rm   rn   )r4   r5   r   r   listr   r   itemsr   new_from_ipcr   r   )rF   r%   rg   r)   r    r#   r(   rh   r'   ri   rj   rk   rl   rm   rn   sources_credential_provider_builderpylfs                      rO   r:   r:   l  s   T GIG&3+&&#FF	FD	!	!"6** %$F #6uE$  G
 G 	A"C_n# 	4467 ##^>%7%+1-D  D>Os   C)rF   str | Path | IO[bytes] | bytesr$   list[int] | list[str] | Noner%   
int | Noner&   boolr'   r|   r(   dict[str, Any] | Noner    
str | Noner#   r;   r)   r|   returnr   )rF   ry   r$   $Sequence[int] | Sequence[str] | Noner%   r{   r    r~   r#   r;   r)   r|   r'   r|   r   r   )rF   ry   r$   rz   r%   r{   r&   r|   r(   r}   r    r~   r#   r;   r)   r|   r   r   )rF   ry   r$   r   r%   r{   r    r~   r#   r;   r)   r|   r   r   )rF   ry   r   zdict[str, DataType]) rF   zWstr | Path | IO[bytes] | bytes | list[str] | list[Path] | list[IO[bytes]] | list[bytes]r%   r{   rg   r|   r)   r|   r    r~   r#   r;   r(   r}   rh   z3CredentialProviderFunction | Literal['auto'] | Noner'   r|   ri   r;   rj   r{   rk   zbool | Nonerl   zSchemaDict | Nonerm   r|   rn   r~   r   r   ):
__future__r   
contextlibr7   pathlibr   typingr   r   r   r   polars._reexport	_reexportrA   polars.functions	functionsr=   polars._dependenciesr	   polars._utils.deprecationr
   polars._utils.variousr   r   r   polars._utils.wrapr   r   polars.io._utilsr   r   r   r   r   ,polars.io.cloud.credential_provider._builderr   suppressImportErrorpolars._plrr   r   r   rd   collections.abcr   polarsr   r   r   polars._typingr   polars.io.cloudr   rP   rE   ra   r^   r:    rY   rO   <module>r      s   "  	  2 2   0 A 
 1  %4? & (55): -/?R/1CXV -1-1!%L
*L
 *L
 	L

 L
 L
 +L
 L
 L
 L
 L
 W SL
d 59!%,*, 2, 	,
 , , , , ,^ -/?R/1CXV -1-1!%M
*M
 *M
 	M

 M
 +M
 M
 M
 M
 M
 W SM
f 59!%* 2 	
    4$. -/?R/1CXV !%-1OU!%%)%)!%%)3T	T T T T T  !T" +#T$ M%T& 'T( )T* +T, #-T. #/T0 1T2 #3T4 5T W STc
 &%s   1F""
F1