
    q-PhH                       d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZmZ d dlmZ d d	lmZmZmZm Z m!Z! d d
l"m#Z#  ej$        e%          5  d dl&m'Z'm(Z( d dl&m)Z* ddd           n# 1 swxY w Y   erd dl+m,Z, d dl-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4  eddd           eddd          ddddddd dddEd*                        Z5dddd ddd+dFd-Z6 eddd           eddd          dddddd dd.dGd/                        Z7dddd dd0dHd1Z8dId3Z) eddd           eddd          ddddd dd4dd5dddddd6dJdD                        Z9dS )K    )annotationsN)Path)IOTYPE_CHECKINGAnyLiteral)deprecate_renamed_parameter)is_path_or_str_sequenceis_str_sequencenormalize_filepath)wrap_dfwrap_ldf)import_optional)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#   rechunksourcestr | Path | IO[bytes] | bytesr$   list[int] | list[str] | Noner%   
int | Noner&   boolr'   r(   dict[str, Any] | None
str | Noneintr)   returnr   c          
        t          | x}	t          t          f          rt          |	                              d          x}
st	          j        d          dk    r|
r|rd}t          |          t          | |||||          }|rXt          |d         t                    r(|	                    t          j        |                    }n|	                    |          }|                                }|S |r|r|sd}t          |          t          | ||          5 }|rt          d	d
d          }|                    |||          }t           j                            ||          }||                    ||          }||                    d|          }|cddd           S t+          |||||||          cddd           S # 1 swxY w Y   dS )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_ipcr1   selectFnthcollectr   r   
read_tableplr   _from_arrowwith_row_indexslice_read_ipc_impl)r*   r$   r%   r&   r'   r(   r    r#   r)   vis_hfmsglfdfdatapyarrow_feathertbls                    W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/io/ipc/functions.pyread_ipcrW   )   s   X 	;1d,,!
 a&&##G,,	,! 9)**c11  	"[ 	"HCS//!+)-
 
 
  	('!*c** (YYquW~~..YYw''ZZ\\	 v j Voo	K
 
 
 
	 	-!U  O
 ",,% -  C
 ))#w)??B)&&~7GHH!XXa(('
 
 
 
 
 
 
 
* )-!
 
 
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   A?G*GGGr<   $Sequence[int] | Sequence[str] | Nonec          
     r   t          | t          t          f          rt          | d          } t          |t                    r|g}t          | t                    rt	          |           rt          |           rwt          | ||||          }||                                }nJt          |d          r(|	                    |                                          }nd}	t          |	          |S t          |          \  }
}t          j        | ||
|t          ||          |          }t          |          S )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'   )r=   r>   r   r   r   r   rC   rG   r   rD   	TypeErrorr   r   rW   r   r   )r*   r$   r%   r    r#   r)   r'   scanrR   rP   
projectionpydfs               rV   rM   rM      sT    &3+&& G#FFFF'3 )&# ?6#:#: }V?T?T )-
 
 
 ?BBW666 	!W%%--//BB-  C.. 	+G44J^-=>>  D 4==    )r$   r%   r&   r(   r    r#   r)   c          	        t          | ||          5 }|rt          ddd          }	|	                    |          5 }
|
                                }t          j                            ||          }||                    ||          }||                    d|          }|cddd           cddd           S # 1 swxY w Y   t          ||||||	          cddd           S # 1 swxY w Y   dS )
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
    r6   zpyarrow.ipcr7   z?is required when using 'read_ipc_stream(..., use_pyarrow=True)'r8   r;   Nr   r$   r%   r    r#   r)   )
r   r   RecordBatchStreamReaderread_allrI   r   rJ   rK   rL   _read_ipc_stream_impl)r*   r$   r%   r&   r(   r    r#   r)   rS   pyarrow_ipcreaderrU   rR   s                rV   read_ipc_streamri      s   l 
K
 
 
 
	 	)\  K
 44T:: foo''\--c7-CC!-**>;KLLB%!V,,B      
 
 
 
 
 
 
 
        %)-
 
 
%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s5   *C)A'B=$C)=C	C)C	C))C-0C-rc   c          
        t          | t          t          f          rt          | d          } t          |t                    r|g}t	          |          \  }}t          j        | |||t          ||          |          }t          |          S )NFrZ   )	r=   r>   r   r   r   r   ri   r   r   )r*   r$   r%   r    r#   r)   r_   r`   s           rV   rf   rf   ;  s     &3+&& G#FFFF'3 )+G44J&^-=>> D 4==ra   dict[str, DataType]c                z    t          | t          t          f          rt          | d          } t	          |           S )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
    FrZ   )r=   r>   r   r   _read_ipc_schema)r*   s    rV   r   r   U  s;    " &3+&& G#FFFFF###ra   auto   )r%   cacher)   r    r#   r(   credential_providerr'   retriesfile_cache_ttlhive_partitioninghive_schematry_parse_hive_datesinclude_file_pathsWstr | Path | IO[bytes] | bytes | list[str] | list[Path] | list[IO[bytes]] | list[bytes]rp   rq   3CredentialProviderFunction | Literal['auto'] | Nonerr   rs   rt   bool | Noneru   SchemaDict | Nonerv   rw   r   c                  g }t          | t          t          f          rt          | d          } n5t          | t                    r t          |           rd | D             }n| }d} |}t          || |d          }~|r"t	          |                                          }nd}t          j	        | ||||t          ||          |||	|
||||          }t          |          S )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.
    FrZ   c                0    g | ]}t          |d           S )FrZ   )r   ).0r*   s     rV   
<listcomp>zscan_ipc.<locals>.<listcomp>  s5        #6uEEE  ra   Nscan_parquet)cloud_optionsrq   rr   rs   rt   ru   rv   rw   )r=   r>   r   r   listr
   r   itemsr   new_from_ipcr   r   )r*   r%   rp   r)   r    r#   r(   rq   r'   rr   rs   rt   ru   rv   rw   sources_credential_provider_builderpylfs                      rV   rC   rC   l  s-   T GIG&3+&& #FFFF	FD	!	! 	"6** 	 $  GG
 G 	A"CV_n# # 	 446677 #^-=>>%7%+1-  D  D>>ra   )r*   r+   r$   r,   r%   r-   r&   r.   r'   r.   r(   r/   r    r0   r#   r1   r)   r.   r2   r   )r*   r+   r$   rX   r%   r-   r    r0   r#   r1   r)   r.   r'   r.   r2   r   )r*   r+   r$   r,   r%   r-   r&   r.   r(   r/   r    r0   r#   r1   r)   r.   r2   r   )r*   r+   r$   rX   r%   r-   r    r0   r#   r1   r)   r.   r2   r   )r*   r+   r2   rk   ) r*   rx   r%   r-   rp   r.   r)   r.   r    r0   r#   r1   r(   r/   rq   ry   r'   r.   rr   r1   rs   r-   rt   rz   ru   r{   rv   r.   rw   r0   r2   r   ):
__future__r   
contextlibr@   pathlibr   typingr   r   r   r   polars._reexport	_reexportrI   polars.functions	functionsrE   polars._utils.deprecationr	   polars._utils.variousr
   r   r   polars._utils.wrapr   r   polars.dependenciesr   polars.io._utilsr   r   r   r   r   ,polars.io.cloud.credential_provider._builderr   suppressImportErrorpolars.polarsr   r   r   rm   collections.abcr   polarsr   r   r   polars._typingr   polars.io.cloudr   rW   rM   ri   rf   rC    ra   rV   <module>r      sp   " " " " " "     				       2 2 2 2 2 2 2 2 2 2 2 2             A A A A A A         
 1 0 0 0 0 0 0 0 / / / / / /                   Z%% B B66666666AAAAAAB B B B B B B B B B B B B B B  ;((((((5555555555)))))):::::: -/?RRR/1CXVVV -1-1!%L
 L
 L
 L
 L
 WV SRL
d 59!%, , , , , ,^ -/?RRR/1CXVVV -1-1!%M
 M
 M
 M
 M
 WV SRM
f 59!%     4$ $ $ $. -/?RRR/1CXVVV !%-1OU!%%)%)!%%)3T T T T T WV SRT T Ts   /B

BB