
    j+&                        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	 d dl
mZmZmZmZmZ e G d d                      Zd	S )
    )annotations)TYPE_CHECKING)expr_dispatch)Series)PySeries)
EndiannessIntoExprPolarsDataTypeSizeUnitTransferEncodingc                      e Zd ZdZdZd2dZd3d
Zd4dZd5dZddd6dZ	d7dZ
d8d9dZddd:d!Zd;d<d'Zd(d)d=d-Zd>d?d0Zd>d?d1Zd"S )@BinaryNameSpacezSeries.bin namespace.binseriesr   returnNonec                    |j         | _         d S N)_s)selfr   s     Y/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/polars/series/binary.py__init__zBinaryNameSpace.__init__   s    "I    literalr	   c                    dS )a+  
        Check if binaries in Series contain a binary substring.

        Parameters
        ----------
        literal
            The binary substring to look for

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

        Examples
        --------
        >>> s = pl.Series("colors", [b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"])
        >>> s.bin.contains(b"\xff")
        shape: (3,)
        Series: 'colors' [bool]
        [
            false
            true
            true
        ]
        N )r   r   s     r   containszBinaryNameSpace.contains         r   suffixc                    dS )a  
        Check if string values end with a binary substring.

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

        Examples
        --------
        >>> s = pl.Series("colors", [b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"])
        >>> s.bin.ends_with(b"\x00")
        shape: (3,)
        Series: 'colors' [bool]
        [
            true
            true
            false
        ]
        Nr   )r   r   s     r   	ends_withzBinaryNameSpace.ends_with7   r   r   prefixc                    dS )a  
        Check if values start with a binary substring.

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

        Examples
        --------
        >>> s = pl.Series("colors", [b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"])
        >>> s.bin.starts_with(b"\x00")
        shape: (3,)
        Series: 'colors' [bool]
        [
            true
            false
            true
        ]
        Nr   )r   r"   s     r   starts_withzBinaryNameSpace.starts_withM   r   r   T)strictencodingr   r%   boolc                   dS )a  
        Decode values using the provided encoding.

        Parameters
        ----------
        encoding : {'hex', 'base64'}
            The encoding to use.
        strict
            Raise an error if the underlying value cannot be decoded,
            otherwise mask out with a null value.

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

        Examples
        --------
        Decode values using hexadecimal encoding.

        >>> s = pl.Series("colors", [b"000000", b"ffff00", b"0000ff"])
        >>> s.bin.decode("hex")
        shape: (3,)
        Series: 'colors' [binary]
        [
            b"\x00\x00\x00"
            b"\xff\xff\x00"
            b"\x00\x00\xff"
        ]

        Decode values using Base64 encoding.

        >>> s = pl.Series("colors", [b"AAAA", b"//8A", b"AAD/"])
        >>> s.bin.decode("base64")
        shape: (3,)
        Series: 'colors' [binary]
        [
            b"\x00\x00\x00"
            b"\xff\xff\x00"
            b"\x00\x00\xff"
        ]

        Set `strict=False` to set invalid values to null instead of raising an error.

        >>> s = pl.Series("colors", [b"000000", b"ffff00", b"invalid_value"])
        >>> s.bin.decode("hex", strict=False)
        shape: (3,)
        Series: 'colors' [binary]
        [
            b"\x00\x00\x00"
            b"\xff\xff\x00"
            null
        ]
        Nr   )r   r&   r%   s      r   decodezBinaryNameSpace.decodec   r   r   c                    dS )a1  
        Encode values using the provided encoding.

        Parameters
        ----------
        encoding : {'hex', 'base64'}
            The encoding to use.

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

        Examples
        --------
        Encode values using hexadecimal encoding.

        >>> s = pl.Series("colors", [b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"])
        >>> s.bin.encode("hex")
        shape: (3,)
        Series: 'colors' [str]
        [
            "000000"
            "ffff00"
            "0000ff"
        ]

        Encode values using Base64 encoding.

        >>> s.bin.encode("base64")
        shape: (3,)
        Series: 'colors' [str]
        [
            "AAAA"
            "//8A"
            "AAD/"
        ]
        Nr   )r   r&   s     r   encodezBinaryNameSpace.encode   r   r   bunitr   c                    dS )a  
        Get the size of the binary values in a Series in the given unit.

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

        Examples
        --------
        >>> from os import urandom
        >>> s = pl.Series("data", [urandom(n) for n in (512, 256, 2560, 1024)])
        >>> s.bin.size("kb")
        shape: (4,)
        Series: 'data' [f64]
        [
            0.5
            0.25
            2.5
            1.0
        ]
        Nr   )r   r-   s     r   sizezBinaryNameSpace.size   r   r   little)
endiannessdtyper
   r1   r   c                   dS )a  
        Interpret bytes as another type.

        Supported types are numerical or temporal dtypes, or an ``Array`` of
        these dtypes.

        Parameters
        ----------
        dtype : PolarsDataType
            Which type to interpret binary column into.
        endianness : {"big", "little"}, optional
            Which endianness to use when interpreting bytes, by default "little".

        Returns
        -------
        Series
            Series of data type `dtype`.
            Note that rows of the binary array where the length does not match
            the size in bytes of the output array (number of items * byte size
            of item) will become NULL.

        Examples
        --------
        >>> s = pl.Series("data", [b"\x05\x00\x00\x00", b"\x10\x00\x01\x00"])
        >>> s.bin.reinterpret(dtype=pl.Int32, endianness="little")
        shape: (2,)
        Series: 'data' [i32]
        [
            5
            65552
        ]

        Nr   )r   r2   r1   s      r   reinterpretzBinaryNameSpace.reinterpret   r   r   Noffsetintlength
int | Nonec                    dS )a  
        Slice the binary values.

        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 value.

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

        Examples
        --------
        >>> colors = pl.Series([b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"])
        >>> colors.bin.slice(1, 2)
        shape: (3,)
        Series: '' [binary]
        [
                b"\x00\x00"
                b"\xff\x00"
                b"\x00\xff"
        ]
        Nr   )r   r5   r7   s      r   slicezBinaryNameSpace.slice   r   r   F)null_on_oobindexint | IntoExprr;   c                   dS )a-  
        Get the byte value at the given index.

        For example, index `0` would return the first byte of every binary value
        and index `-1` would return the last byte of every binary value.
        The behavior if an index is out of bounds is determined by the argument
        `null_on_oob`.

        Parameters
        ----------
        index
            Index to return per binary value
        null_on_oob
            Behavior if an index is out of bounds:

            * True -> set as null
            * False -> raise an error

        Examples
        --------
        >>> s = pl.Series("a", [b"\x01\x02\x03", b"", b"\x04\x05"])
        >>> s.bin.get(0, null_on_oob=True)
        shape: (3,)
        Series: 'a' [u8]
        [
            1
            null
            4
        ]

        Nr   )r   r<   r;   s      r   getzBinaryNameSpace.get  r   r      nc                    dS )a`  
        Take the first `n` bytes of the binary values.

        Parameters
        ----------
        n
            Length of the slice. Negative indexing is supported; see note (2) below.

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

        Notes
        -----
        (1) A similar method exists for taking the last `n` bytes: :func:`tail`.
        (2) If `n` is negative, it is interpreted as "until the nth byte from the end",
            e.g., ``head(-3)`` returns all but the last three bytes.

        Examples
        --------
        >>> colors = pl.Series([b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"])
        >>> colors.bin.head(2)
        shape: (3,)
        Series: '' [binary]
        [
                b"\x00\x00"
                b"\xff\xff"
                b"\x00\x00"
        ]
        Nr   r   rA   s     r   headzBinaryNameSpace.head?  r   r   c                    dS )aZ  
        Take the last `n` bytes of the binary values.

        Parameters
        ----------
        n
            Length of the slice. Negative indexing is supported; see note (2) below.

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

        Notes
        -----
        (1) A similar method exists for taking the first `n` bytes: :func:`head`.
        (2) If `n` is negative, it is interpreted as "starting at the nth byte",
            e.g., ``tail(-3)`` returns all but the first three bytes.

        Examples
        --------
        >>> colors = pl.Series([b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"])
        >>> colors.bin.tail(2)
        shape: (3,)
        Series: '' [binary]
        [
                b"\x00\x00"
                b"\xff\x00"
                b"\x00\xff"
        ]
        Nr   rC   s     r   tailzBinaryNameSpace.tail`  r   r   )r   r   r   r   )r   r	   r   r   )r   r	   r   r   )r"   r	   r   r   )r&   r   r%   r'   r   r   )r&   r   r   r   )r,   )r-   r   r   r   )r2   r
   r1   r   r   r   r   )r5   r6   r7   r8   r   r   )r<   r=   r;   r'   r   r   )r@   )rA   r6   r   r   )__name__
__module____qualname____doc__	_accessorr   r   r!   r$   r)   r+   r/   r4   r:   r?   rD   rF   r   r   r   r   r      s[       I& & & &   6   ,   , DH 6 6 6 6 6 6p& & & &P    2 BJ# # # # # #J    < AF      B    B      r   r   N)
__future__r   typingr   polars.series.utilsr   polarsr   polars._plrr   polars._typingr   r	   r
   r   r   r   r   r   r   <module>rR      s    " " " " " "             - - - - - - 	$$$$$$              k k k k k k k k k kr   