o
    i*                     @  s   d dl mZ d dlZd dlmZ d dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ erCd dlmZ d d	lmZmZ d d
lmZ n
erMeje Zee_eG dd dZdS )    )annotationsN)TYPE_CHECKING)BUILDING_SPHINX_DOCSqualified_type_namesphinx_accessor)wrap_df)Schema)expr_dispatch)Sequence)	DataFrameSeries)PySeriesc                   @  sv   e Zd ZdZdZd#ddZd$ddZd%ddZed%ddZ	d&ddZ
d'ddZed(ddZd)ddZd*d d!Zd"S )+StructNameSpacezSeries.struct namespace.structseriesr   returnNonec                 C  s   |j | _ d S N)_s)selfr    r   K/home/app/Keep/.python/lib/python3.10/site-packages/polars/series/struct.py__init__!   s   zStructNameSpace.__init__item	int | strc                 C  sD   t |tr| | j| S t |tr| |S dt|}t|)Nzexpected type 'int | str', got )
isinstanceintfieldfieldsstrr   	TypeError)r   r   msgr   r   r   __getitem__$   s   


zStructNameSpace.__getitem__	list[str]c                 C  s   | j S r   )r   r   r   r   r   _ipython_key_completions_-   s   z)StructNameSpace._ipython_key_completions_c                 C  s   t | dddu r
g S | j S )z
        Get the names of the fields.

        Examples
        --------
        >>> s = pl.Series([{"a": 1, "b": 2}, {"a": 3, "b": 4}])
        >>> s.struct.fields
        ['a', 'b']
        r   N)getattrr   Zstruct_fieldsr$   r   r   r   r   0   s   
zStructNameSpace.fieldsnamer   c                 C     dS )a  
        Retrieve one of the fields of this `Struct` as a new Series.

        Parameters
        ----------
        name
            Name of the field.

        Examples
        --------
        >>> s = pl.Series([{"a": 1, "b": 2}, {"a": 3, "b": 4}])
        >>> s.struct.field("a")
        shape: (2,)
        Series: 'a' [i64]
        [
            1
            3
        ]
        Nr   )r   r'   r   r   r   r   ?       zStructNameSpace.fieldnamesSequence[str]c                 C  r(   )a  
        Rename the fields of the struct.

        Parameters
        ----------
        names
            New names in the order of the struct's fields.

        Examples
        --------
        >>> s = pl.Series([{"a": 1, "b": 2}, {"a": 3, "b": 4}])
        >>> s.struct.fields
        ['a', 'b']
        >>> s = s.struct.rename_fields(["c", "d"])
        >>> s.struct.fields
        ['c', 'd']
        Nr   )r   r*   r   r   r   rename_fieldsT   r)   zStructNameSpace.rename_fieldsr   c                 C  s2   t | dddu rti S | j  }t|ddS )z
        Get the struct definition as a name/dtype schema dict.

        Examples
        --------
        >>> s = pl.Series([{"a": 1, "b": 2}, {"a": 3, "b": 4}])
        >>> s.struct.schema
        Schema({'a': Int64, 'b': Int64})
        r   NF)Zcheck_dtypes)r&   r   r   ZdtypeZ	to_schema)r   schemar   r   r   r-   g   s   zStructNameSpace.schemar   c                 C  s   t | j S )u  
        Convert this struct Series to a DataFrame with a separate column for each field.

        Examples
        --------
        >>> s = pl.Series([{"a": 1, "b": 2}, {"a": 3, "b": 4}])
        >>> s.struct.unnest()
        shape: (2, 2)
        ┌─────┬─────┐
        │ a   ┆ b   │
        │ --- ┆ --- │
        │ i64 ┆ i64 │
        ╞═════╪═════╡
        │ 1   ┆ 2   │
        │ 3   ┆ 4   │
        └─────┴─────┘
        )r   r   Zstruct_unnestr$   r   r   r   unnestx   s   zStructNameSpace.unnestc                 C  r(   )ar  
        Convert this struct to a string column with json values.

        Examples
        --------
        >>> s = pl.Series("a", [{"a": [1, 2], "b": [45]}, {"a": [9, 1, 3], "b": None}])
        >>> s.struct.json_encode()
        shape: (2,)
        Series: 'a' [str]
        [
            "{"a":[1,2],"b":[45]}"
            "{"a":[9,1,3],"b":null}"
        ]
        Nr   r$   r   r   r   json_encode   r)   zStructNameSpace.json_encodeN)r   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%   propertyr   r   r,   r-   r.   r/   r   r   r   r   r      s    


	


r   )
__future__r   systypingr   Zpolars._utils.variousr   r   r   Zpolars._utils.wrapr   Zpolars.schemar   Zpolars.series.utilsr	   collections.abcr
   Zpolarsr   r   Zpolars._plrr   modulesr0   Zcurrent_moduler5   r   r   r   r   r   <module>   s     
