
    ˀh,                        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rd dlmZ d d	lmZmZ d d
lmZ nerej,                  e   Zee_        e G d d             Zy)    )annotationsN)TYPE_CHECKING)BUILDING_SPHINX_DOCSqualified_type_namesphinx_accessor)wrap_df)Schema)expr_dispatch)Sequence)	DataFrameSeries)PySeriesc                  p    e Zd ZdZdZddZddZddZedd       Z	ddZ
ddZedd	       Zdd
ZddZy)StructNameSpacezSeries.struct namespace.structc                &    |j                   | _         y N)_s)selfseriess     p/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/series/struct.py__init__zStructNameSpace.__init__!   s    "II    c                    t        |t              r| j                  | j                  |         S t        |t              r| j                  |      S dt        |      }t        |      )Nzexpected type 'int | str', got )
isinstanceintfieldfieldsstrr   	TypeError)r   itemmsgs      r   __getitem__zStructNameSpace.__getitem__$   sZ    dC ::dkk$/00c"::d##34G4M3PQCC. r   c                    | j                   S r   )r   r   s    r   _ipython_key_completions_z)StructNameSpace._ipython_key_completions_-   s    {{r   c                T    t        | dd      g S | j                  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   struct_fieldsr%   s    r   r   zStructNameSpace.fields0   s+     4t$,Iww$$&&r   c                     y)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
        ]
        N )r   names     r   r   zStructNameSpace.field?       r   c                     y)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   namess     r   rename_fieldszStructNameSpace.rename_fieldsT   r-   r   c                    t        | dd      t        i       S | j                  j                         j	                         }t        |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)check_dtypes)r(   r	   r   dtype	to_schema)r   schemas     r   r5   zStructNameSpace.schemag   sB     4t$,":**,f511r   c                H    t        | j                  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   struct_unnestr%   s    r   unnestzStructNameSpace.unnestx   s    $ tww,,.//r   c                     y)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%   s    r   json_encodezStructNameSpace.json_encode   r-   r   N)r   r   returnNone)r!   z	int | strr;   r   )r;   z	list[str])r,   r   r;   r   )r/   zSequence[str]r;   r   )r;   r	   )r;   r   )r;   r   )__name__
__module____qualname____doc__	_accessorr   r#   r&   propertyr   r   r0   r5   r8   r:   r+   r   r   r   r      sU    "I&! ' '*& 2 2 0(r   r   )
__future__r   systypingr   polars._utils.variousr   r   r   polars._utils.wrapr   polars.schemar	   polars.series.utilsr
   collections.abcr   polarsr   r   polars.polarsr   modulesr=   current_modulerB   r   r+   r   r   <module>rO      sf    " 
   
 '   -((& [[*N-N ~ ~ ~r   