§
    Ò¬¸jV  ã                  ó¤   — d Z ddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ erddlmZ ddlmZmZ dd	lmZ d
gZ e
¦   «         dd„¦   «         ZdS )z.Functions for scanning Arrow C Stream sources.é    )Úannotations)ÚTYPE_CHECKINGÚAnyN)Úunstable)Úregister_io_source)ÚIterator)Ú	DataFrameÚExpr)Ú	LazyFrameÚscan_arrow_c_streamÚsourcer   Úreturnr   c                ó´   ‡— t          | d¦  «        sd}t          |¦  «        ‚ddlm} |                     | ¦  «        Šdˆfd„}t          |‰j        ¬¦  «        S )u›  
    Scan a source that implements the Arrow PyCapsule Interface.

    This creates a lazy scan over an object that exposes a `__arrow_c_stream__`
    method (e.g. a `pyarrow.RecordBatchReader`, or a `nanoarrow` stream). The
    source is consumed, batch by batch, during query execution.

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

    Parameters
    ----------
    source
        Any object implementing the Arrow PyCapsule Interface
        (i.e. it has a `__arrow_c_stream__` method).

    Returns
    -------
    LazyFrame

    Notes
    -----
    - The source must produce Arrow RecordBatches with a struct-typed schema.
      See: https://arrow.apache.org/docs/format/CStreamInterface.html.
    - Once the stream is consumed, the same source cannot be scanned again.

    Examples
    --------
    Scan from a PyArrow RecordBatchReader:

    >>> import pyarrow as pa
    >>> schema = pa.schema([("a", pa.int64()), ("b", pa.string())])
    >>> batches = [
    ...     pa.record_batch([[1, 2, 3], ["x", "y", "z"]], schema=schema),
    ...     pa.record_batch([[4, 5], ["a", "b"]], schema=schema),
    ... ]
    >>> reader = pa.RecordBatchReader.from_batches(schema, batches)
    >>> pl.scan_arrow_c_stream(reader).collect()
    shape: (5, 2)
    â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”�
    â”‚ a   â”† b   â”‚
    â”‚ --- â”† --- â”‚
    â”‚ i64 â”† str â”‚
    â•žâ•�â•�â•�â•�â•�â•ªâ•�â•�â•�â•�â•�â•¡
    â”‚ 1   â”† x   â”‚
    â”‚ 2   â”† y   â”‚
    â”‚ 3   â”† z   â”‚
    â”‚ 4   â”† a   â”‚
    â”‚ 5   â”† b   â”‚
    â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
    Ú__arrow_c_stream__zHsource must implement the Arrow PyCapsule Interface (__arrow_c_stream__)r   NÚwith_columnsúlist[str] | NoneÚ	predicateúExpr | NoneÚn_rowsú
int | NoneÚ
batch_sizer   úIterator[DataFrame]c              3  ó:  •K  — |}‰                      | ¦  «        x}�~t          j                             |¦  «        }|�|                     |¦  «        }|�|                     |¦  «        }||j        z  }|V — |�|dk    rd S ‰                      | ¦  «        x}­|d S d S )Nr   )Ú
next_batchÚplr	   Ú
_from_pydfÚfilterÚheadÚheight)r   r   r   r   Ú	remainingÚbatchÚdfÚreaders          €úh/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/polars/io/arrow_c_stream.pyÚ	io_sourcez&scan_arrow_c_stream.<locals>.io_sourceR   s¹   øè è € ð ˆ	Ø×)Ò)¨,Ñ7Ô7Ð7ˆuÐDÝ”×(Ò(¨Ñ/Ô/ˆBØÐ$Ø—Y’Y˜yÑ)Ô)�ØÐ$Ø—W’W˜YÑ'Ô'�Ø˜RœYÑ&�	ØˆHˆHˆHØÐ$¨°aª¨Ø�ð ×)Ò)¨,Ñ7Ô7Ð7ˆuÐDÐDÐDÐDÐDó    )r%   Úschema)
r   r   r   r   r   r   r   r   r   r   )ÚhasattrÚ	TypeErrorÚpolars._plrÚ_plrÚPyArrowCStreamReaderr   r'   )r   ÚmsgÚplrr%   r#   s       @r$   r   r      s„   ø€ õl �6Ð/Ñ0Ô0ð ØXˆÝ˜‰nŒnÐàÐÐÐÐÐà×%Ò% fÑ-Ô-€Fðð ð ð ð ð õ$ ¨	¸&¼-ÐHÑHÔHÐHr&   )r   r   r   r   )Ú__doc__Ú
__future__r   Útypingr   r   Úpolars._reexportÚ	_reexportr   Úpolars._utils.unstabler   Úpolars.io.pluginsr   Úcollections.abcr   Úpolarsr	   r
   Úpolars.lazyframer   Ú__all__r   © r&   r$   ú<module>r;      só   ðØ 4Ð 4à "Ð "Ð "Ð "Ð "Ð "à %Ð %Ð %Ð %Ð %Ð %Ð %Ð %à Ð Ð Ð Ð Ð Ø +Ð +Ð +Ð +Ð +Ð +Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0àð +Ø(Ð(Ð(Ð(Ð(Ð(à&Ð&Ð&Ð&Ð&Ð&Ð&Ð&Ø*Ð*Ð*Ð*Ð*Ð*à Ð
!€ð 
€�„ðOIð OIð OIñ „ðOIð OIð OIr&   