σ
    ΰ'·hG9  γ                  σ    S SK Jr  S SKJ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JrJrJrJr   " S	 S
5      rg)ι    )Ϊannotations)ΪTYPE_CHECKING)Ϊparse_into_expression)Ϊscale_bytes)Ϊ	wrap_expr)Ϊparse_into_datatype_expr)ΪDataTypeExprΪExpr)Ϊ
EndiannessΪIntoExprΪPolarsDataTypeΪSizeUnitΪTransferEncodingc                  σ    \ 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	.SS
 jjr
SS jrSSS jjrSS.     SS jjrSrg)ΪExprBinaryNameSpaceι   z&Namespace for bin related expressions.Ϊbinc                σ&    UR                   U l         g )N©Ϊ_pyexpr)ΪselfΪexprs     ΪeC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\polars/expr/binary.pyΪ__init__ΪExprBinaryNameSpace.__init__   s    Ψ||σ    c                σ^    [        USS9n[        U R                  R                  U5      5      $ )uP  
Check if binaries in Series contain a binary substring.

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

Returns
-------
Expr
    Expression of data type :class:`Boolean`.

See Also
--------
starts_with : Check if the binary substring exists at the start
ends_with : Check if the binary substring exists at the end

Examples
--------
>>> colors = pl.DataFrame(
...     {
...         "name": ["black", "yellow", "blue"],
...         "code": [b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"],
...         "lit": [b"\x00", b"\xff\x00", b"\xff\xff"],
...     }
... )
>>> colors.select(
...     "name",
...     pl.col("code").bin.contains(b"\xff").alias("contains_with_lit"),
...     pl.col("code").bin.contains(pl.col("lit")).alias("contains_with_expr"),
... )
shape: (3, 3)
ββββββββββ¬ββββββββββββββββββββ¬βββββββββββββββββββββ
β name   β contains_with_lit β contains_with_expr β
β ---    β ---               β ---                β
β str    β bool              β bool               β
ββββββββββͺββββββββββββββββββββͺβββββββββββββββββββββ‘
β black  β false             β true               β
β yellow β true              β true               β
β blue   β true              β false              β
ββββββββββ΄ββββββββββββββββββββ΄βββββββββββββββββββββ
T©Ϊ
str_as_lit)r   r   r   Ϊbin_contains)r   ΪliteralΪliteral_pyexprs      r   ΪcontainsΪExprBinaryNameSpace.contains   s+    τX /¨wΐ4ΡHάΧ2Ρ2°>ΣBΣCΠCr   c                σ^    [        USS9n[        U R                  R                  U5      5      $ )uΑ  
Check if string values end with a binary substring.

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

Returns
-------
Expr
    Expression of data type :class:`Boolean`.

See Also
--------
starts_with : Check if the binary substring exists at the start
contains : Check if the binary substring exists anywhere

Examples
--------
>>> colors = pl.DataFrame(
...     {
...         "name": ["black", "yellow", "blue"],
...         "code": [b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"],
...         "suffix": [b"\x00", b"\xff\x00", b"\x00\x00"],
...     }
... )
>>> colors.select(
...     "name",
...     pl.col("code").bin.ends_with(b"\xff").alias("ends_with_lit"),
...     pl.col("code").bin.ends_with(pl.col("suffix")).alias("ends_with_expr"),
... )
shape: (3, 3)
ββββββββββ¬ββββββββββββββββ¬βββββββββββββββββ
β name   β ends_with_lit β ends_with_expr β
β ---    β ---           β ---            β
β str    β bool          β bool           β
ββββββββββͺββββββββββββββββͺβββββββββββββββββ‘
β black  β false         β true           β
β yellow β false         β true           β
β blue   β true          β false          β
ββββββββββ΄ββββββββββββββββ΄βββββββββββββββββ
Tr   )r   r   r   Ϊbin_ends_with)r   ΪsuffixΪsuffix_pyexprs      r   Ϊ	ends_withΪExprBinaryNameSpace.ends_withL   s+    τX .¨fΐΡFάΧ3Ρ3°MΣBΣCΠCr   c                σ^    [        USS9n[        U R                  R                  U5      5      $ )u  
Check if values start with a binary substring.

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

Returns
-------
Expr
    Expression of data type :class:`Boolean`.

See Also
--------
ends_with : Check if the binary substring exists at the end
contains : Check if the binary substring exists anywhere

Examples
--------
>>> colors = pl.DataFrame(
...     {
...         "name": ["black", "yellow", "blue"],
...         "code": [b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"],
...         "prefix": [b"\x00", b"\xff\x00", b"\x00\x00"],
...     }
... )
>>> colors.select(
...     "name",
...     pl.col("code").bin.starts_with(b"\xff").alias("starts_with_lit"),
...     pl.col("code")
...     .bin.starts_with(pl.col("prefix"))
...     .alias("starts_with_expr"),
... )
shape: (3, 3)
ββββββββββ¬ββββββββββββββββββ¬βββββββββββββββββββ
β name   β starts_with_lit β starts_with_expr β
β ---    β ---             β ---              β
β str    β bool            β bool             β
ββββββββββͺββββββββββββββββββͺβββββββββββββββββββ‘
β black  β false           β true             β
β yellow β true            β false            β
β blue   β false           β true             β
ββββββββββ΄ββββββββββββββββββ΄βββββββββββββββββββ
Tr   )r   r   r   Ϊbin_starts_with)r   ΪprefixΪprefix_pyexprs      r   Ϊstarts_withΪExprBinaryNameSpace.starts_with{   s+    τ\ .¨fΐΡFάΧ5Ρ5°mΣDΣEΠEr   T)Ϊstrictc               σΜ    US:X  a$  [        U R                  R                  U5      5      $ US:X  a$  [        U R                  R                  U5      5      $ SU< 3n[	        U5      e)uΧ  
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
-------
Expr
    Expression of data type :class:`Binary`.

Examples
--------
>>> colors = pl.DataFrame(
...     {
...         "name": ["black", "yellow", "blue"],
...         "encoded": [b"000000", b"ffff00", b"0000ff"],
...     }
... )
>>> colors.with_columns(
...     pl.col("encoded").bin.decode("hex").alias("code"),
... )
shape: (3, 3)
ββββββββββ¬ββββββββββββ¬ββββββββββββββββββ
β name   β encoded   β code            β
β ---    β ---       β ---             β
β str    β binary    β binary          β
ββββββββββͺββββββββββββͺββββββββββββββββββ‘
β black  β b"000000" β b"\x00\x00\x00" β
β yellow β b"ffff00" β b"\xff\xff\x00" β
β blue   β b"0000ff" β b"\x00\x00\xff" β
ββββββββββ΄ββββββββββββ΄ββββββββββββββββββ
ΪhexΪbase64ϊ1`encoding` must be one of {'hex', 'base64'}, got )r   r   Ϊbin_hex_decodeΪbin_base64_decodeΪ
ValueError)r   Ϊencodingr1   Ϊmsgs       r   ΪdecodeΪExprBinaryNameSpace.decode¬   s_    πN uΣάT\\Χ8Ρ8ΈΣ@ΣAΠAΨΣ!άT\\Χ;Ρ;ΈFΣCΣDΠDΰGΘΑ|ΠTCάS/Π!r   c                σΘ    US:X  a#  [        U R                  R                  5       5      $ US:X  a#  [        U R                  R                  5       5      $ SU< 3n[	        U5      e)u[  
Encode a value using the provided encoding.

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

Returns
-------
Expr
    Expression of data type :class:`Binary`.

Examples
--------
>>> colors = pl.DataFrame(
...     {
...         "color": ["black", "yellow", "blue"],
...         "code": [b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"],
...     }
... )
>>> colors.with_columns(
...     pl.col("code").bin.encode("hex").alias("encoded"),
... )
shape: (3, 3)
ββββββββββ¬ββββββββββββββββββ¬ββββββββββ
β color  β code            β encoded β
β ---    β ---             β ---     β
β str    β binary          β str     β
ββββββββββͺββββββββββββββββββͺββββββββββ‘
β black  β b"\x00\x00\x00" β 000000  β
β yellow β b"\xff\xff\x00" β ffff00  β
β blue   β b"\x00\x00\xff" β 0000ff  β
ββββββββββ΄ββββββββββββββββββ΄ββββββββββ
r3   r4   r5   )r   r   Ϊbin_hex_encodeΪbin_base64_encoder8   )r   r9   r:   s      r   ΪencodeΪExprBinaryNameSpace.encodeΫ   s[    πH uΣάT\\Χ8Ρ8Σ:Σ;Π;ΨΣ!άT\\Χ;Ρ;Σ=Σ>Π>ΰGΘΑ|ΠTCάS/Π!r   c                σb    [        U R                  R                  5       5      n[        X!5      nU$ )uΉ  
Get the size of binary values in the given unit.

Parameters
----------
unit : {'b', 'kb', 'mb', 'gb', 'tb'}
    Scale the returned size to the given unit.

Returns
-------
Expr
    Expression of data type :class:`UInt32` or `Float64`.

Examples
--------
>>> from os import urandom
>>> df = pl.DataFrame({"data": [urandom(n) for n in (512, 256, 1024)]})
>>> df.with_columns(  # doctest: +IGNORE_RESULT
...     n_bytes=pl.col("data").bin.size(),
...     n_kilobytes=pl.col("data").bin.size("kb"),
... )
shape: (4, 3)
βββββββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββββ
β data                            β n_bytes β n_kilobytes β
β ---                             β ---     β ---         β
β binary                          β u32     β f64         β
βββββββββββββββββββββββββββββββββββͺββββββββββͺββββββββββββββ‘
β b"y?~B\x83\xf4V\x07\xd3\xfb\xbβ¦ β 512     β 0.5         β
β b"\xee$4@f\xc14\x07\x8e\x88\x1β¦ β 256     β 0.25        β
β b"\x80\xbd\xb9nEq;2\x99$\xf9\xβ¦ β 1024    β 1.0         β
βββββββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββββ
)r   r   Ϊbin_size_bytesr   )r   ΪunitΪszs      r   ΪsizeΪExprBinaryNameSpace.size  s+    τB t||Χ2Ρ2Σ4Σ5άΣ"Ψ	r   Ϊlittle)Ϊ
endiannessc               σv    [        U5      n[        U R                  R                  UR                  U5      5      $ )u1  
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
-------
Expr
    Expression 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
--------
>>> df = pl.DataFrame({"data": [b"\x05\x00\x00\x00", b"\x10\x00\x01\x00"]})
>>> df.with_columns(  # doctest: +IGNORE_RESULT
...     bin2int=pl.col("data").bin.reinterpret(
...         dtype=pl.Int32, endianness="little"
...     ),
... )
shape: (2, 2)
βββββββββββββββββββββββ¬ββββββββββ
β data                β bin2int β
β ---                 β ---     β
β binary              β i32     β
βββββββββββββββββββββββͺββββββββββ‘
β b"\x05\x00\x00\x00" β 5       β
β b"\x10\x00\x01\x00" β 65552   β
βββββββββββββββββββββββ΄ββββββββββ
)r   r   r   Ϊbin_reinterpretΪ_pydatatype_expr)r   ΪdtyperI   s      r   ΪreinterpretΪExprBinaryNameSpace.reinterpret,  s6    τT )¨Σ/δΨLLΧ(Ρ(¨Χ)?Ρ)?ΐΣLσ
π 	
r   r   N)r   r
   ΪreturnΪNone)r!   r   rP   r
   )r'   r   rP   r
   )r-   r   rP   r
   )r9   r   r1   ΪboolrP   r
   )r9   r   rP   r
   )Ϊb)rD   r   rP   r
   )rM   zPolarsDataType | DataTypeExprrI   r   rP   r
   )Ϊ__name__Ϊ
__module__Ϊ__qualname__Ϊ__firstlineno__Ϊ__doc__Ϊ	_accessorr   r#   r)   r/   r;   r@   rF   rN   Ϊ__static_attributes__© r   r   r   r      sf    Ω0ΰIτ$τ-Dτ^-Dτ^/Fπb DHχ -"τ^*"φX#πL QYρ.
Ψ5π.
ΨCMπ.
ΰ	χ.
π .
r   r   N)Ϊ
__future__r   Ϊtypingr   Ϊpolars._utils.parser   Ϊpolars._utils.variousr   Ϊpolars._utils.wrapr   Ϊpolars.datatypesr   Ϊpolarsr	   r
   Ϊpolars._typingr   r   r   r   r   r   r[   r   r   Ϊ<module>rd      s3   πέ "ε  ε 5έ -έ (έ 5ζί)χυ χE
ς E
r   