
    .h                       U d dl mZ d dl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 d dlmZmZmZ d d	lmZ d d
lmZ d dlmZ  ej6                  e      5  d dlmZmZm Z  ddd       e	r0d dlm!Z! d dl"m#Z#m$Z$ d dlm%Z% ejL                  dk\  rd dlm'Z' nd dl(m'Z' ejL                  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+      Z0y# 1 sw Y   zxY w)    )annotationsN)OrderedDict)Mapping)TYPE_CHECKINGLiteralUnionoverload)PythonDataType)unstable)DataTypeDataTypeClassis_polars_dtype)parse_into_dtype)DuplicateError)CompatLevel)&init_polars_schema_from_arrow_c_schema'polars_schema_field_from_arrow_c_schemapolars_schema_to_pycapsule)Iterable	DataFrame	LazyFrame)ArrowSchemaExportable)   
   )	TypeAliasc                ,    t        | j                        S N)bool__annotations__tps    K/var/www/html/ai-service/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_dtyper1   6   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 e       dd       Z	dd	Z
dd
Zedd       Zedddd       ZddddZddZddZ xZS )r*   aA  
    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, or any
        object implementing the  `__arrow_c_schema__` PyCapsule interface
        (e.g. pyarrow schemas).

    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

    Import a pyarrow schema.

    >>> import pyarrow as pa
    >>> pl.Schema(pa.schema([pa.field("x", pa.int32())]))
    Schema({'x': Int32})

    Export a schema to pyarrow.

    >>> pa.schema(pl.Schema({"x": pl.Int32}))
    x: int32
    T)check_dtypesc                  t        |d      rt        |t              st        | |       y t        |t              r|j                         n|xs d}|D ]  }t        |d      rt        |t              st        |      n|\  }}|| v rd| d}t        |      |st        | )  ||       Wt        |      rt        | )  |t        |             ||| |<    y )N__arrow_c_schema__ z7iterable passed to pl.Schema contained duplicate name '')hasattrr,   r*   r   r   itemsr   r   r   super__setitem__r   r1   )	selfschemar3   inputvnamer"   r0   	__class__s	           r#   r'   zSchema.__init__t   s     6/0FF9S24@",VW"=FLb 	 A 123Jq(<S 8: D" t|OPTvUVW$S))#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zipr9   is_)r<   othernm1tp1nm2tp2s         r#   __eq__zSchema.__eq__   sj    %)t9E
"&)$**,&F 	"JS#
ccz	 r%   c                &    | j                  |       S r   )rK   )r<   rF   s     r#   __ne__zSchema.__ne__   s    ;;u%%%r%   c                N    t        t        |            }t        |   ||       y r   )r1   r   r:   r;   )r<   r@   dtyperA   s      r#   r;   zSchema.__setitem__   s$     -e45D%(r%   c                R    t        | t        j                         j                        S )z
        Export a Schema via the Arrow PyCapsule Interface.

        https://arrow.apache.org/docs/dev/format/CDataInterface/PyCapsuleInterface.html
        )r   r   newest_versionr<   s    r#   r5   zSchema.__arrow_c_schema__   s      *$0B0B0D0M0MNNr%   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keysrS   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)]
        )rU   valuesrS   s    r#   dtypeszSchema.dtypes   s     DKKM""r%   c                    y r   r6   r<   eagers     r#   to_framezSchema.to_frame   s    ?Br%   .)r]   c                    y r   r6   r\   s     r#   r^   zSchema.to_frame   s    DGr%   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   )r=   )polarsr   r   )r<   r]   r   r   s       r#   r^   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
        )rC   rS   s    r#   rC   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'>}
        )r9   	to_python)r<   r@   r"   s      r#   rd   zSchema.to_python   s-      6:ZZ\Brblln$BBBs   3r   )r=   zMapping[str, SchemaInitDataType] | Iterable[tuple[str, SchemaInitDataType] | ArrowSchemaExportable] | ArrowSchemaExportable | Noner3   r   returnNone)rF   objectre   r   )r@   strrO   z)DataType | DataTypeClass | PythonDataTypere   rf   )re   rg   )re   z	list[str])re   zlist[DataType])r]   zLiteral[False]re   r   )r]   zLiteral[True]re   r   )r]   r   re   zDataFrame | LazyFrame)re   int)re   zdict[str, type])__name__
__module____qualname____doc__r'   rK   rM   r;   r   r5   rW   rZ   r	   r^   rC   rd   __classcell__)rA   s   @r#   r*   r*   @   s    1t    "        
  D&)) I)	) ZO O
!
# B B14G G(, K6Cr%   )r"   r   re   r   )r"   zDataType | DataTypeClassre   r   )1
__future__r   
contextlibsyscollectionsr   collections.abcr   typingr   r   r   r	   polars._typingr
   polars._utils.unstabler   polars.datatypesr   r   r   polars.datatypes._parser   polars.exceptionsr   polars.interchange.protocolr   suppressImportErrorpolars._plrr   r   r   r   ra   r   r   r   version_infor   typing_extensionsr$   rh   
BaseSchemar)   r    __all__r1   r*   r6   r%   r#   <module>r      s    "  
 # # : : ) + E E 4 , 3Z%   (+4
7"$/w() h'
 %h~&M N I N*ICZ ICa s   "C&&C/