
    y-Ph{'                        d dl Z d dlZd dlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZ d dlmZ  G d dej                  ZdZ G d dej                  Z G d d	ej                  Z G d
 dej                  Zd Zd ZddddZ d!                    e          e _"        ddddZ#ddddZ$d!                    e          e$_"        dddddZ%ddddZ&dddZ'dS )    N)IpcReadOptionsIpcWriteOptions	ReadStats
WriteStatsMessageMessageReaderRecordBatchReader_ReadPandasMixinMetadataVersionread_messageread_record_batchread_schemaread_tensorwrite_tensorget_record_batch_sizeget_tensor_sizec                        e Zd ZdZddddZdS )RecordBatchStreamReadera  
    Reader for the Arrow streaming binary format.

    Parameters
    ----------
    source : bytes/buffer-like, pyarrow.NativeFile, or file-like Python object
        Either an in-memory buffer, or a readable file object.
        If you want to use memory map use MemoryMappedFile as source.
    options : pyarrow.ipc.IpcReadOptions
        Options for IPC deserialization.
        If None, default values will be used.
    memory_pool : MemoryPool, default None
        If None, default memory pool is used.
    Noptionsmemory_poolc                T    t          |          }|                     |||           d S )Nr    _ensure_default_ipc_read_options_open)selfsourcer   r   s       K/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pyarrow/ipc.py__init__z RecordBatchStreamReader.__init__2   s-    27;;

67
DDDDD    __name__
__module____qualname____doc__r    r    r   r   r   "   sE          +/D E E E E E E Er    r   aN  Parameters
----------
sink : str, pyarrow.NativeFile, or file-like Python object
    Either a file path, or a writable file object.
schema : pyarrow.Schema
    The Arrow schema for data to be written to the file.
use_legacy_format : bool, default None
    Deprecated in favor of setting options. Cannot be provided with
    options.

    If None, False will be used unless this default is overridden by
    setting the environment variable ARROW_PRE_0_15_IPC_FORMAT=1
options : pyarrow.ipc.IpcWriteOptions
    Options for IPC serialization.

    If None, default values will be used: the legacy format will not
    be used unless overridden by setting the environment variable
    ARROW_PRE_0_15_IPC_FORMAT=1, and the V5 metadata version will be
    used unless overridden by setting the environment variable
    ARROW_PRE_1_0_METADATA_VERSION=1.c                   F    e Zd Zd                    e          ZddddZdS )RecordBatchStreamWriterz0Writer for the Arrow streaming binary format

{}Nuse_legacy_formatr   c                V    t          ||          }|                     |||           d S Nr   _get_legacy_format_defaultr   r   sinkschemar*   r   s        r   r   z RecordBatchStreamWriter.__init__S   0    ,->HH

4
11111r    r"   r#   r$   format_ipc_writer_class_docr%   r   r&   r    r   r(   r(   N   sL        f"##  ;? 2 2 2 2 2 2 2r    r(   c                   "    e Zd ZdZdddddZdS )RecordBatchFileReadera  
    Class for reading Arrow record batch data from the Arrow binary file format

    Parameters
    ----------
    source : bytes/buffer-like, pyarrow.NativeFile, or file-like Python object
        Either an in-memory buffer, or a readable file object.
        If you want to use memory map use MemoryMappedFile as source.
    footer_offset : int, default None
        If the file is embedded in some larger file, this is the byte offset to
        the very end of the file data
    options : pyarrow.ipc.IpcReadOptions
        Options for IPC serialization.
        If None, default values will be used.
    memory_pool : MemoryPool, default None
        If None, default memory pool is used.
    Nr   c                V    t          |          }|                     ||||           d S )Nfooter_offsetr   r   r   )r   r   r;   r   r   s        r   r   zRecordBatchFileReader.__init__k   s=    27;;

6" 	 	= 	= 	= 	= 	=r    Nr!   r&   r    r   r8   r8   X   sA         $=d!= = = = = = =r    r8   c                   F    e Zd Zd                    e          ZddddZdS )RecordBatchFileWriterz1Writer to create the Arrow binary file format

{}Nr)   c                V    t          ||          }|                     |||           d S r,   r.   r0   s        r   r   zRecordBatchFileWriter.__init__x   r3   r    r4   r&   r    r   r>   r>   r   sL        f"##  ;? 2 2 2 2 2 2 2r    r>   c                    | |t          d          |rFt          |t                    s/t          d                    t          |                              |S t          j        }| :t          t          t          j                            dd                              } t          t          t          j                            dd                              rt          j        }t          | |          S )Nz8Can provide at most one of options and use_legacy_formatz expected IpcWriteOptions, got {}ARROW_PRE_0_15_IPC_FORMAT0ARROW_PRE_1_0_METADATA_VERSION)r*   metadata_version)
ValueError
isinstancer   	TypeErrorr5   typer   V5boolintosenvirongetV4)r*   r   rD   s      r   r/   r/   }   s    $)<FH H 	H	 '?33 	4>#VDMM224 4 4&) RZ^^$?EEFFGG 	C
?EEFFGG .*-->,<> > > >r    c                     | rDt          | t                    s/t          d                    t	          |                               | pt                      S )Nzexpected IpcReadOptions, got {})rF   r   rG   r5   rH   r-   s    r   r   r      sW     
z'>:: 
-44T']]CC
 
 	
 &n&&&r    r)   c                (    t          | |||          S Nr)   )r(   r1   r2   r*   r   s       r   
new_streamrT      s#    "45F+24 4 4 4r    zCreate an Arrow columnar IPC stream writer instance

{}

Returns
-------
writer : RecordBatchStreamWriter
    A writer for the given sink
r   c                &    t          | ||          S )a  
    Create reader for Arrow streaming format.

    Parameters
    ----------
    source : bytes/buffer-like, pyarrow.NativeFile, or file-like Python object
        Either an in-memory buffer, or a readable file object.
    options : pyarrow.ipc.IpcReadOptions
        Options for IPC serialization.
        If None, default values will be used.
    memory_pool : MemoryPool, default None
        If None, default memory pool is used.

    Returns
    -------
    reader : RecordBatchStreamReader
        A reader for the given source
    r   )r   )r   r   r   s      r   open_streamrV      s"    & #67/:< < < <r    c                (    t          | |||          S rR   )r>   rS   s       r   new_filerX      s#     v3D)02 2 2 2r    zCreate an Arrow columnar IPC file writer instance

{}

Returns
-------
writer : RecordBatchFileWriter
    A writer for the given sink
c                (    t          | |||          S )a  
    Create reader for Arrow file format.

    Parameters
    ----------
    source : bytes/buffer-like, pyarrow.NativeFile, or file-like Python object
        Either an in-memory buffer, or a readable file object.
    footer_offset : int, default None
        If the file is embedded in some larger file, this is the byte offset to
        the very end of the file data.
    options : pyarrow.ipc.IpcReadOptions
        Options for IPC serialization.
        If None, default values will be used.
    memory_pool : MemoryPool, default None
        If None, default memory pool is used.

    Returns
    -------
    reader : RecordBatchFileReader
        A reader for the given source
    r:   )r8   )r   r;   r   r   s       r   	open_filerZ      s%    , !m[2 2 2 2r    nthreadspreserve_indexc                "   t           j                            | ||          }t          j                    }t          j        ||j                  5 }|                    |           ddd           n# 1 swxY w Y   |                                S )a  
    Serialize a pandas DataFrame into a buffer protocol compatible object.

    Parameters
    ----------
    df : pandas.DataFrame
    nthreads : int, default None
        Number of threads to use for conversion to Arrow, default all CPUs.
    preserve_index : bool, default None
        The default of None will store the index as a column, except for
        RangeIndex which is stored as metadata only. If True, always
        preserve the pandas index data as a column. If False, no index
        information is saved and the result will have a default RangeIndex.

    Returns
    -------
    buf : buffer
        An object compatible with the buffer protocol.
    r[   N)paRecordBatchfrom_pandasBufferOutputStreamr(   r2   write_batchgetvalue)dfr\   r]   batchr1   writers         r   serialize_pandasrh      s    ( N&&rH6D ' F FE ""D		#D%,	7	7 "65!!!" " " " " " " " " " " " " " "==??s   A22A69A6Tuse_threadsc                    t          j        |           }t          j        |          5 }|                                }ddd           n# 1 swxY w Y   |                    |          S )a  Deserialize a buffer protocol compatible object into a pandas DataFrame.

    Parameters
    ----------
    buf : buffer
        An object compatible with the buffer protocol.
    use_threads : bool, default True
        Whether to parallelize the conversion using multiple threads.

    Returns
    -------
    df : pandas.DataFrame
        The buffer deserialized as pandas DataFrame
    Nri   )r_   BufferReaderr   read_all	to_pandas)bufrj   buffer_readerreadertables        r   deserialize_pandasrs     s     OC((M		#M	2	2 "f!!" " " " " " " " " " " " " " "??{?333s   A

AAr<   )(rL   pyarrowr_   pyarrow.libr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   lib_RecordBatchStreamReaderr   r6   _RecordBatchStreamWriterr(   _RecordBatchFileReaderr8   _RecordBatchFileWriterr>   r/   r   rT   r5   r%   rV   rX   rZ   rh   rs   r&   r    r   <module>r{      s  ( 
			    A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A      E E E E Ec: E E E*) .2 2 2 2 2c: 2 2 2= = = = =C6 = = =42 2 2 2 2C6 2 2 2> > >(' ' ' 37 4 4 4 4 4	 F !!   $(T < < < < <. 15d 2 2 2 2 2	 F !! 	 2Tt 2 2 2 2 26 &*$     8 ,0 4 4 4 4 4 4 4r    