ง
    ่jF:  ใ                  ๓`    d dl mZ d dlmZ d dlmZ erd dlmZ d dlm	Z	  G d dฆ  ซ        Z
dS )	้    )ฺannotations)ฺTYPE_CHECKING)ฺ	wrap_expr)ฺCallable)ฺExprc                  ๓t    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d#dZd"dZdS )$ฺExprNameNameSpacez;Namespace for expressions that operate on expression names.ฺnameฺexprr   ฺreturnฺNonec                ๓    |j         | _         d S )N)ฺ_pyexpr)ฺselfr   s     ๚U/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/polars/expr/name.pyฺ__init__zExprNameNameSpace.__init__   s    ุ|๓    c                ๓N    t          | 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ิ1ั2ิ2ะ2r   ฺfunction๚Callable[[str], str]c                ๓P    t          | 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
        replace

        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.mapB   s#    ๕T ื.า.จxั8ิ8ั9ิ9ะ9r   ฺprefixฺstrc                ๓P    t          | 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   r   s     r   r   zExprNameNameSpace.prefixn   ๓#    ๕D ื1า1ฐ&ั9ิ9ั:ิ:ะ:r   ฺsuffixc                ๓P    t          | 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   r$   s     r   r$   zExprNameNameSpace.suffix   r#   r   c                ๓N    t          | 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ิ9ั:ิ:ะ:r   c                ๓N    t          | 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                ๓P    t          | 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                ๓P    t          | 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ิAะAr   F)ฺliteralฺpatternฺvaluer6   ฺboolc               ๓T    t          | j                             |||ฆ  ซ        ฆ  ซ        S )u/  
        Replace matching regex/literal substring in the name with a new value.

        Parameters
        ----------
        pattern
            A valid regular expression pattern, compatible with the `regex crate
            <https://docs.rs/regex/latest/regex/>`_.
        value
            String that will replace the matched substring.
        literal
            Treat `pattern` as a literal string, not a regex.

        Notes
        -----
        * To modify regular expression behaviour (such as case-sensitivity) with flags,
          use the inline `(?iLmsuxU)` syntax. See the regex crate's section on
          `grouping and flags <https://docs.rs/regex/latest/regex/#grouping-and-flags>`_
          for additional information about the use of inline expression modifiers.

        * The dollar sign (`$`) is a special character related to capture groups; if you
          want to replace some target pattern with characters that include a literal `$`
          you should escape it by doubling it up as `$$`, or set `literal=True` if you
          do not need a full regular expression pattern match. Otherwise, you will be
          referencing a (potentially non-existent) capture group.

        See Also
        --------
        Expr.str.replace

        Examples
        --------
        >>> df = pl.DataFrame(
        ...     {
        ...         "n_foo": [1, 2, 3],
        ...         "n_bar": ["x", "y", "z"],
        ...     }
        ... )
        >>> df.select(pl.all().name.replace(r"^n_", "col_"))
        shape: (3, 2)
        โโโโโโโโโโโฌโโโโโโโโโโ
        โ col_foo โ col_bar โ
        โ ---     โ ---     โ
        โ i64     โ str     โ
        โโโโโโโโโโโชโโโโโโโโโโก
        โ 1       โ x       โ
        โ 2       โ y       โ
        โ 3       โ z       โ
        โโโโโโโโโโโดโโโโโโโโโโ
        >>> df.select(pl.all().name.replace(r"(a|e|i|o|u)", "@")).schema
        Schema({'n_f@@': Int64, 'n_b@r': String})

        Apply case-insensitive string replacement using the `(?i)` flag.

        >>> pl.DataFrame({"Foo": [1], "faz": [2]}).select(
        ...     pl.all().name.replace(r"(?i)^f", "b")
        ... )
        shape: (1, 2)
        โโโโโโโฌโโโโโโ
        โ boo โ baz โ
        โ --- โ --- โ
        โ i64 โ i64 โ
        โโโโโโโชโโโโโโก
        โ 1   โ 2   โ
        โโโโโโโดโโโโโโ

        Capture groups are supported. Use `$1` or `${1}` in the `value` string to refer
        to the first capture group in the pattern, `$2` or `${2}` to refer to the
        second capture group, and so on. You can also use named capture groups.

        >>> df = pl.DataFrame({"x_1": [1], "x_2": [2], "group_id": ["xyz"]})
        >>> df.select(pl.all().name.replace(r"_(\d+)$", ":$1"))
        shape: (1, 3)
        โโโโโโโฌโโโโโโฌโโโโโโโโโโโ
        โ x:1 โ x:2 โ group_id โ
        โ --- โ --- โ ---      โ
        โ i64 โ i64 โ str      โ
        โโโโโโโชโโโโโโชโโโโโโโโโโโก
        โ 1   โ 2   โ xyz      โ
        โโโโโโโดโโโโโโดโโโโโโโโโโโ

        The `${1}` form is used to disambiguate the group reference from surrounding
        text.

        >>> df = pl.DataFrame({"hat": [1], "hut": [2]}).with_row_index()
        >>> df.with_columns(pl.all().name.replace(r"^h(.)t", "s$1m"))  # doctest: +SKIP
        # ComputeError: the name 's' passed to `LazyFrame.with_columns` is duplicate

        >>> df.with_columns(pl.all().name.replace(r"^h(.)t", "s${1}m"))
        shape: (1, 5)
        โโโโโโโโโฌโโโโโโฌโโโโโโฌโโโโโโฌโโโโโโ
        โ index โ hat โ hut โ sam โ sum โ
        โ ---   โ --- โ --- โ --- โ --- โ
        โ u32   โ i64 โ i64 โ i64 โ i64 โ
        โโโโโโโโโชโโโโโโชโโโโโโชโโโโโโชโโโโโโก
        โ 0     โ 1   โ 2   โ 1   โ 2   โ
        โโโโโโโโโดโโโโโโดโโโโโโดโโโโโโดโโโโโโ
        )r   r   ฺname_replace)r   r7   r8   r6   s       r   ฺreplacezExprNameNameSpace.replace,  s'    ๕F ื2า2ฐ7ธEภ7ัKิKัLิLะLr   c                ๓P    t          | 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  r5   r   N)r   r   r   r   )r   r   )r   r   r   r   )r   r   r   r   )r$   r   r   r   )r7   r   r8   r   r6   r9   r   r   )ฺ__name__ฺ
__module__ฺ__qualname__ฺ__doc__ฺ	_accessorr   r   r   r   r$   r*   r.   r1   r4   r<   r?   ฉ r   r   r	   r	      s-       ุEะEเI๐$๐ $๐ $๐ $๐+3๐ +3๐ +3๐ +3๐Z*:๐ *:๐ *:๐ *:๐X";๐ ";๐ ";๐ ";๐H";๐ ";๐ ";๐ ";๐H;๐ ;๐ ;๐ ;๐B;๐ ;๐ ;๐ ;๐BA๐ A๐ A๐ A๐4B๐ B๐ B๐ B๐4 DI๐ cM๐ cM๐ cM๐ cM๐ cM๐ cM๐JB๐ B๐ B๐ B๐ B๐ Br   r	   N)ฺ
__future__r   ฺtypingr   ฺpolars._utils.wrapr   ฺcollections.abcr   ฺpolarsr   r	   rE   r   r   ๚<module>rK      sญ   ๐ุ "ะ "ะ "ะ "ะ "ะ "เ  ะ  ะ  ะ  ะ  ะ  เ (ะ (ะ (ะ (ะ (ะ (เ๐ ุ(ะ(ะ(ะ(ะ(ะ(เะะะะะ๐\B๐ \B๐ \B๐ \B๐ \B๑ \B๔ \B๐ \B๐ \B๐ \Br   