Λ
    ±.σh6(  γ                  σP    d dl mZ d dlmZmZ d dlmZ erd dlmZ  G d d«      Z	y)ι    )Ϊannotations)ΪTYPE_CHECKINGΪCallable)Ϊ	wrap_expr)ΪExprc                  σd    e Zd ZdZdZddZddZddZddZddZ	ddZ
dd	Zdd
ZddZddZy)ΪExprNameNameSpacez;Namespace for expressions that operate on expression names.Ϊnamec                σ&    |j                   | _         y )N)Ϊ_pyexpr)ΪselfΪexprs     ϊN/var/www/html/ai-service/venv/lib/python3.12/site-packages/polars/expr/name.pyΪ__init__zExprNameNameSpace.__init__   s    Ψ||σ    c                σH    t        | j                  j                  «       «      S )uΥ  
        Keep the original root name of the expression.

        See Also
        --------
        Expr.alias
        map

        Examples
        --------
        Prevent errors due to potential duplicate column names.

        >>> df = pl.DataFrame(
        ...     {
        ...         "a": [1, 2],
        ...         "b": [3, 4],
        ...     }
        ... )
        >>> df.select((pl.lit(10) / pl.all()).name.keep())
        shape: (2, 2)
        ββββββββ¬βββββββββββ
        β a    β b        β
        β ---  β ---      β
        β f64  β f64      β
        ββββββββͺβββββββββββ‘
        β 10.0 β 3.333333 β
        β 5.0  β 2.5      β
        ββββββββ΄βββββββββββ

        Undo an alias operation.

        >>> df.with_columns((pl.col("a") * 9).alias("c").name.keep())
        shape: (2, 2)
        βββββββ¬ββββββ
        β a   β b   β
        β --- β --- β
        β i64 β i64 β
        βββββββͺββββββ‘
        β 9   β 3   β
        β 18  β 4   β
        βββββββ΄ββββββ
        )r   r   Ϊ	name_keep©r   s    r   ΪkeepzExprNameNameSpace.keep   s    τV Χ/Ρ/Σ1Σ2Π2r   c                σJ    t        | j                  j                  |«      «      S )u   
        Rename the output of an expression by mapping a function over the root name.

        Parameters
        ----------
        function
            Function that maps a root name to a new name.

        See Also
        --------
        keep
        prefix
        suffix

        Examples
        --------
        Remove a common suffix and convert to lower case.

        >>> df = pl.DataFrame(
        ...     {
        ...         "A_reverse": [3, 2, 1],
        ...         "B_reverse": ["z", "y", "x"],
        ...     }
        ... )
        >>> df.with_columns(
        ...     pl.all()
        ...     .reverse()
        ...     .name.map(lambda c: c.removesuffix("_reverse").lower())
        ... )
        shape: (3, 4)
        βββββββββββββ¬ββββββββββββ¬ββββββ¬ββββββ
        β A_reverse β B_reverse β a   β b   β
        β ---       β ---       β --- β --- β
        β i64       β str       β i64 β str β
        βββββββββββββͺββββββββββββͺββββββͺββββββ‘
        β 3         β z         β 1   β x   β
        β 2         β y         β 2   β y   β
        β 1         β x         β 3   β z   β
        βββββββββββββ΄ββββββββββββ΄ββββββ΄ββββββ
        )r   r   Ϊname_map©r   Ϊfunctions     r   ΪmapzExprNameNameSpace.map@   s    τR Χ.Ρ.¨xΣ8Σ9Π9r   c                σJ    t        | j                  j                  |«      «      S )uΘ  
        Add a prefix to the root column name of the expression.

        Parameters
        ----------
        prefix
            Prefix to add to the root column name.

        See Also
        --------
        suffix
        map

        Examples
        --------
        >>> df = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 3],
        ...         "b": ["x", "y", "z"],
        ...     }
        ... )
        >>> df.with_columns(pl.all().reverse().name.prefix("reverse_"))
        shape: (3, 4)
        βββββββ¬ββββββ¬ββββββββββββ¬ββββββββββββ
        β a   β b   β reverse_a β reverse_b β
        β --- β --- β ---       β ---       β
        β i64 β str β i64       β str       β
        βββββββͺββββββͺββββββββββββͺββββββββββββ‘
        β 1   β x   β 3         β z         β
        β 2   β y   β 2         β y         β
        β 3   β z   β 1         β x         β
        βββββββ΄ββββββ΄ββββββββββββ΄ββββββββββββ
        )r   r   Ϊname_prefix©r   Ϊprefixs     r   r   zExprNameNameSpace.prefixk   σ    τD Χ1Ρ1°&Σ9Σ:Π:r   c                σJ    t        | j                  j                  |«      «      S )uΘ  
        Add a suffix to the root column name of the expression.

        Parameters
        ----------
        suffix
            Suffix to add to the root column name.

        See Also
        --------
        prefix
        map

        Examples
        --------
        >>> df = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 3],
        ...         "b": ["x", "y", "z"],
        ...     }
        ... )
        >>> df.with_columns(pl.all().reverse().name.suffix("_reverse"))
        shape: (3, 4)
        βββββββ¬ββββββ¬ββββββββββββ¬ββββββββββββ
        β a   β b   β a_reverse β b_reverse β
        β --- β --- β ---       β ---       β
        β i64 β str β i64       β str       β
        βββββββͺββββββͺββββββββββββͺββββββββββββ‘
        β 1   β x   β 3         β z         β
        β 2   β y   β 2         β y         β
        β 3   β z   β 1         β x         β
        βββββββ΄ββββββ΄ββββββββββββ΄ββββββββββββ
        )r   r   Ϊname_suffix©r   Ϊsuffixs     r   r#   zExprNameNameSpace.suffix   r   r   c                σH    t        | j                  j                  «       «      S )uπ  
        Make the root column name lowercase.

        See Also
        --------
        prefix
        suffix
        to_uppercase
        map

        Examples
        --------
        >>> df = pl.DataFrame(
        ...     {
        ...         "ColX": [1, 2, 3],
        ...         "ColY": ["x", "y", "z"],
        ...     }
        ... )
        >>> df.with_columns(pl.all().name.to_lowercase())
        shape: (3, 4)
        ββββββββ¬βββββββ¬βββββββ¬βββββββ
        β ColX β ColY β colx β coly β
        β ---  β ---  β ---  β ---  β
        β i64  β str  β i64  β str  β
        ββββββββͺβββββββͺβββββββͺβββββββ‘
        β 1    β x    β 1    β x    β
        β 2    β y    β 2    β y    β
        β 3    β z    β 3    β z    β
        ββββββββ΄βββββββ΄βββββββ΄βββββββ
        )r   r   Ϊname_to_lowercaser   s    r   Ϊto_lowercasezExprNameNameSpace.to_lowercase³   σ    τ> Χ7Ρ7Σ9Σ:Π:r   c                σH    t        | j                  j                  «       «      S )uπ  
        Make the root column name uppercase.

        See Also
        --------
        prefix
        suffix
        to_lowercase
        map

        Examples
        --------
        >>> df = pl.DataFrame(
        ...     {
        ...         "ColX": [1, 2, 3],
        ...         "ColY": ["x", "y", "z"],
        ...     }
        ... )
        >>> df.with_columns(pl.all().name.to_uppercase())
        shape: (3, 4)
        ββββββββ¬βββββββ¬βββββββ¬βββββββ
        β ColX β ColY β COLX β COLY β
        β ---  β ---  β ---  β ---  β
        β i64  β str  β i64  β str  β
        ββββββββͺβββββββͺβββββββͺβββββββ‘
        β 1    β x    β 1    β x    β
        β 2    β y    β 2    β y    β
        β 3    β z    β 3    β z    β
        ββββββββ΄βββββββ΄βββββββ΄βββββββ
        )r   r   Ϊname_to_uppercaser   s    r   Ϊto_uppercasezExprNameNameSpace.to_uppercaseΤ   r'   r   c                σJ    t        | j                  j                  |«      «      S )aL  
        Rename fields of a struct by mapping a function over the field name(s).

        Notes
        -----
        This only takes effect for struct columns.

        Parameters
        ----------
        function
            Function that maps a field name to a new name.

        See Also
        --------
        prefix_fields
        suffix_fields

        Examples
        --------
        >>> df = pl.DataFrame({"x": {"a": 1, "b": 2}})
        >>> df.select(pl.col("x").name.map_fields(lambda x: x.upper())).schema
        Schema({'x': Struct({'A': Int64, 'B': Int64})})
        )r   r   Ϊname_map_fieldsr   s     r   Ϊ
map_fieldszExprNameNameSpace.map_fieldsυ   s    τ0 Χ5Ρ5°hΣ?Σ@Π@r   c                σJ    t        | j                  j                  |«      «      S )a%  
        Add a prefix to all field names of a struct.

        Notes
        -----
        This only takes effect for struct columns.

        Parameters
        ----------
        prefix
            Prefix to add to the field name.

        See Also
        --------
        map_fields
        suffix_fields

        Examples
        --------
        >>> df = pl.DataFrame({"x": {"a": 1, "b": 2}})
        >>> df.select(pl.col("x").name.prefix_fields("prefix_")).schema
        Schema({'x': Struct({'prefix_a': Int64, 'prefix_b': Int64})})
        )r   r   Ϊname_prefix_fieldsr   s     r   Ϊprefix_fieldszExprNameNameSpace.prefix_fields  σ    τ0 Χ8Ρ8ΈΣ@ΣAΠAr   c                σJ    t        | j                  j                  |«      «      S )a%  
        Add a suffix to all field names of a struct.

        Notes
        -----
        This only takes effect for struct columns.

        Parameters
        ----------
        suffix
            Suffix to add to the field name.

        See Also
        --------
        map_fields
        prefix_fields

        Examples
        --------
        >>> df = pl.DataFrame({"x": {"a": 1, "b": 2}})
        >>> df.select(pl.col("x").name.suffix_fields("_suffix")).schema
        Schema({'x': Struct({'a_suffix': Int64, 'b_suffix': Int64})})
        )r   r   Ϊname_suffix_fieldsr"   s     r   Ϊsuffix_fieldszExprNameNameSpace.suffix_fields)  r1   r   N)r   r   ΪreturnΪNone)r5   r   )r   zCallable[[str], str]r5   r   )r   Ϊstrr5   r   )r#   r7   r5   r   )Ϊ__name__Ϊ
__module__Ϊ__qualname__Ϊ__doc__Ϊ	_accessorr   r   r   r   r#   r&   r*   r-   r0   r4   © r   r   r	   r	      sE    ΩEΰIσ$σ+3σZ):σV";σH";σH;σB;σBAσ4Bτ4Br   r	   N)
Ϊ
__future__r   Ϊtypingr   r   Ϊpolars._utils.wrapr   Ϊpolarsr   r	   r=   r   r   ϊ<module>rB      s"   πέ "η *ε (αέχvBς vBr   