Λ
    θΛhΦ/  γ                  σD    d dl mZ d dlmZmZ erd dlmZ  G d d«      Zy)ι    )Ϊannotations)ΪTYPE_CHECKINGΪCallable)Ϊ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                σH    |j                   | _         |j                  | _        y )N)Ϊ_from_pyexprΪ_pyexpr)ΪselfΪexprs     ϊl/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/expr/name.pyΪ__init__zExprNameNameSpace.__init__   s    Ψ Χ-Ρ-ΤΨ||σ    c                σT    | j                  | j                  j                  «       «      S )u  
        Keep the original root name of the expression.

        Notes
        -----
        This will undo any previous renaming operations on the expression.

        Due to implementation constraints, this method can only be called as the last
        expression in a chain. Only one name operation per expression will work.
        Consider using `.name.map` for advanced renaming.

        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#    πf Χ Ρ  §‘Χ!7Ρ!7Σ!9Σ:Π:r   c                σV    | j                  | j                  j                  |«      «      S )u±  
        Rename the output of an expression by mapping a function over the root name.

        Notes
        -----
        This will undo any previous renaming operations on the expression.

        Due to implementation constraints, this method can only be called as the last
        expression in a chain. Only one name operation per expression will work.


        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.mapG   s%    πb Χ Ρ  §‘Χ!6Ρ!6°xΣ!@ΣAΠAr   c                σV    | j                  | 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.


        Notes
        -----
        This will undo any previous renaming operations on the expression.

        Due to implementation constraints, this method can only be called as the last
        expression in a chain. Only one name operation per expression will work.
        Consider using `.name.map` for advanced renaming.

        See Also
        --------
        suffix

        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.prefixz   s%    πT Χ Ρ  §‘Χ!9Ρ!9Έ&Σ!AΣBΠBr   c                σV    | j                  | 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.

        Notes
        -----
        This will undo any previous renaming operations on the expression.

        Due to implementation constraints, this method can only be called as the last
        expression in a chain. Only one name operation per expression will work.
        Consider using `.name.map` for advanced renaming.

        See Also
        --------
        prefix

        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¦   s%    πR Χ Ρ  §‘Χ!9Ρ!9Έ&Σ!AΣBΠBr   c                σT    | j                  | j                  j                  «       «      S )u.  
        Make the root column name lowercase.

        Notes
        -----
        This will undo any previous renaming operations on the expression.

        Due to implementation constraints, this method can only be called as the last
        expression in a chain. Only one name operation per expression will work.
        Consider using `.name.map` for advanced renaming.

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

        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Ρ   σ#    πL Χ Ρ  §‘Χ!?Ρ!?Σ!AΣBΠBr   c                σT    | j                  | j                  j                  «       «      S )u.  
        Make the root column name uppercase.

        Notes
        -----
        This will undo any previous renaming operations on the expression.

        Due to implementation constraints, this method can only be called as the last
        expression in a chain. Only one name operation per expression will work.
        Consider using `.name.map` for advanced renaming.

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

        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                σV    | j                  | 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 Χ Ρ  §‘Χ!=Ρ!=ΈhΣ!GΣHΠHr   c                σV    | j                  | 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 Χ Ρ  §‘Χ!@Ρ!@ΐΣ!HΣIΠIr   c                σV    | j                  | 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_fieldsU  r0   r   N)r   r   ΪreturnΪNone)r4   r   )r   zCallable[[str], str]r4   r   )r   Ϊstrr4   r   )r"   r6   r4   r   )Ϊ__name__Ϊ
__module__Ϊ__qualname__Ϊ__doc__Ϊ	_accessorr   r   r   r   r"   r%   r)   r,   r/   r3   © r   r   r   r   	   sJ    ΩEΰIσ$σ3;σj1Bσf*CσX)CσV&CσP&CσPIσ4Jτ4Jr   r   N)Ϊ
__future__r   Ϊtypingr   r   Ϊpolarsr   r   r<   r   r   ϊ<module>r@      s   πέ "η *αέχdJς dJr   