σ
    ΰ'·h 7  γ                  σ    S SK Jr  S SK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Jr  S SKJr  S S	KJr   " S
 S5      rg)ι    )ΪannotationsN)ΪTYPE_CHECKING)Ϊparse_into_list_of_expressions)Ϊqualified_type_name)Ϊ	wrap_expr)ΪIterableΪSequence)ΪExpr)ΪIntoExprc                  σn    \ rS rSrSrSrSS jrSS jrSS jrSS jr	SS jr
SS	 jr      SS
 jrSrg)ΪExprStructNameSpaceι   z)Namespace for struct related expressions.Ϊstructc                σ&    UR                   U l         g )N©Ϊ_pyexpr)ΪselfΪexprs     ΪeC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\polars/expr/struct.pyΪ__init__ΪExprStructNameSpace.__init__   s    Ψ||σ    c                σώ    [        U[        5      (       a  U R                  U5      $ [        U[        5      (       a$  [	        U R
                  R                  U5      5      $ S[        U5      < SU< S3n[        U5      e)Nzexpected type 'int | str', got z (Ϊ))	Ϊ
isinstanceΪstrΪfieldΪintr   r   Ϊstruct_field_by_indexr   Ϊ	TypeError)r   ΪitemΪmsgs      r   Ϊ__getitem__ΪExprStructNameSpace.__getitem__   sn    άdCΧ Ρ Ψ::dΣ#Π#άcΧ"Ρ"άT\\Χ?Ρ?ΐΣEΣFΠFΰ3Τ4GΘΣ4MΡ3PΠPRΠSWΡRZΠZ[Π\CάC.Π r   c                σ   U(       a  / [        U[        5      (       a  U/OUQUQn[        U[        5      (       a$  [        U R                  R                  U5      5      $ [        U R                  R                  U5      5      $ )uϋ  
Retrieve one or multiple `Struct` field(s) as a new Series.

Parameters
----------
name
    Name of the struct field to retrieve.
*more_names
    Additional struct field names.

Examples
--------
>>> df = pl.DataFrame(
...     {
...         "aaa": [1, 2],
...         "bbb": ["ab", "cd"],
...         "ccc": [True, None],
...         "ddd": [[1, 2], [3]],
...     }
... ).select(pl.struct("aaa", "bbb", "ccc", "ddd").alias("struct_col"))
>>> df
shape: (2, 1)
ββββββββββββββββββββββββ
β struct_col           β
β ---                  β
β struct[4]            β
ββββββββββββββββββββββββ‘
β {1,"ab",true,[1, 2]} β
β {2,"cd",null,[3]}    β
ββββββββββββββββββββββββ

Retrieve struct field(s) as Series:

>>> df.select(pl.col("struct_col").struct.field("bbb"))
shape: (2, 1)
βββββββ
β bbb β
β --- β
β str β
βββββββ‘
β ab  β
β cd  β
βββββββ

>>> df.select(
...     pl.col("struct_col").struct.field("bbb"),
...     pl.col("struct_col").struct.field("ddd"),
... )
shape: (2, 2)
βββββββ¬ββββββββββββ
β bbb β ddd       β
β --- β ---       β
β str β list[i64] β
βββββββͺββββββββββββ‘
β ab  β [1, 2]    β
β cd  β [3]       β
βββββββ΄ββββββββββββ

Use wildcard expansion:

>>> df.select(pl.col("struct_col").struct.field("*"))
shape: (2, 4)
βββββββ¬ββββββ¬βββββββ¬ββββββββββββ
β aaa β bbb β ccc  β ddd       β
β --- β --- β ---  β ---       β
β i64 β str β bool β list[i64] β
βββββββͺββββββͺβββββββͺββββββββββββ‘
β 1   β ab  β true β [1, 2]    β
β 2   β cd  β null β [3]       β
βββββββ΄ββββββ΄βββββββ΄ββββββββββββ

Retrieve multiple fields by name:

>>> df.select(pl.col("struct_col").struct.field("aaa", "bbb"))
shape: (2, 2)
βββββββ¬ββββββ
β aaa β bbb β
β --- β --- β
β i64 β str β
βββββββͺββββββ‘
β 1   β ab  β
β 2   β cd  β
βββββββ΄ββββββ

Retrieve multiple fields by regex expansion:

>>> df.select(pl.col("struct_col").struct.field("^a.*|b.*$"))
shape: (2, 2)
βββββββ¬ββββββ
β aaa β bbb β
β --- β --- β
β i64 β str β
βββββββͺββββββ‘
β 1   β ab  β
β 2   β cd  β
βββββββ΄ββββββ

Notes
-----
The `struct` namespace has implemented `__getitem__`
so you can also access fields by index:

>>> df.select(pl.col("struct_col").struct[1])
shape: (2, 1)
βββββββ
β bbb β
β --- β
β str β
βββββββ‘
β ab  β
β cd  β
βββββββ
)r   r   Ϊlistr   r   Ϊstruct_multiple_fieldsΪstruct_field_by_name)r   ΪnameΪ
more_namess      r   r   ΪExprStructNameSpace.field"   sh    φd ΨN€
¨4΄Χ 5Ρ 5tfΈ4ΠNΐ:ΠNDάdDΧ!Ρ!άT\\Χ@Ρ@ΐΣFΣGΠGδΧ:Ρ:Έ4Σ@ΣAΠAr   c                σ$    U R                  S5      $ )u  
Expand the struct into its individual fields.

Alias for `Expr.struct.field("*")`.

>>> df = pl.DataFrame(
...     {
...         "aaa": [1, 2],
...         "bbb": ["ab", "cd"],
...         "ccc": [True, None],
...         "ddd": [[1, 2], [3]],
...     }
... ).select(pl.struct("aaa", "bbb", "ccc", "ddd").alias("struct_col"))
>>> df
shape: (2, 1)
ββββββββββββββββββββββββ
β struct_col           β
β ---                  β
β struct[4]            β
ββββββββββββββββββββββββ‘
β {1,"ab",true,[1, 2]} β
β {2,"cd",null,[3]}    β
ββββββββββββββββββββββββ
>>> df.select(pl.col("struct_col").struct.unnest())
shape: (2, 4)
βββββββ¬ββββββ¬βββββββ¬ββββββββββββ
β aaa β bbb β ccc  β ddd       β
β --- β --- β ---  β ---       β
β i64 β str β bool β list[i64] β
βββββββͺββββββͺβββββββͺββββββββββββ‘
β 1   β ab  β true β [1, 2]    β
β 2   β cd  β null β [3]       β
βββββββ΄ββββββ΄βββββββ΄ββββββββββββ
Ϊ*)r   ©r   s    r   ΪunnestΪExprStructNameSpace.unnest   s    πF zz#Πr   c                σJ    [        U R                  R                  U5      5      $ )u  
Rename the fields of the struct.

Parameters
----------
names
    New names, given in the same order as the struct's fields.

Examples
--------
>>> df = pl.DataFrame(
...     {
...         "aaa": [1, 2],
...         "bbb": ["ab", "cd"],
...         "ccc": [True, None],
...         "ddd": [[1, 2], [3]],
...     }
... ).select(pl.struct("aaa", "bbb", "ccc", "ddd").alias("struct_col"))
>>> df
shape: (2, 1)
ββββββββββββββββββββββββ
β struct_col           β
β ---                  β
β struct[4]            β
ββββββββββββββββββββββββ‘
β {1,"ab",true,[1, 2]} β
β {2,"cd",null,[3]}    β
ββββββββββββββββββββββββ

>>> df.unnest("struct_col")
shape: (2, 4)
βββββββ¬ββββββ¬βββββββ¬ββββββββββββ
β aaa β bbb β ccc  β ddd       β
β --- β --- β ---  β ---       β
β i64 β str β bool β list[i64] β
βββββββͺββββββͺβββββββͺββββββββββββ‘
β 1   β ab  β true β [1, 2]    β
β 2   β cd  β null β [3]       β
βββββββ΄ββββββ΄βββββββ΄ββββββββββββ

Rename fields:

>>> df = df.select(
...     pl.col("struct_col").struct.rename_fields(["www", "xxx", "yyy", "zzz"])
... )
>>> df.unnest("struct_col")
shape: (2, 4)
βββββββ¬ββββββ¬βββββββ¬ββββββββββββ
β www β xxx β yyy  β zzz       β
β --- β --- β ---  β ---       β
β i64 β str β bool β list[i64] β
βββββββͺββββββͺβββββββͺββββββββββββ‘
β 1   β ab  β true β [1, 2]    β
β 2   β cd  β null β [3]       β
βββββββ΄ββββββ΄βββββββ΄ββββββββββββ

Following a rename, the previous field names (obviously) cannot be referenced:

>>> df.select(pl.col("struct_col").struct.field("aaa"))  # doctest: +SKIP
StructFieldNotFoundError: aaa
)r   r   Ϊstruct_rename_fields)r   Ϊnamess     r   Ϊrename_fieldsΪ!ExprStructNameSpace.rename_fieldsΐ   s    τ| Χ:Ρ:Έ5ΣAΣBΠBr   c                σH    [        U R                  R                  5       5      $ )u  
Convert this struct to a string column with json values.

Examples
--------
>>> pl.DataFrame(
...     {"a": [{"a": [1, 2], "b": [45]}, {"a": [9, 1, 3], "b": None}]}
... ).with_columns(pl.col("a").struct.json_encode().alias("encoded"))
shape: (2, 2)
ββββββββββββββββββββ¬βββββββββββββββββββββββββ
β a                β encoded                β
β ---              β ---                    β
β struct[2]        β str                    β
ββββββββββββββββββββͺβββββββββββββββββββββββββ‘
β {[1, 2],[45]}    β {"a":[1,2],"b":[45]}   β
β {[9, 1, 3],null} β {"a":[9,1,3],"b":null} β
ββββββββββββββββββββ΄βββββββββββββββββββββββββ
)r   r   Ϊstruct_json_encoder.   s    r   Ϊjson_encodeΪExprStructNameSpace.json_encode   s    τ& Χ8Ρ8Σ:Σ;Π;r   c                σΜ    [        [        [        R                  R	                  SS5      5      5      n[        U0 UDSU0D6n[        U R                  R                  U5      5      $ )u	  
Add or overwrite fields of this struct.

This is similar to `with_columns` on `DataFrame`.

.. versionadded:: 0.20.27

Examples
--------
>>> df = pl.DataFrame(
...     {
...         "coords": [{"x": 1, "y": 4}, {"x": 4, "y": 9}, {"x": 9, "y": 16}],
...         "multiply": [10, 2, 3],
...     }
... )
>>> df
shape: (3, 2)
βββββββββββββ¬βββββββββββ
β coords    β multiply β
β ---       β ---      β
β struct[2] β i64      β
βββββββββββββͺβββββββββββ‘
β {1,4}     β 10       β
β {4,9}     β 2        β
β {9,16}    β 3        β
βββββββββββββ΄βββββββββββ
>>> df = df.with_columns(
...     pl.col("coords").struct.with_fields(
...         pl.field("x").sqrt(),
...         y_mul=pl.field("y") * pl.col("multiply"),
...     )
... )
>>> df
shape: (3, 2)
βββββββββββββββ¬βββββββββββ
β coords      β multiply β
β ---         β ---      β
β struct[3]   β i64      β
βββββββββββββββͺβββββββββββ‘
β {1.0,4,40}  β 10       β
β {2.0,9,18}  β 2        β
β {3.0,16,48} β 3        β
βββββββββββββββ΄βββββββββββ
>>> df.unnest("coords")
shape: (3, 4)
βββββββ¬ββββββ¬ββββββββ¬βββββββββββ
β x   β y   β y_mul β multiply β
β --- β --- β ---   β ---      β
β f64 β i64 β i64   β i64      β
βββββββͺββββββͺββββββββͺβββββββββββ‘
β 1.0 β 4   β 40    β 10       β
β 2.0 β 9   β 18    β 2        β
β 3.0 β 16  β 48    β 3        β
βββββββ΄ββββββ΄ββββββββ΄βββββββββββ

Parameters
----------
*exprs
    Field(s) to add, specified as positional arguments.
    Accepts expression input. Strings are parsed as column names, other
    non-expression inputs are parsed as literals.
**named_exprs
    Additional fields to add, specified as keyword arguments.
    The columns will be renamed to the keyword used.

See Also
--------
field
ΪPOLARS_AUTO_STRUCTIFYr   Ϊ__structify)	Ϊboolr   ΪosΪenvironΪgetr   r   r   Ϊstruct_with_fields)r   ΪexprsΪnamed_exprsΪ	structifyΪpyexprss        r   Ϊwith_fieldsΪExprStructNameSpace.with_fields  s]    τT RZZ^^Π,CΐQΣGΣHΣI	δ0Ψπ
Ψ!ρ
Ψ/8ς
τ Χ8Ρ8ΈΣAΣBΠBr   r   N)r   r
   ΪreturnΪNone)r!   z	str | intrH   r
   )r)   zstr | list[str]r*   r   rH   r
   )rH   r
   )r3   zSequence[str]rH   r
   )rB   zIntoExpr | Iterable[IntoExpr]rC   r   rH   r
   )Ϊ__name__Ϊ
__module__Ϊ__qualname__Ϊ__firstlineno__Ϊ__doc__Ϊ	_accessorr   r#   r   r/   r4   r8   rF   Ϊ__static_attributes__© r   r   r   r      sW    Ω3ΰIτ$τ!τwBτr#τJ>Cτ@<π*PCΰ-πPCπ  πPCπ 
χ	PCr   r   )Ϊ
__future__r   r>   Ϊtypingr   Ϊpolars._utils.parser   Ϊpolars._utils.variousr   Ϊpolars._utils.wrapr   Ϊcollections.abcr   r	   Ϊpolarsr
   Ϊpolars._typingr   r   rQ   r   r   Ϊ<module>rZ      s1   πέ "γ 	έ  ε >έ 5έ (ζί2εέ'χTCς TCr   