
    g{'                        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j0                        Z G d d	ej4                        Z G d
 dej8                        Zd Zd ZddddZ djC                  e      e _"        ddddZ#ddddZ$djC                  e      e$_"        dddddZ%ddddZ&dddZ'y)    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y)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                B    t        |      }| j                  |||       y )Nr    _ensure_default_ipc_read_options_open)selfsourcer   r   s       @/var/www/openai/venv/lib/python3.12/site-packages/pyarrow/ipc.py__init__z RecordBatchStreamReader.__init__2   s    27;

67
D    __name__
__module____qualname____doc__r    r    r   r   r   "   s     +/D 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                   <    e Zd Zdj                  e      ZddddZy)RecordBatchStreamWriterz0Writer for the Arrow streaming binary format

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

4
1r    r"   r#   r$   format_ipc_writer_class_docr%   r   r&   r    r   r(   r(   N   s#    f"#  ;? 2r    r(   c                        e Zd ZdZdddddZy)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                D    t        |      }| j                  ||||       y )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   s    $=d!=r    r8   c                   <    e Zd Zdj                  e      ZddddZy)RecordBatchFileWriterz1Writer to create the Arrow binary file format

{}Nr)   c                D    t        ||      }| j                  |||       y r,   r.   r0   s        r   r   zRecordBatchFileWriter.__init__x   r3   r    r4   r&   r    r   r>   r>   r   s#    f"#  ;? 2r    r>   c                    | |t        d      |r5t        |t              s#t        dj	                  t        |                  |S t        j                  }| 2t        t        t        j                  j                  dd                  } t        t        t        j                  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	'?3>#VDM24 4&)) RZZ^^$?EFG 	C

?EFG*--->,<> >r    c                     | r3t        | t              s#t        dj                  t	        |                   | xs
 t               S )Nzexpected IpcReadOptions, got {})rF   r   rG   r5   rH   r-   s    r   r   r      s=    z'>:-44T']C
 	
 &n&&r    r)   c                     t        | |||      S Nr)   )r(   r1   r2   r*   r   s       r   
new_streamrT      s    "45F+2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 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 2r    nthreadspreserve_indexc                8   t         j                  j                  | ||      }t        j                         }t        j                  ||j
                        5 }|j                  |       ddd       |j                         S # 1 sw Y   |j                         S xY w)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      sz    ( NN&&rH6D ' FE  "D		#	#D%,,	765! 
8==? 
8==?s   BBTuse_threadsc                    t        j                  |       }t        j                  |      5 }|j                         }ddd       j	                  |      S # 1 sw Y   xY w)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     sM     OOC(M		#	#M	2f! 
3??{?33 
3	2s   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 Ec:: E*) .2c:: 2=C66 =42C66 2>(' 37 4	 F !   $(T <. 15d 2	 F ! 	 2Tt 26 &*$ 8 ,0 4r    