
    h9                        S SK Jr  S SKJr  S SKJr  S SKJr  S SKJr  \(       a  S SKJr  \" SSS	9r	 " S
 S\\	   5      r
g)    )annotations)TYPE_CHECKING)Any)Generic)TypeVar)SeriesSeriesTzSeries[Any])boundc                      \ rS rSrSS jrSS jrSSS.         SS jjrSS.SS	 jjrSSS jjrSS jr	SS jr
SS.SS jjrSS S jjrS!S jrS"S#S jjrS"S#S jjrSS jrSS jrSS$S jjrSrg
)%SeriesStringNamespace   c                    Xl         g N_narwhals_series)selfseriess     E/var/www/html/env/lib/python3.13/site-packages/narwhals/series_str.py__init__SeriesStringNamespace.__init__   s     &    c                    U R                   R                  U R                   R                  R                  R	                  5       5      $ )a  Return the length of each string as the number of characters.

Returns:
    A new Series containing the length of each string in characters.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> s_native = pl.Series(["foo", "345", None])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.len_chars().to_native()  # doctest: +NORMALIZE_WHITESPACE
    shape: (3,)
    Series: '' [u32]
    [
            3
            3
            null
    ]
)r   _with_compliant_compliant_seriesstr	len_charsr   s    r   r   SeriesStringNamespace.len_chars   s;    ( $$44!!3377AAC
 	
r   F   literalnc          	         U R                   R                  U R                   R                  R                  R	                  XX4S95      $ )a  Replace first matching regex/literal substring with a new string value.

Arguments:
    pattern: A valid regular expression pattern.
    value: String that will replace the matched substring.
    literal: Treat `pattern` as a literal string.
    n: Number of matches to replace.

Returns:
    A new Series with the regex/literal pattern replaced with the specified value.

Examples:
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> s_native = pd.Series(["123abc", "abc abc123"])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.replace("abc", "").to_native()
    0        123
    1     abc123
    dtype: object
r    )r   r   r   r   replace)r   patternvaluer!   r"   s        r   r$   SeriesStringNamespace.replace*   sH    0 $$44!!3377?? @ 
 	
r   r!   c                   U R                   R                  U R                   R                  R                  R	                  XUS95      $ )a`  Replace all matching regex/literal substring with a new string value.

Arguments:
    pattern: A valid regular expression pattern.
    value: String that will replace the matched substring.
    literal: Treat `pattern` as a literal string.

Returns:
    A new Series with all occurrences of pattern replaced with the specified value.

Examples:
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> s_native = pd.Series(["123abc", "abc abc123"])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.replace_all("abc", "").to_native()
    0     123
    1     123
    dtype: object
r(   )r   r   r   r   replace_all)r   r%   r&   r!   s       r   r*   !SeriesStringNamespace.replace_allH   sH    * $$44!!3377CC D 
 	
r   Nc                    U R                   R                  U R                   R                  R                  R	                  U5      5      $ )a  Remove leading and trailing characters.

Arguments:
    characters: The set of characters to be removed. All combinations of this set of characters will be stripped from the start and end of the string. If set to None (default), all leading and trailing whitespace is removed instead.

Returns:
    A new Series with leading and trailing characters removed.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> s_native = pl.Series(["apple", "\nmango"])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.strip_chars().to_native()  # doctest: +NORMALIZE_WHITESPACE
    shape: (2,)
    Series: '' [str]
    [
            "apple"
            "mango"
    ]
)r   r   r   r   strip_chars)r   
characterss     r   r-   !SeriesStringNamespace.strip_charsc   s=    , $$44!!3377CCJO
 	
r   c                    U R                   R                  U R                   R                  R                  R	                  U5      5      $ )a  Check if string values start with a substring.

Arguments:
    prefix: prefix substring

Returns:
    A new Series with boolean values indicating if each string starts with the prefix.

Examples:
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> s_native = pd.Series(["apple", "mango", None])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.starts_with("app").to_native()
    0     True
    1    False
    2     None
    dtype: object
)r   r   r   r   starts_with)r   prefixs     r   r1   !SeriesStringNamespace.starts_with}   s=    ( $$44!!3377CCFK
 	
r   c                    U R                   R                  U R                   R                  R                  R	                  U5      5      $ )a  Check if string values end with a substring.

Arguments:
    suffix: suffix substring

Returns:
    A new Series with boolean values indicating if each string ends with the suffix.

Examples:
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> s_native = pd.Series(["apple", "mango", None])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.ends_with("ngo").to_native()
    0    False
    1     True
    2     None
    dtype: object
)r   r   r   r   	ends_with)r   suffixs     r   r5   SeriesStringNamespace.ends_with   s=    ( $$44!!3377AA&I
 	
r   c                   U R                   R                  U R                   R                  R                  R	                  XS95      $ )a  Check if string contains a substring that matches a pattern.

Arguments:
    pattern: A Character sequence or valid regular expression pattern.
    literal: If True, treats the pattern as a literal string.
             If False, assumes the pattern is a regular expression.

Returns:
    A new Series with boolean values indicating if each string contains the pattern.

Examples:
    >>> import pyarrow as pa
    >>> import narwhals as nw
    >>> s_native = pa.chunked_array([["cat", "dog", "rabbit and parrot"]])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.contains("cat|parrot").to_native()  # doctest: +ELLIPSIS
    <pyarrow.lib.ChunkedArray object at ...>
    [
      [
        true,
        false,
        true
      ]
    ]
r(   )r   r   r   r   contains)r   r%   r!   s      r   r9   SeriesStringNamespace.contains   s@    4 $$44!!3377@@@Z
 	
r   c                    U R                   R                  U R                   R                  R                  R	                  XS95      $ )aY  Create subslices of the string values of a Series.

Arguments:
    offset: Start index. Negative indexing is supported.
    length: Length of the slice. If set to `None` (default), the slice is taken to the
        end of the string.

Returns:
    A new Series containing subslices of each string.

Examples:
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> s_native = pd.Series(["pear", None, "papaya"])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.slice(4, 3).to_native()  # doctest: +NORMALIZE_WHITESPACE
    0
    1    None
    2      ya
    dtype: object
offsetlengthr   r   r   r   slice)r   r=   r>   s      r   r@   SeriesStringNamespace.slice   sE    , $$44!!3377== > 
 	
r   c                    U R                   R                  U R                   R                  R                  R	                  US95      $ )a  Split the string values of a Series by a substring.

Arguments:
    by: Substring to split by.

Returns:
    A new Series containing lists of strings.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> s_native = pl.Series(["foo bar", "foo_bar"])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.split("_").to_native()  # doctest: +NORMALIZE_WHITESPACE
    shape: (2,)
    Series: '' [list[str]]
    [
            ["foo bar"]
            ["foo", "bar"]
    ]
)by)r   r   r   r   split)r   rC   s     r   rD   SeriesStringNamespace.split   s@    , $$44!!3377===D
 	
r   c                    U R                   R                  U R                   R                  R                  R	                  SUS95      $ )az  Take the first n elements of each string.

Arguments:
    n: Number of elements to take. Negative indexing is supported (see note (1.))

Returns:
    A new Series containing the first n characters of each string.

Notes:
    1. When the `n` input is negative, `head` returns characters up to the n-th from the end of the string.
        For example, if `n = -3`, then all characters except the last three are returned.
    2. If the length of the string has fewer than `n` characters, the full string is returned.

Examples:
    >>> import pyarrow as pa
    >>> import narwhals as nw
    >>> s_native = pa.chunked_array([["taata", "taatatata", "zukkyun"]])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.head().to_native()  # doctest: +ELLIPSIS
    <pyarrow.lib.ChunkedArray object at ...>
    [
      [
        "taata",
        "taata",
        "zukky"
      ]
    ]
r   r<   r?   r   r"   s     r   headSeriesStringNamespace.head  sB    : $$44!!3377==Qq=Q
 	
r   c                    U R                   R                  U R                   R                  R                  R	                  U* SS95      $ )a  Take the last n elements of each string.

Arguments:
    n: Number of elements to take. Negative indexing is supported (see note (1.))

Returns:
    A new Series containing the last n characters of each string.

Notes:
    1. When the `n` input is negative, `tail` returns characters starting from the n-th from the beginning of
        the string. For example, if `n = -3`, then all characters except the first three are returned.
    2. If the length of the string has fewer than `n` characters, the full string is returned.

Examples:
    >>> import pyarrow as pa
    >>> import narwhals as nw
    >>> s_native = pa.chunked_array([["taata", "taatatata", "zukkyun"]])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.tail().to_native()  # doctest: +ELLIPSIS
    <pyarrow.lib.ChunkedArray object at ...>
    [
      [
        "taata",
        "atata",
        "kkyun"
      ]
    ]
Nr<   r?   rG   s     r   tailSeriesStringNamespace.tail"  sE    : $$44!!3377==aRPT=U
 	
r   c                    U R                   R                  U R                   R                  R                  R	                  5       5      $ )uM  Transform string to uppercase variant.

Returns:
    A new Series with values converted to uppercase.

Notes:
    The PyArrow backend will convert 'ß' to 'ẞ' instead of 'SS'.
    For more info see: https://github.com/apache/arrow/issues/34599
    There may be other unicode-edge-case-related variations across implementations.

Examples:
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> s_native = pd.Series(["apple", None])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.to_uppercase().to_native()
    0    APPLE
    1     None
    dtype: object
)r   r   r   r   to_uppercaser   s    r   rN   "SeriesStringNamespace.to_uppercaseC  s;    * $$44!!3377DDF
 	
r   c                    U R                   R                  U R                   R                  R                  R	                  5       5      $ )ai  Transform string to lowercase variant.

Returns:
    A new Series with values converted to lowercase.

Examples:
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> s_native = pd.Series(["APPLE", None])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.to_lowercase().to_native()
    0    apple
    1     None
    dtype: object
)r   r   r   r   to_lowercaser   s    r   rQ   "SeriesStringNamespace.to_lowercase\  s;      $$44!!3377DDF
 	
r   c                    U R                   R                  U R                   R                  R                  R	                  US95      $ )u  Parse Series with strings to a Series with Datetime dtype.

Notes:
    - pandas defaults to nanosecond time unit, Polars to microsecond.
      Prior to pandas 2.0, nanoseconds were the only time unit supported
      in pandas, with no ability to set any other one. The ability to
      set the time unit in pandas, if the version permits, will arrive.
    - timezone-aware strings are all converted to and parsed as UTC.

Warning:
    As different backends auto-infer format in different ways, if `format=None`
    there is no guarantee that the result will be equal.

Arguments:
    format: Format to use for conversion. If set to None (default), the format is
        inferred from the data.

Returns:
    A new Series with datetime dtype.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> s_native = pl.Series(["2020-01-01", "2020-01-02"])
    >>> s = nw.from_native(s_native, series_only=True)
    >>> s.str.to_datetime(
    ...     format="%Y-%m-%d"
    ... ).to_native()  # doctest: +NORMALIZE_WHITESPACE
    shape: (2,)
    Series: '' [datetime[μs]]
    [
            2020-01-01 00:00:00
            2020-01-02 00:00:00
    ]
)format)r   r   r   r   to_datetime)r   rT   s     r   rU   !SeriesStringNamespace.to_datetimep  sA    H $$44!!3377CC6CR
 	
r   r   )r   r	   returnNone)rW   r	   )
r%   r   r&   r   r!   boolr"   intrW   r	   )r%   r   r&   r   r!   rY   rW   r	   r   )r.   
str | NonerW   r	   )r2   r   rW   r	   )r6   r   rW   r	   )r%   r   r!   rY   rW   r	   )r=   rZ   r>   z
int | NonerW   r	   )rC   r   rW   r	   )   )r"   rZ   rW   r	   )rT   r[   rW   r	   )__name__
__module____qualname____firstlineno__r   r   r$   r*   r-   r1   r5   r9   r@   rD   rH   rK   rN   rQ   rU   __static_attributes__ r   r   r   r      s    '
2 <A1

#&
48
EH
	
< HM 
6
4
0
0 9> 
<
8
4
B
B
2
(&
 &
r   r   N)
__future__r   typingr   r   r   r   narwhals.seriesr   r	   r   rb   r   r   <module>rf      s9    "     &
)=
1H
GG, H
r   