o
    i                     @  s   d dl m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 er4d dlmZ d dlmZmZ ddd	d&ddZe	d'dddd(ddZe	d'dd d)d#dZ	d*dddd+d%dZdS ),    )annotations)partial)TYPE_CHECKINGAnyLiteraloverloadNpyarrow)Iterator)	DataFrame	LazyFrameT)allow_pyarrow_filter
batch_sizedspa.dataset.Datasetr   boolr   
int | Nonereturnr   c                C  s:   |rdnd}t t| fd|i||i}tjj| j||dS )a'  
    Pickle the partially applied function `_scan_pyarrow_dataset_impl`.

    The bytes are then sent to the polars logical plan. It can be deserialized once
    executed and ran.

    Parameters
    ----------
    ds
        pyarrow dataset
    allow_pyarrow_filter
        Allow predicates to be pushed down to pyarrow. This can lead to different
        results if comparisons are done with null values as pyarrow handles this
        different than polars does.
    batch_size
        The maximum row count for scanned pyarrow record batches.
    r   user_batch_sizer   r   )r   _scan_pyarrow_dataset_implplr   Z_scan_python_functionZschema)r   r   r   Zbatch_size_keyfunc r   _/home/app/Keep/.python/lib/python3.10/site-packages/polars/io/pyarrow_dataset/anonymous_scan.py_scan_pyarrow_dataset   s   r   .)r   r   with_columnslist[str] | None	predicatestr | bytes | Nonen_rowsLiteral[True]r   r   c                C     d S Nr   r   r   r   r   r   r   r   r   r   r   r   4      
r   )r   Literal[False] tuple[Iterator[DataFrame], bool]c                C  r!   r"   r   r#   r   r   r   r   A   r$   ,DataFrame | tuple[Iterator[DataFrame], bool]c                  s   d}d|r7|dur7ddl m}m}	m}
m} ddlm}m}m} t	|t
|||||	|
|d}du r5|}n|||d |durB|n|}|durL| d< d fd
d}|r^| \}|S | dfS )a  
    Take the projected columns and materialize an arrow table.

    Parameters
    ----------
    ds
        pyarrow dataset.
    with_columns
        Columns that are projected.
    predicate
        pyarrow expression string (when `allow_pyarrow_filter=True`) or
        serialized Polars predicate bytes (when `allow_pyarrow_filter=False`).
    n_rows:
        Materialize only `n` rows from the arrow dataset.
    batch_size
        The maximum row count for scanned pyarrow record batches.
    allow_pyarrow_filter
        If True, evaluate predicate and return DataFrame directly.
        If False, return `(generator, False)` tuple for IOPlugin path.
    user_batch_size
        User-specified `batch_size` (takes precedence over Rust-provided `batch_size`).

    Warnings
    --------
    Don't use this if you accept untrusted user inputs. Predicates will be evaluated
    with python 'eval'. There is sanitation in place, but it is a possible attack
    vector.

    Returns
    -------
    DataFrame or tuple[Iterator[DataFrame], bool]
    Nr   )
to_py_dateto_py_datetime
to_py_timeto_py_timedelta)DateDatetimeDuration)par,   r-   r.   r(   r)   r*   r+   )columnsfilterr   r   Iterator[DataFrame]c                   3  sX    t d ur d urjfi  njfi  njdi  V  d S )Nr   )r   r   headr1   Zto_tabler   Zcommon_paramsr   Zfilter_post_slice_r   r   r   frames   s   
z*_scan_pyarrow_dataset_impl.<locals>.framesF)r   r2   )Zpolars._utils.convertr(   r)   r*   r+   Zpolars.datatypesr,   r-   r.   evalr/   )r   r   r   r   r   r   r   filter_r(   r)   r*   r+   r,   r-   r.   vr5   xr   r4   r   r   N   s:   *

)r   r   r   r   r   r   r   r   ).)r   r   r   r   r   r   r   r   r   r   r   r    r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r%   r   r   r   r&   r"   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r'   )
__future__r   	functoolsr   typingr   r   r   r   Zpolars._reexportZ	_reexportr   Zpolars._dependenciesr	   r/   collections.abcr
   Zpolarsr   r   r   r   r   r   r   r   <module>   s6    %