
    j9                        d dl mZ d dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ er6d dlZd d	lmZ d d
lmZ d dlmZ d dlmZmZ ej        dk    rd dlm
Z
 nd dlm
Z
  G d d          Z dS )    )annotations)TYPE_CHECKINGLiteraloverloadN)
deprecated)serialize_polars_object)display_dot_graph	wrap_expr)ComputeError)IOBase)Path)Expr)
SchemaDictSerializationFormat)      c                  2   e Zd ZdZdZdUdZdVd	ZdVd
ZdWdZdXdZ	dXdZ
dXdZdXdZdYdZdYdZdYdZdddZdZdddZdZeddd[d             Zed\d#            Zddd]d$Zd%d&d^d*Zd_d,Zd`d-Zd`d.Zdad0Ze	 dbd1d2dcd7            Zedbddd9            Zed1d2ded<            Z	 dfd=d2dgd@ZedbdhdA            ZedidB            Z edC          dfdjdD            Zed1d%dEdkdH            Zed%d&dldI            Zdd%dEdmdJZdd%ddKd%dLdndSZdodTZd%S )pExprMetaNameSpacez*Namespace for expressions on a meta level.metaexprr   returnNonec                    |j         | _         d S N)_pyexprselfr   s     U/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/polars/expr/meta.py__init__zExprMetaNameSpace.__init__   s    |    strc                T    t          | j                                                   dS Nz.meta)r   r   __str__r   s    r   r%   zExprMetaNameSpace.__str__"   s'    DL))1133::::r!   c                T    t          | j                                                   dS r$   )r   r   __repr__r&   s    r   r(   zExprMetaNameSpace.__repr__%   s'    DL))2244;;;;r!   intc                4    | j                                         S r   )r   __hash__r&   s    r   r+   zExprMetaNameSpace.__hash__(   s    |$$&&&r!   otherExprMetaNameSpace | Exprboolc                @    | j                             |j                   S r   r   meta_eqr   r,   s     r   __eq__zExprMetaNameSpace.__eq__+   s    |##EM222r!   c                    | |k     S r    r2   s     r   __ne__zExprMetaNameSpace.__ne__.   s    5=  r!   c                @    | j                             |j                   S )aX  
        Indicate if this expression is the same as another expression.

        Examples
        --------
        >>> foo_bar = pl.col("foo").alias("bar")
        >>> foo = pl.col("foo")
        >>> foo_bar.meta.eq(foo)
        False
        >>> foo_bar2 = pl.col("foo").alias("bar")
        >>> foo_bar.meta.eq(foo_bar2)
        True
        r0   r2   s     r   eqzExprMetaNameSpace.eq1   s     |##EM222r!   c                .    |                      |           S )a\  
        Indicate if this expression is NOT the same as another expression.

        Examples
        --------
        >>> foo_bar = pl.col("foo").alias("bar")
        >>> foo = pl.col("foo")
        >>> foo_bar.meta.ne(foo)
        True
        >>> foo_bar2 = pl.col("foo").alias("bar")
        >>> foo_bar.meta.ne(foo_bar2)
        False
        )r8   r2   s     r   nezExprMetaNameSpace.neA   s     775>>!!r!   c                4    | j                                         S )z
        Indicate if this expression expands into multiple expressions.

        Examples
        --------
        >>> e = pl.col(["a", "b"]).name.suffix("_foo")
        >>> e.meta.has_multiple_outputs()
        True
        )r   meta_has_multiple_outputsr&   s    r   has_multiple_outputsz&ExprMetaNameSpace.has_multiple_outputsQ   s     |55777r!   c                4    | j                                         S )aq  
        Indicate if this expression is a basic (non-regex) unaliased column.

        Examples
        --------
        >>> e = pl.col("foo")
        >>> e.meta.is_column()
        True
        >>> e = pl.col("foo") * pl.col("bar")
        >>> e.meta.is_column()
        False
        >>> e = pl.col(r"^col.*\d+$")
        >>> e.meta.is_column()
        False
        )r   meta_is_columnr&   s    r   	is_columnzExprMetaNameSpace.is_column]   s      |**,,,r!   c                4    | j                                         S )z
        Indicate if this expression expands to columns that match a regex pattern.

        Examples
        --------
        >>> e = pl.col("^.*$").name.prefix("foo_")
        >>> e.meta.is_regex_projection()
        True
        )r   meta_is_regex_projectionr&   s    r   is_regex_projectionz%ExprMetaNameSpace.is_regex_projectiono   s     |44666r!   F)allow_aliasingrD   c               6    | j                             |          S )az  
        Indicate if this expression only selects columns (optionally with aliasing).

        This can include bare columns, columns matched by regex or dtype, selectors
        and exclude ops, and (optionally) column/expression aliasing.

        .. versionadded:: 0.20.30

        Parameters
        ----------
        allow_aliasing
            If False (default), any aliasing is not considered to be column selection.
            Set True to allow for column selection that also includes aliasing.

        Examples
        --------
        >>> import polars.selectors as cs
        >>> e = pl.col("foo")
        >>> e.meta.is_column_selection()
        True
        >>> e = pl.col("foo").alias("bar")
        >>> e.meta.is_column_selection()
        False
        >>> e.meta.is_column_selection(allow_aliasing=True)
        True
        >>> e = pl.col("foo") * pl.col("bar")
        >>> e.meta.is_column_selection()
        False
        >>> e = cs.starts_with("foo")
        >>> e.meta.is_column_selection()
        True
        >>> e = cs.starts_with("foo").exclude("foo!")
        >>> e.meta.is_column_selection()
        True
        )r   meta_is_column_selectionr   rD   s     r   is_column_selectionz%ExprMetaNameSpace.is_column_selection{   s    H |44^DDDr!   c               6    | j                             |          S )a  
        Indicate if this expression is a literal value (optionally aliased).

        .. versionadded:: 1.14

        Parameters
        ----------
        allow_aliasing
            If False (default), only a bare literal will match.
            Set True to also allow for aliased literals.

        Examples
        --------
        >>> from datetime import datetime
        >>> e = pl.lit(123)
        >>> e.meta.is_literal()
        True
        >>> e = pl.lit(987.654321).alias("foo")
        >>> e.meta.is_literal()
        False
        >>> e = pl.lit(datetime.now()).alias("bar")
        >>> e.meta.is_literal(allow_aliasing=True)
        True
        )r   meta_is_literalrG   s     r   
is_literalzExprMetaNameSpace.is_literal   s    2 |++N;;;r!   T)raise_if_undeterminedrL   Literal[True]c                   d S r   r5   r   rL   s     r   output_namezExprMetaNameSpace.output_name   s    RURUr!   Literal[False]
str | Nonec                   d S r   r5   rO   s     r   rP   zExprMetaNameSpace.output_name   s    SVSVr!   c               ^    	 | j                                         S # t          $ r |sY dS  w xY w)aa  
        Get the column name that this expression would produce.

        It may not always be possible to determine the output name as that can depend
        on the schema of the context; in that case this will raise `ComputeError` if
        `raise_if_undetermined` is True (the default), or `None` otherwise.

        Examples
        --------
        >>> e = pl.col("foo") * pl.col("bar")
        >>> e.meta.output_name()
        'foo'
        >>> e_filter = pl.col("foo").filter(pl.col("bar") == 13)
        >>> e_filter.meta.output_name()
        'foo'
        >>> e_sum_over = pl.sum("foo").over("groups")
        >>> e_sum_over.meta.output_name()
        'foo'
        >>> e_sum_slice = pl.sum("foo").slice(pl.len() - 10, pl.col("bar"))
        >>> e_sum_slice.meta.output_name()
        'foo'
        >>> pl.len().meta.output_name()
        'len'
        N)r   meta_output_namer   rO   s     r   rP   zExprMetaNameSpace.output_name   sH    2	<00222 	 	 	( tt	s    ,,N)schemarV   SchemaDict | None
list[Expr]c               J    d | j                             |          D             S )a<  
        Pop the latest expression and return the input(s) of the popped expression.

        Returns
        -------
        list of Expr
            A list of expressions which in most cases will have a unit length.
            This is not the case when an expression has multiple inputs.
            For instance in a `fold` expression.

        Examples
        --------
        >>> e = pl.col("foo") + pl.col("bar")
        >>> first = e.meta.pop()[0]
        >>> first.meta == pl.col("bar")
        True
        >>> first.meta == pl.col("foo")
        False
        c                ,    g | ]}t          |          S r5   r
   ).0es     r   
<listcomp>z)ExprMetaNameSpace.pop.<locals>.<listcomp>   s    DDD	!DDDr!   )r   meta_pop)r   rV   s     r   popzExprMetaNameSpace.pop   s)    ( EDdl&;&;F&C&CDDDDr!   	list[str]c                4    | j                                         S )aD  
        Get a list with the root column name.

        Examples
        --------
        >>> e = pl.col("foo") * pl.col("bar")
        >>> e.meta.root_names()
        ['foo', 'bar']
        >>> e_filter = pl.col("foo").filter(pl.col("bar") == 13)
        >>> e_filter.meta.root_names()
        ['foo', 'bar']
        >>> e_sum_over = pl.sum("foo").over("groups")
        >>> e_sum_over.meta.root_names()
        ['foo', 'groups']
        >>> e_sum_slice = pl.sum("foo").slice(pl.len() - 10, pl.col("bar"))
        >>> e_sum_slice.meta.root_names()
        ['foo', 'bar']
        )r   meta_root_namesr&   s    r   
root_nameszExprMetaNameSpace.root_names   s    & |++---r!   c                N    t          | j                                                  S )aR  
        Undo any renaming operation like `alias` or `name.keep`.

        Examples
        --------
        >>> e = pl.col("foo").alias("bar")
        >>> e.meta.undo_aliases().meta == pl.col("foo")
        True
        >>> e = pl.col("foo").sum().over("bar")
        >>> e.name.keep().meta.undo_aliases().meta == e
        True
        )r   r   meta_undo_aliasesr&   s    r   undo_aliaseszExprMetaNameSpace.undo_aliases  s      7799:::r!   c                *    t          | j                  S )zReturn the original expression.)r   r   r&   s    r   as_expressionzExprMetaNameSpace.as_expression  s    &&&r!   pl.Selectorc                n    t           j                            | j                                                  S )a2  
        Try to turn this expression in a selector.

        Raises if the underlying expressions is not a column or selector.

        .. warning::
            This functionality is considered **unstable**. It may be changed
            at any point without it being considered a breaking change.
        )plSelector_from_pyselectorr   into_selectorr&   s    r   as_selectorzExprMetaNameSpace.as_selector   s(     {++DL,F,F,H,HIIIr!   .formatfilerq   Literal['binary']bytesc                   d S r   r5   r   rr   rq   s      r   	serializezExprMetaNameSpace.serialize,  s	     r!   Literal['json']c                   d S r   r5   rv   s      r   rw   zExprMetaNameSpace.serialize1  s    NQcr!   IOBase | str | Pathr   c                   d S r   r5   rv   s      r   rw   zExprMetaNameSpace.serialize4  s	     sr!   binaryIOBase | str | Path | Nonebytes | str | Nonec                   |dk    r| j         j        }n'|dk    r| j         j        }nd|}t          |          t	          |||          S )u  
        Serialize this expression to a file or string in JSON format.

        Parameters
        ----------
        file
            File path to which the result should be written. If set to `None`
            (default), the output is returned as a string instead.
        format
            The format in which to serialize. Options:

            - `"binary"`: Serialize to binary format (bytes). This is the default.
            - `"json"`: Serialize to JSON format (string).

        See Also
        --------
        Expr.deserialize

        Notes
        -----
        Serialization is not stable across Polars versions: a LazyFrame serialized
        in one Polars version may not be deserializable in another Polars version.

        Examples
        --------
        Serialize the expression into a binary representation.

        >>> expr = pl.col("foo").sum().over("bar")
        >>> bytes = expr.meta.serialize()
        >>> type(bytes)
        <class 'bytes'>

        The bytes can later be deserialized back into an `Expr` object.

        >>> import io
        >>> pl.Expr.deserialize(io.BytesIO(bytes))
        <Expr ['col("foo").sum().over([col("ba…'] at ...>
        r|   jsonz0`format` must be one of {'binary', 'json'}, got )r   serialize_binaryserialize_json
ValueErrorr   )r   rr   rq   
serializermsgs        r   rw   zExprMetaNameSpace.serialize9  s^    X X6JJv4JJQvQQCS//!&z4@@@r!   c                    d S r   r5   r   rr   s     r   
write_jsonzExprMetaNameSpace.write_jsono  s    363r!   c                    d S r   r5   r   s     r   r   zExprMetaNameSpace.write_jsonr  s    =@Sr!   z;`meta.write_json` was renamed; use `meta.serialize` insteadc                0    |                      |d          S )z
        Write expression to json.

        .. deprecated:: 0.20.11
            This method has been renamed to :meth:`serialize`.
        r   rp   )rw   r   s     r   r   zExprMetaNameSpace.write_jsonu  s     ~~d6~222r!   )return_as_stringrV   r   None | SchemaDictc                   d S r   r5   r   r   rV   s      r   tree_formatzExprMetaNameSpace.tree_format  s	     sr!   c                   d S r   r5   r   s      r   r   zExprMetaNameSpace.tree_format  s	     cr!   c               `    | j                             |          }|r|S t          |           dS )am  
        Format the expression as a tree.

        Parameters
        ----------
        return_as_string:
            If True, return as string rather than printing to stdout.
        schema
            Optionally provide a schema for the expression tree formatter.
            This is a mapping of column names to their data types. If provided,
            it may be used to enhance the tree formatting with type information.

        Examples
        --------
        >>> e = (pl.col("foo") * pl.col("bar")).sum().over(pl.col("ham")) / 2
        >>> e.meta.tree_format(return_as_string=True)  # doctest: +SKIP
        N)r   meta_tree_formatprint)r   r   rV   ss       r   r   zExprMetaNameSpace.tree_format  s6    ( L))&11 	H!HHH4r!   )g      0@g      (@)showoutput_path
raw_outputfigsizerV   r   r   str | Path | Noner   r   tuple[float, float]c               ^    | j                             |          }t          |||||          S )a  
        Format the expression as a Graphviz graph.

        Note that Graphviz must be installed to render the visualization (if not
        already present, you can download it here: `<https://graphviz.org/download>`_).

        Parameters
        ----------
        show
            Show the figure.
        output_path
            Write the figure to disk.
        raw_output
            Return dot syntax. This cannot be combined with `show` and/or `output_path`.
        figsize
            Passed to matplotlib if `show == True`.
        schema
            Optionally provide a schema for the expression tree formatter.
            This is a mapping of column names to their data types. If provided,
            it may be used to enhance the tree formatting with type information.

        Examples
        --------
        >>> e = (pl.col("foo") * pl.col("bar")).sum().over(pl.col("ham")) / 2
        >>> e.meta.show_graph()  # doctest: +SKIP
        )dotr   r   r   r   )r   meta_show_graphr	   )r   r   r   r   r   rV   r   s          r   
show_graphzExprMetaNameSpace.show_graph  s@    F l**622 #!
 
 
 	
r!   c                Z    t          | j                            |j                            S r   )r   r   meta_replace_elementr   s     r   _replace_elementz"ExprMetaNameSpace._replace_element  s"    ::4<HHIIIr!   )r   r   r   r   )r   r"   )r   r)   )r,   r-   r   r.   )r   r.   )rD   r.   r   r.   )rL   rM   r   r"   )rL   rQ   r   rR   )rL   r.   r   rR   )rV   rW   r   rX   )r   r`   )r   r   )r   ri   ).)rr   r   rq   rs   r   rt   )rr   r   rq   rx   r   r"   )rr   rz   rq   r   r   r   r   )rr   r}   rq   r   r   r~   )rr   r   r   r"   )rr   rz   r   r   )rr   r}   r   rR   )r   rQ   rV   r   r   r   )r   rM   rV   r   r   r"   )r   r.   rV   r   r   rR   )r   r.   r   r   r   r.   r   r   rV   r   r   rR   )r   r   r   r   )__name__
__module____qualname____doc__	_accessorr    r%   r(   r+   r3   r6   r8   r:   r=   r@   rC   rH   rK   r   rP   r_   rc   rf   rh   ro   rw   r   r   r   r   r   r5   r!   r   r   r      s       44I$ $ $ $; ; ; ;< < < <' ' ' '3 3 3 3! ! ! !3 3 3 3 " " " " 
8 
8 
8 
8- - - -$
7 
7 
7 
7 =B $E $E $E $E $E $EL 49 < < < < < <6 DHUUUUU XUVVV XV;?      @ 26 E E E E E E,. . . .*; ; ; ;' ' ' '
J 
J 
J 
J ?B     X QQQQ XQJM     X ,04A '/	4A 4A 4A 4A 4A 4Al 6666 X6@@@ X@ZMNN3 3 3 3 ON3  ,/$(	     X NR     X
 +0T     < )- '3$(*
 *
 *
 *
 *
 *
XJ J J J J Jr!   r   )!
__future__r   typingr   r   r   polars._reexport	_reexportrk   polars._utils.deprecationr   polars._utils.serder   polars._utils.variousr	   polars._utils.wrapr   polars.exceptionsr   sysior   pathlibr   polarsr   polars._typingr   r   version_infowarningstyping_extensionsr   r5   r!   r   <module>r      s{   " " " " " " 3 3 3 3 3 3 3 3 3 3       0 0 0 0 0 0 7 7 7 7 7 7 3 3 3 3 3 3 ( ( ( ( ( ( * * * * * * 1JJJ>>>>>>>>
7""'''''''000000zJ zJ zJ zJ zJ zJ zJ zJ zJ zJr!   