ง
    q-Phึ/  ใ                  ๓L    d dl mZ d dlmZmZ erd dlmZ  G d dฆ  ซ        ZdS )้    )ฺannotations)ฺTYPE_CHECKINGฺCallable)ฺExprc                  ๓f    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dS )ฺExprNameNameSpacez;Namespace for expressions that operate on expression names.ฺnameฺexprr   ฺreturnฺNonec                ๓6    |j         | _         |j        | _        d S )N)ฺ_from_pyexprฺ_pyexpr)ฺselfr
   s     ๚P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/expr/name.pyฺ__init__zExprNameNameSpace.__init__   s    ุ ิ-ิุ|๓    c                ๓Z    |                       | 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ิ!9ั:ิ:ะ:r   ฺfunction๚Callable[[str], str]c                ๓\    |                       | 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   r   s     r   ฺmapzExprNameNameSpace.mapG   s)    ๐b ื า  คื!6า!6ฐxั!@ิ!@ัAิAะAr   ฺprefixฺstrc                ๓\    |                       | 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   r   s     r   r   zExprNameNameSpace.prefixz   s)    ๐T ื า  คื!9า!9ธ&ั!Aิ!AัBิBะBr   ฺsuffixc                ๓\    |                       | 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   r#   s     r   r#   zExprNameNameSpace.suffixฆ   s)    ๐R ื า  คื!9า!9ธ&ั!Aิ!AัBิBะBr   c                ๓Z    |                       | 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ิ!AัBิBะBr   c                ๓Z    |                       | 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                ๓\    |                       | 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ิ!GัHิHะHr   c                ๓\    |                       | 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ิ!HัIิIะIr   c                ๓\    |                       | 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  r4   r   N)r
   r   r   r   )r   r   )r   r   r   r   )r   r   r   r   )r#   r   r   r   )ฺ__name__ฺ
__module__ฺ__qualname__ฺ__doc__ฺ	_accessorr   r   r   r   r#   r)   r-   r0   r3   r7   ฉ r   r   r   r   	   s       ุEะEเI๐$๐ $๐ $๐ $๐3;๐ 3;๐ 3;๐ 3;๐j1B๐ 1B๐ 1B๐ 1B๐f*C๐ *C๐ *C๐ *C๐X)C๐ )C๐ )C๐ )C๐V&C๐ &C๐ &C๐ &C๐P&C๐ &C๐ &C๐ &C๐PI๐ I๐ I๐ I๐4J๐ J๐ J๐ J๐4J๐ J๐ J๐ J๐ J๐ Jr   r   N)ฺ
__future__r   ฺtypingr   r   ฺpolarsr   r   r=   r   r   ๚<module>rA      s   ๐ุ "ะ "ะ "ะ "ะ "ะ "เ *ะ *ะ *ะ *ะ *ะ *ะ *ะ *เ๐ ุะะะะะ๐dJ๐ dJ๐ dJ๐ dJ๐ dJ๑ dJ๔ dJ๐ dJ๐ dJ๐ dJr   