o
    io                     @  sn   d dl mZ d dlmZ 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 e	G dd	 d	Zd
S )    )annotations)TYPE_CHECKING)
deprecated)wrap_s)expr_dispatch)Series)PySeriesc                   @  s   e Zd ZdZdZd&ddZd'd	d
Zedd(ddZd'ddZ	edd(ddZ
d'ddZd'ddZd)ddZd*ddZd+d,d$d%ZdS )-CatNameSpacez)Namespace for categorical related series.catseriesr   returnNonec                 C  s   |j | _ d S N)_s)selfr    r   P/home/app/Keep/.python/lib/python3.10/site-packages/polars/series/categorical.py__init__   s   zCatNameSpace.__init__c                 C     dS )ab  
        Get the categories stored in this data type.

        Examples
        --------
        >>> s = pl.Series(["foo", "bar", "foo", "foo", "ham"], dtype=pl.Categorical)
        >>> s.cat.get_categories()  # doctest: +SKIP
        shape: (3,)
        Series: '' [str]
        [
            "foo"
            "bar"
            "ham"
        ]
        Nr   r   r   r   r   get_categories       zCatNameSpace.get_categorieszu`cat.is_local()` is deprecated; Categoricals no longer have a local scope. This method will be removed in Polars 2.0.boolc                 C  
   | j  S )zi
        Return whether or not the column is a local categorical.

        Always returns false.
        )r   Zcat_is_localr   r   r   r   is_local(   s   

zCatNameSpace.is_localc                 C  s   t | j S )zFSimply returns the column as-is, local representations are deprecated.)r   r   Zcat_to_localr   r   r   r   to_local4   s   zCatNameSpace.to_localz`cat.uses_lexical_ordering()` is deprecated; Categoricals are now always ordered lexically. This method will be removed in Polars 2.0.c                 C  r   )z
        Indicate whether the Series uses lexical ordering.

        Always returns true.

        Examples
        --------
        >>> s = pl.Series(["b", "a", "b"]).cast(pl.Categorical)
        >>> s.cat.uses_lexical_ordering()
        True
        )r   Zcat_uses_lexical_orderingr   r   r   r   uses_lexical_ordering8   s   
z"CatNameSpace.uses_lexical_orderingc                 C  r   )u&  
        Return the byte-length of the string representation of each value.

        Returns
        -------
        Series
            Series of data type :class:`UInt32`.

        See Also
        --------
        len_chars

        Notes
        -----
        When working with non-ASCII text, the length in bytes is not the same as the
        length in characters. You may want to use :func:`len_chars` instead.
        Note that :func:`len_bytes` is much more performant (_O(1)_) than
        :func:`len_chars` (_O(n)_).

        Examples
        --------
        >>> s = pl.Series(["Café", "345", "東京", None], dtype=pl.Categorical)
        >>> s.cat.len_bytes()
        shape: (4,)
        Series: '' [u32]
        [
            5
            3
            6
            null
        ]
        Nr   r   r   r   r   	len_bytesJ   r   zCatNameSpace.len_bytesc                 C  r   )u  
        Return the number of characters of the string representation of each value.

        Returns
        -------
        Series
            Series of data type :class:`UInt32`.

        See Also
        --------
        len_bytes

        Notes
        -----
        When working with ASCII text, use :func:`len_bytes` instead to achieve
        equivalent output with much better performance:
        :func:`len_bytes` runs in _O(1)_, while :func:`len_chars` runs in (_O(n)_).

        A character is defined as a `Unicode scalar value`_. A single character is
        represented by a single byte when working with ASCII text, and a maximum of
        4 bytes otherwise.

        .. _Unicode scalar value: https://www.unicode.org/glossary/#unicode_scalar_value

        Examples
        --------
        >>> s = pl.Series(["Café", "345", "東京", None], dtype=pl.Categorical)
        >>> s.cat.len_chars()
        shape: (4,)
        Series: '' [u32]
        [
            4
            3
            2
            null
        ]
        Nr   r   r   r   r   	len_charsl   r   zCatNameSpace.len_charsprefixstrc                 C  r   )a{  
        Check if string representations of values start with a substring.

        Parameters
        ----------
        prefix
            Prefix substring.

        See Also
        --------
        contains : Check if the string repr contains a substring that matches a pattern.
        ends_with : Check if string repr ends with a substring.

        Examples
        --------
        >>> s = pl.Series("fruits", ["apple", "mango", None], dtype=pl.Categorical)
        >>> s.cat.starts_with("app")
        shape: (3,)
        Series: 'fruits' [bool]
        [
            true
            false
            null
        ]
        Nr   )r   r   r   r   r   starts_with   r   zCatNameSpace.starts_withsuffixc                 C  r   )az  
        Check if string representations of values end with a substring.

        Parameters
        ----------
        suffix
            Suffix substring.

        See Also
        --------
        contains : Check if the string repr contains a substring that matches a pattern.
        starts_with : Check if string repr starts with a substring.

        Examples
        --------
        >>> s = pl.Series("fruits", ["apple", "mango", None], dtype=pl.Categorical)
        >>> s.cat.ends_with("go")
        shape: (3,)
        Series: 'fruits' [bool]
        [
            false
            true
            null
        ]
        Nr   )r   r"   r   r   r   	ends_with   r   zCatNameSpace.ends_withNoffsetintlength
int | Nonec                 C  r   )aV  
        Extract a substring from the string representation of each string value.

        Parameters
        ----------
        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
        -------
        Series
            Series of data type :class:`String`.

        Notes
        -----
        Both the `offset` and `length` inputs are defined in terms of the number
        of characters in the (UTF8) string. A character is defined as a
        `Unicode scalar value`_. A single character is represented by a single byte
        when working with ASCII text, and a maximum of 4 bytes otherwise.

        .. _Unicode scalar value: https://www.unicode.org/glossary/#unicode_scalar_value

        Examples
        --------
        >>> s = pl.Series(["pear", None, "papaya", "dragonfruit"], dtype=pl.Categorical)
        >>> s.cat.slice(-3)
        shape: (4,)
        Series: '' [str]
        [
            "ear"
            null
            "aya"
            "uit"
        ]

        Using the optional `length` parameter

        >>> s.cat.slice(4, length=3)
        shape: (4,)
        Series: '' [str]
        [
            ""
            null
            "ya"
            "onf"
        ]
        Nr   )r   r$   r&   r   r   r   slice   r   zCatNameSpace.slice)r   r   r   r   )r   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   r   r!   r#   r(   r   r   r   r   r	      s&    




"
'
r	   N)
__future__r   typingr   Zpolars._utils.deprecationr   Zpolars._utils.wrapr   Zpolars.series.utilsr   Zpolarsr   Zpolars._plrr   r	   r   r   r   r   <module>   s    