
    q-Ph                        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 d dl	m
Z d dlmZ erd dlmZ d dlmZ d dlmZmZmZ d dlmZ  e            d	d
dd            Z e            dd
dd            ZdS )    )annotationsN)Iterator)TYPE_CHECKINGCallable)unstable)r   )	DataFrameExpr	LazyFrame)
SchemaDictF)validate_schema	io_sourceVCallable[[list[str] | None, Expr | None, int | None, int | None], Iterator[DataFrame]]schema%Callable[[], SchemaDict] | SchemaDictr   boolreturnr
   c               V     d fd
}t           j                            ||d|          S )a  
    Register your IO plugin and initialize a LazyFrame.

    See the `user guide <https://docs.pola.rs/user-guide/plugins/io_plugins>`_
    for more information about plugins.

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


    Parameters
    ----------
    io_source
        Function that accepts the following arguments:
            with_columns
                Columns that are projected. The reader must
                project these columns if applied
            predicate
                Polars expression. The reader must filter
                their rows accordingly.
            n_rows
                Materialize only n rows from the source.
                The reader can stop when `n_rows` are read.
            batch_size
                A hint of the ideal batch size the reader's
                generator must produce.

        The function should return a an iterator/generator
        that produces DataFrames.
    schema
        Schema or function that when called produces the schema that the reader
        will produce before projection pushdown.
    validate_schema
        Whether the engine should validate if the batches generated match
        the given schema. It's an implementation error if this isn't
        the case and can lead to bugs that are hard to solve.

    Returns
    -------
    LazyFrame
    with_columnslist[str] | None	predicatebytes | Nonen_rows
int | None
batch_sizer    tuple[Iterator[DataFrame], bool]c                   d}d }|rw	 t           j                            |          }nV# t          $ rI}t          j                            d          rt          d| t          j	                   d}Y d }~nd }~ww xY w | |||          |fS )NTPOLARS_VERBOSEzMfailed parsing IO plugin expression

filter will be handled on Polars' side: )fileF)
plr	   deserialize	Exceptionosenvirongetprintsysstderr)r   r   r   r   parsed_predicate_successparsed_predicateer   s          Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/io/plugins.pywrapz register_io_source.<locals>.wrapG   s     $(  		11#%7#6#6y#A#A   1 1 1:>>"233 mjkmm Z    ,1((((((1 y*FJ
 
#$ 	$s   ) 
A<?A77A<F)r   scan_fnpyarrowr   )
r   r   r   r   r   r   r   r   r   r   )r   r
   _scan_python_function)r   r   r   r,   s   `   r+   register_io_sourcer0      sL    h$ $ $ $ $ $. <--tUO .       TfunctionCallable[[], DataFrame]%SchemaDict | Callable[[], SchemaDict]c               4     d fd
}t          |||          S )u  
    Deferred execution.

    Takes a function that produces a `DataFrame` but defers execution until the
    `LazyFrame` is collected.

    Parameters
    ----------
    function
        Function that takes no arguments and produces a `DataFrame`.
    schema
        Schema of the `DataFrame` the deferred function will return.
        The caller must ensure this schema is correct.
    validate_schema
        Whether the engine should validate if the batches generated match
        the given schema. It's an implementation error if this isn't
        the case and can lead to bugs that are hard to solve.

    Examples
    --------
    Delay DataFrame execution until query is executed.

    >>> import numpy as np
    >>> np.random.seed(0)
    >>> lf = pl.defer(
    ...     lambda: pl.DataFrame({"a": np.random.randn(3)}), schema={"a": pl.Float64}
    ... )
    >>> lf.collect()
    shape: (3, 1)
    ┌──────────┐
    │ a        │
    │ ---      │
    │ f64      │
    ╞══════════╡
    │ 1.764052 │
    │ 0.400157 │
    │ 0.978738 │
    └──────────┘

     Run an eager source in Polars Cloud

    >>> (
    ...     pl.defer(
    ...         lambda: pl.read_database("select * from tbl"),
    ...         schema={"a": pl.Float64, "b": pl.Boolean},
    ...     )
    ...     .filter("b")
    ...     .sum("a")
    ...     .remote()
    ...     .collect()
    ... )  # doctest: +SKIP


    r   r   r   Expr | Noner   r   r   r   Iterator[DataFrame]c              3     K                                                 }| |                    |           }||                    |          }||                    |          }|                                V  d S )N)lazyselectfilterlimitcollect)r   r   r   r   lfr2   s        r+   sourcez_defer.<locals>.source   s}       XZZ__#<((B 9%%B&!!Bjjllr1   )r   r   r   )
r   r   r   r6   r   r   r   r   r   r7   )r0   )r2   r   r   r?   s   `   r+   _deferr@   c   sB    |         r1   )r   r   r   r   r   r   r   r
   )r2   r3   r   r4   r   r   r   r
   )
__future__r   r"   r&   collections.abcr   typingr   r   polars._reexport	_reexportr   polars._utils.unstabler   polarsr   r	   r
   polars._typingr   r0   r@    r1   r+   <module>rJ      sV   " " " " " " 				 



 $ $ $ $ $ $ * * * * * * * *       + + + + + + *((((((1111111111)))))) 
 "L L L L L L^ 

 !	N N N N N N N Nr1   