o
    i                     @  s*  d dl mZ d dlZd dlZd dlmZmZmZmZmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZmZmZmZmZ d dlmZ d dlmZ d d	lmZmZmZmZm Z  d d
l!m"Z" e#e$ d dl%m&Z' W d   n1 stw   Y  e
rd dl(m)Z) d dl*m+Z+m,Z, 	ddddddZ-dS )    )annotationsN)datedatetimetime	timedeltatimezone)TYPE_CHECKINGAny)ZoneInfo)_check_for_numpy_check_for_pytz_check_for_torchpytztorch)numpy)	wrap_expr)BaseExtensionDateDatetimeDurationObject)DataTypeMappings)Expr)PolarsDataTypeTimeUnitF)allow_objectvaluer	   dtypePolarsDataType | Noner   boolreturnr   c                C  s4  t |trt| | j|S t |tr$t|tr$d| d}t||t	kr<t
jd| g|d}ttj|j|ddS t | tr|tkrRttj|  dddS |d	urct|d
d }d	urc|}nd}t|dd	}| j}|d	u ru|}	n[|d	u rt |tst|rt |tjjr|jd	urt|}	n=| tj} d}	n4t||krt|}	n)t|drtt|| ddt|| ddkr|}	nd|d|d}t|| jtjd}
t
d|
g t!|}|	d	ur|j"j#|	| j$dkrdndd}ttj|jddd}|S t | t%r4t
d| g}|d	ur't|d
d	 }d	ur'| t&|}ttj|jddd}|S t | t'rDttj| dddS t | tr|t!krt|d
dpWd}t| j(| j)| j*}
t
d|
g t!|}t|dd	 }d	ur|j"#t|}ttj|jddd}|S ttj| dddS t | t
jr| j} ttj| |ddS t+| rt | t,j-rtt
jd| |dS t.| rt | t/j0rtt
jd| j1dd|dS t | t2t3frttjt
jd| g|dj|ddS t | t4j5rt| j6|dS |rt
d| g |}ttj|j|ddS t+| rt | t,j7rt | 8  }ttt%fr8t|S t |t9rvt| drv| j:j;}|<dr_|t=dd }t| t!|S |<drv|t=dd }t| t&|S t>j?@| j:jA| j:jBf}|d	urt| |dS n| }ttj||ddS )a}  
    Return an expression representing a literal value.

    Parameters
    ----------
    value
        Value that should be used as a `literal`.
    dtype
        The data type of the resulting expression.
        If set to `None` (default), the data type is inferred from the `value` input.
    allow_object
        If type is unknown use an 'object' type.
        By default, we will raise a `ValueException`
        if the type is unknown.

    Notes
    -----
    Expected datatypes:

    - `pl.lit([])` -> empty List<Null>
    - `pl.lit([1, 2, 3])` -> List<i64>
    - `pl.lit(pl.Series([]))`-> empty Series Null
    - `pl.lit(pl.Series([1, 2, 3]))` -> Series Int64
    - `pl.lit(None)` -> Null

    Examples
    --------
    Literal scalar values:

    >>> pl.lit(1)  # doctest: +IGNORE_RESULT
    >>> pl.lit(5.5)  # doctest: +IGNORE_RESULT
    >>> pl.lit(None)  # doctest: +IGNORE_RESULT
    >>> pl.lit("foo_bar")  # doctest: +IGNORE_RESULT
    >>> pl.lit(date(2021, 1, 20))  # doctest: +IGNORE_RESULT
    >>> pl.lit(datetime(2023, 3, 31, 10, 30, 45))  # doctest: +IGNORE_RESULT

    Literal list/Series data (1D):

    >>> pl.lit([1, 2, 3])  # doctest: +SKIP
    >>> pl.lit(pl.Series("x", [1, 2, 3]))  # doctest: +IGNORE_RESULT

    Literal list/Series data (2D):

    >>> pl.lit([[1, 2], [3, 4]])  # doctest: +SKIP
    >>> pl.lit(pl.Series("y", [[1, 2], [3, 4]]))  # doctest: +IGNORE_RESULT
    zdtype 'z4' is a BaseExtension class, it should be an instanceliteral)r   T)	is_scalarF)r   r"   N	time_unitus	time_zoneUTC	utcoffsetsecondsr      ztime zone of dtype (z#) differs from time zone of value ())tzinfoZearliestZlatest)Z	ambiguous)forcer   zdatetime64[ztimedelta64[)C
isinstancer   litZext_storageexttotype
issubclass	TypeErrorr   plZSeriesr   plrZ_sr   r   r   getattrr+   r
   r   r   Z
BaseTzInfozonestr
astimezoner   utchasattrr'   replacecastr   dtZreplace_time_zonefoldr   r   r   yearmonthdayr   npZndarrayr   r   ZTensorr   listtupleenumEnumr   Zgenericitemintr   name
startswithlenr   Z NUMPY_KIND_AND_ITEMSIZE_TO_DTYPEgetkinditemsize)r   r   r   msgZvalue_sZtur#   Zdtype_tzZvalue_tztzZdt_utcZdt_utc_sexprr%   rI   Z
dtype_name rT   K/home/app/Keep/.python/lib/python3.10/site-packages/polars/functions/lit.pyr/      s   
3



 

r/   )N)r   r	   r   r   r   r   r    r   ).
__future__r   
contextlibrG   r   r   r   r   r   typingr   r	   zoneinfor
   Zpolars._reexportZ	_reexportr5   Zpolars._dependenciesr   r   r   r   r   r   rD   Zpolars._utils.wrapr   Zpolars.datatypesr   r   r   r   r   Zpolars.datatypes.convertr   suppressImportErrorZpolars._plrZ_plrr6   Zpolarsr   Zpolars._typingr   r   r/   rT   rT   rT   rU   <module>   s,    