
    ˀh                    J   U d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
mZ d dlmZ d dlmZmZmZ d dlmZ er*d d	lmZ d d
lmZmZ ej0                  dk\  rd dlmZ nd dlmZ ej0                  dk\  rddZnddZeeef   Ze
eeef   Zded<   dgZ ddZ! G d de      Z"y)    )annotationsN)OrderedDict)Mapping)TYPE_CHECKINGLiteralUnionoverload)PythonDataType)DataTypeDataTypeClassis_polars_dtype)parse_into_dtype)Iterable	DataFrame	LazyFrame)   
   )	TypeAliasc                ,    t        | j                        S N)bool__annotations__tps    i/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/schema.py_required_init_argsr      s     B&&''    c                    d| j                   v S )N__init__)__dict__r   s    r   r   r      s     R[[((r   r   SchemaInitDataTypeSchemac                    t        | t              sB| j                         s| j                         st	        |       rd| }t        |       |        } | S )Nz%dtypes must be fully-specified, got: )
isinstancer   	is_nested
is_decimalr   	TypeError)r   msgs     r   _check_dtyper*   *   sG    b(#<<>R]]_0CB0G9"@CC. TIr   c                       e Zd ZdZ	 ddd	 	 	 	 	 d fdZddZddZ	 	 	 	 	 	 d fdZddZdd	Z	e
d
ddd       Ze
dd       ZddddZddZddZ xZS )r#   a  
    Ordered mapping of column names to their data type.

    Parameters
    ----------
    schema
        The schema definition given by column names and their associated
        Polars data type. Accepts a mapping or an iterable of tuples.

    Examples
    --------
    Define a schema by passing instantiated data types.

    >>> schema = pl.Schema(
    ...     {
    ...         "foo": pl.String(),
    ...         "bar": pl.Duration("us"),
    ...         "baz": pl.Array(pl.Int8, 4),
    ...     }
    ... )
    >>> schema
    Schema({'foo': String, 'bar': Duration(time_unit='us'), 'baz': Array(Int8, shape=(4,))})

    Access the data type associated with a specific column name.

    >>> schema["baz"]
    Array(Int8, shape=(4,))

    Access various schema properties using the `names`, `dtypes`, and `len` methods.

    >>> schema.names()
    ['foo', 'bar', 'baz']
    >>> schema.dtypes()
    [String, Duration(time_unit='us'), Array(Int8, shape=(4,))]
    >>> schema.len()
    3
    T)check_dtypesc                   t        |t              r|j                         n|xs d}|D ]B  \  }}|st        |   ||       t        |      rt        |   |t        |             >|| |<   D y )N )r%   r   itemssuper__setitem__r   r*   )selfschemar,   inputnamer   	__class__s         r   r    zSchema.__init__[   si     #-VW"=FLb 	 HD"#D"- $#D,r*:;T
	 r   c                    t        |t              syt        |       t        |      k7  ryt        | j	                         |j	                               D ]#  \  \  }}\  }}||k7  s|j                  |      r# y y)NFT)r%   r   lenzipr/   is_)r2   othernm1tp1nm2tp2s         r   __eq__zSchema.__eq__n   sj    %)t9E
"&)$**,&F 	"JS#
ccz	 r   c                &    | j                  |       S r   )r@   )r2   r;   s     r   __ne__zSchema.__ne__x   s    ;;u%%%r   c                N    t        t        |            }t        |   ||       y r   )r*   r   r0   r1   )r2   r5   dtyper6   s      r   r1   zSchema.__setitem__{   s$     -e45D%(r   c                4    t        | j                               S )z
        Get the column names of the schema.

        Examples
        --------
        >>> s = pl.Schema({"x": pl.Float64(), "y": pl.Datetime(time_zone="UTC")})
        >>> s.names()
        ['x', 'y']
        )listkeysr2   s    r   nameszSchema.names   s     DIIK  r   c                4    t        | j                               S )z
        Get the data types of the schema.

        Examples
        --------
        >>> s = pl.Schema({"x": pl.UInt8(), "y": pl.List(pl.UInt8)})
        >>> s.dtypes()
        [UInt8, List(UInt8)]
        )rF   valuesrH   s    r   dtypeszSchema.dtypes   s     DKKM""r   .)eagerc                    y r   r.   r2   rM   s     r   to_framezSchema.to_frame   s    EHr   c                    y r   r.   rO   s     r   rP   zSchema.to_frame   s    >Ar   c               :    ddl m}m} |r	 ||       S  ||       S )u  
        Create an empty DataFrame (or LazyFrame) from this Schema.

        Parameters
        ----------
        eager
            If True, create a DataFrame; otherwise, create a LazyFrame.

        Examples
        --------
        >>> s = pl.Schema({"x": pl.Int32(), "y": pl.String()})
        >>> s.to_frame()
        shape: (0, 2)
        ┌─────┬─────┐
        │ x   ┆ y   │
        │ --- ┆ --- │
        │ i32 ┆ str │
        ╞═════╪═════╡
        └─────┴─────┘
        >>> s.to_frame(eager=False)  # doctest: +IGNORE_RESULT
        <LazyFrame at 0x11BC0AD80>
        r   r   )r3   )polarsr   r   )r2   rM   r   r   s       r   rP   zSchema.to_frame   s    . 	0).y%JIT4JJr   c                    t        |       S )z
        Get the number of schema entries.

        Examples
        --------
        >>> s = pl.Schema({"x": pl.Int32(), "y": pl.List(pl.String)})
        >>> s.len()
        2
        >>> len(s)
        2
        )r8   rH   s    r   r8   z
Schema.len   s     4yr   c                r    | j                         D ci c]  \  }}||j                          c}}S c c}}w )a  
        Return a dictionary of column names and Python types.

        Examples
        --------
        >>> s = pl.Schema(
        ...     {
        ...         "x": pl.Int8(),
        ...         "y": pl.String(),
        ...         "z": pl.Duration("us"),
        ...     }
        ... )
        >>> s.to_python()
        {'x': <class 'int'>, 'y':  <class 'str'>, 'z': <class 'datetime.timedelta'>}
        )r/   	to_python)r2   r5   r   s      r   rV   zSchema.to_python   s-      6:ZZ\Brblln$BBBs   3r   )r3   zRMapping[str, SchemaInitDataType] | Iterable[tuple[str, SchemaInitDataType]] | Noner,   r   returnNone)r;   objectrW   r   )r5   strrD   z)DataType | DataTypeClass | PythonDataTyperW   rX   )rW   z	list[str])rW   zlist[DataType])rM   zLiteral[False]rW   r   )rM   zLiteral[True]rW   r   )rM   r   rW   zDataFrame | LazyFrame)rW   int)rW   zdict[str, type])__name__
__module____qualname____doc__r    r@   rB   r1   rI   rL   r	   rP   r8   rV   __classcell__)r6   s   @r   r#   r#   4   s    $X   "     
 &&)) I)	)
!
# 25H HA A(, K6Cr   )r   r   rW   r   )r   zDataType | DataTypeClassrW   r   )#
__future__r   syscollectionsr   collections.abcr   typingr   r   r   r	   polars._typingr
   polars.datatypesr   r   r   polars.datatypes._parser   r   rS   r   r   version_infor   typing_extensionsr   rZ   
BaseSchemar"   r   __all__r*   r#   r.   r   r   <module>rm      s    " 
 # # : : ) E E 4(+
7"$/w() h'
 %h~&M N I N*dCZ dCr   