
    q-Ph                    N   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j        dk    rd dlmZ nd dlmZ ej        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"dS )    )annotationsN)OrderedDict)Mapping)TYPE_CHECKINGLiteralUnionoverload)PythonDataType)DataTypeDataTypeClassis_polars_dtype)parse_into_dtype)Iterable	DataFrame	LazyFrame)   
   )	TypeAliastpr   returnboolc                *    t          | j                  S N)r   __annotations__r   s    M/var/www/html/test/jupyter/venv/lib/python3.11/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SchemaDataType | DataTypeClassr   c                    t          | t                    sU|                                 s#|                                 st	          |           rd| }t          |           |             } | S )Nz%dtypes must be fully-specified, got: )
isinstancer   	is_nested
is_decimalr   	TypeError)r   msgs     r   _check_dtyper,   *   sl    b(## <<>> 	!R]]__ 	!0CB0G0G 	!@"@@CC.. RTT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d0d#Zd1d%Zd2d'Z xZS )3r$   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
    NT)check_dtypesschemaRMapping[str, SchemaInitDataType] | Iterable[tuple[str, SchemaInitDataType]] | Noner.   r   r   Nonec               D   t          |t                    r|                                n|pd}|D ]n\  }}|s#t                                          ||           *t          |          r0t                                          |t          |                     i|| |<   od S )N )r'   r   itemssuper__setitem__r   r,   )selfr/   r.   inputnamer   	__class__s         r   r!   zSchema.__init__[   s     #-VW"="=QFLb 	  	 HD"  ##D"---- $$  ##D,r*:*:;;;;T

	  	 r   otherobjectc                4   t          |t                    sdS t          |           t          |          k    rdS t          |                                 |                                          D ])\  \  }}\  }}||k    s|                    |          s dS *dS )NFT)r'   r   lenzipr4   is_)r7   r;   nm1tp1nm2tp2s         r   __eq__zSchema.__eq__n   s    %)) 	5t99E

""5&)$**,,&F&F 	 	"JS#
cczzzuu tr   c                .    |                      |           S r   )rE   )r7   r;   s     r   __ne__zSchema.__ne__x   s    ;;u%%%%r   r9   strdtype)DataType | DataTypeClass | PythonDataTypec                    t          t          |                    }t                                          ||           d S r   )r,   r   r5   r6   )r7   r9   rI   r:   s      r   r6   zSchema.__setitem__{   s;     -e4455D%(((((r   	list[str]c                D    t          |                                           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r7   s    r   nameszSchema.names   s     DIIKK   r   list[DataType]c                D    t          |                                           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)]
        )rN   valuesrP   s    r   dtypeszSchema.dtypes   s     DKKMM"""r   .)eagerrV   Literal[False]r   c                   d S r   r3   r7   rV   s     r   to_framezSchema.to_frame   s    EHSr   Literal[True]r   c                   d S r   r3   rY   s     r   rZ   zSchema.to_frame   s    >Acr   DataFrame | LazyFramec               F    ddl m}m} |r ||           n ||           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   )r/   )polarsr   r   )r7   rV   r   r   s       r   rZ   zSchema.to_frame   sF    . 	0///////).Jyy%%%%IIT4J4J4JJr   intc                     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
        )r>   rP   s    r   r>   z
Schema.len   s     4yyr   dict[str, type]c                >    d |                                  D             S )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'>}
        c                >    i | ]\  }}||                                 S r3   )	to_python).0r9   r   s      r   
<dictcomp>z$Schema.to_python.<locals>.<dictcomp>   s&    BBBrbllnnBBBr   )r4   rP   s    r   re   zSchema.to_python   s!      CBTZZ\\BBBBr   r   )r/   r0   r.   r   r   r1   )r;   r<   r   r   )r9   rH   rI   rJ   r   r1   )r   rL   )r   rR   )rV   rW   r   r   )rV   r[   r   r   )rV   r   r   r]   )r   r`   )r   rb   )__name__
__module____qualname____doc__r!   rE   rG   r6   rQ   rU   r	   rZ   r>   re   __classcell__)r:   s   @r   r$   r$   4   s]       $ $X   "               &   & & & &) ) ) ) ) )
! 
! 
! 
!
# 
# 
# 
# 25HHHHH XHAAA XA(, K K K K K K6   C C C C C C C Cr   )r   r   r   r   )r   r%   r   r   )#
__future__r   syscollectionsr   collections.abcr   typingr   r   r   r	   polars._typingr
   polars.datatypesr   r   r   polars.datatypes._parser   r   r_   r   r   version_infor   typing_extensionsr   rH   
BaseSchemar#   r   __all__r,   r$   r3   r   r   <module>ry      s   " " " " " " " 



 # # # # # # # # # # # # : : : : : : : : : : : : ) ) ) ) ) ) E E E E E E E E E E 4 4 4 4 4 4 0((((((++++++++
7""$$$$$$$//////w( ( ( ( () ) ) ) h'
 %h~&M N  N N N N*   dC dC dC dC dCZ dC dC dC dC dCr   