
    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
 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 d dlmZ  ej        e          5  d dlmZmZm Z  ddd           n# 1 swxY w Y   erd dlm!Z! d dlm"Z" d dl#Z$d dl%m&Z&m'Z' d dlm(Z( nd dl)m#Z$ ddZ*ee+ef         Z,eez  ez  Z-de.d<   dgZ/d dZ0 G d de,          Z1dS )!    )annotationsN)OrderedDict)Mapping)TYPE_CHECKINGLiteraloverload)PythonDataType)unstable)DataTypeDataTypeClassis_polars_dtype)parse_into_dtype)unpack_dtypes)DuplicateError)CompatLevel)&init_polars_schema_from_arrow_c_schema'polars_schema_field_from_arrow_c_schemapolars_schema_to_pycapsule)Iterable)	TypeAlias	DataFrame	LazyFrame)ArrowSchemaExportable)pyarrowtpr   returnboolc                *    t          | j                  S N)r   __annotations__)r   s    R/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/polars/schema.py_required_init_argsr#   #   s    "###    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	 d1ddd2 fdZd3dZd3dZd4 fdZ e            d5d            Z	d6dZ
d7dZ e            ddd8d            Zed9d"            Zed#d$d:d'            Zdd$d;d)Zd<d+Zd=d-Zd>d0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
    NT)check_dtypesschemaMapping[str, SchemaInitDataType] | Iterable[tuple[str, SchemaInitDataType] | ArrowSchemaExportable] | ArrowSchemaExportable | Noner0   r   r   Nonec               P   t          |d          r't          |t                    st          | |           d S t          |t                    r|                                n|pd}|D ]}t          |d          r$t          |t                    st          |          n|\  }}|| v rd| d}t          |          |s#t                      
                    ||           yt          |          r0t                      
                    |t          |                     || |<   d S )N__arrow_c_schema__ z7iterable passed to pl.Schema contained duplicate name '')hasattrr)   r&   r   r   itemsr   r   r   super__setitem__r   r.   )	selfr1   r0   inputvnamer   r-   	__class__s	           r"   __init__zSchema.__init__k   sK    6/00 	FF9S9S 	24@@@F",VW"="=QFLb 	  	 A 1233<Fq(<S<S7::: D" t||WPTWWW$S)))  ##D"---- $$  ##D,r*:*:;;;;T

!	  	 r$   otherobjectc                8   t          |t                    sdS t          |           t          |          k    rdS t          |                                 |                                d          D ])\  \  }}\  }}||k    s|                    |          s dS *dS )NFT)strict)r)   r   lenzipr9   is_)r<   rB   nm1tp1nm2tp2s         r"   __eq__zSchema.__eq__   s    %)) 	5t99E

""5&)$**,,d&S&S&S 	 	"JS#
cczzzuu tr$   c                .    |                      |           S r    )rM   )r<   rB   s     r"   __ne__zSchema.__ne__   s    ;;u%%%%r$   r?   strdtype)DataType | DataTypeClass | PythonDataTypec                    t          t          |                    }t                                          ||           d S r    )r.   r   r:   r;   )r<   r?   rQ   r@   s      r"   r;   zSchema.__setitem__   s;     -e4455D%(((((r$   c                N    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      *$0B0D0D0MNNNr$   	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keysrW   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)]
        )rZ   valuesrW   s    r"   dtypeszSchema.dtypes   s     DKKMM"""r$   )compat_levelra   CompatLevel | None	pa.Schemac                    G d d          }t          j         || |t          j                    n|                    S )aI  
        Convert the schema to a pyarrow schema.

        Parameters
        ----------
        compat_level
            Use a specific compatibility level
            when exporting Polars' internal data types.

        Examples
        --------
        >>> pl.Schema({"x": pl.String}).to_arrow()
        x: string_view
        c                      e Zd ZddZdd	Zd
S ).Schema.to_arrow.<locals>.SchemaCapsuleProviderr1   r&   ra   r   r   r3   c                "    || _         || _        d S r    )r1   ra   )r<   r1   ra   s      r"   rA   z7Schema.to_arrow.<locals>.SchemaCapsuleProvider.__init__   s    $$0!!!r$   rC   c                @    t          | j        | j        j                  S r    )r   r1   ra   rV   rW   s    r"   r5   zASchema.to_arrow.<locals>.SchemaCapsuleProvider.__arrow_c_schema__   s!    1K!2!;  r$   N)r1   r&   ra   r   r   r3   r   rC   )__name__
__module____qualname__rA   r5   r6   r$   r"   SchemaCapsuleProviderrf      s<        1 1 1 1     r$   rm   )par1   r   rU   )r<   ra   rm   s      r"   to_arrowzSchema.to_arrow   sh    "	 	 	 	 	 	 	 	 y!!l.Bk(*** 
 
 	
r$   eagerLiteral[False]r   c                   d S r    r6   r<   rp   s     r"   to_framezSchema.to_frame   s    ?Bsr$   .)rp   Literal[True]r   c                   d S r    r6   rs   s     r"   rt   zSchema.to_frame   s    DGCr$   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   )r1   )polarsr   r   )r<   rp   r   r   s       r"   rt   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
        )rF   rW   s    r"   rF   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 r6   )	to_python).0r?   r   s      r"   
<dictcomp>z$Schema.to_python.<locals>.<dictcomp>!  s&    BBBrbllnnBBBr$   )r9   rW   s    r"   r   zSchema.to_python  s!      CBTZZ\\BBBBr$   r   	recursivec                   |s-t          fd|                                 D                       S t          |                                  v S )av  
        Check if the schema contains the given data type.

        Parameters
        ----------
        dtype
            The data type to search for.
        recursive
            If False, only check top-level column dtypes.
            If True, also search within nested types (List, Array, Struct).

        Examples
        --------
        >>> s = pl.Schema({"x": pl.Int64(), "y": pl.List(pl.Float64)})
        >>> s.contains_dtype(pl.Int64, recursive=False)
        True
        >>> s.contains_dtype(pl.Float64, recursive=False)
        False
        >>> s.contains_dtype(pl.Float64, recursive=True)
        True
        c              3  $   K   | ]
}|k    V  d S r    r6   )r   dtrQ   s     r"   	<genexpr>z(Schema.contains_dtype.<locals>.<genexpr>:  s'      ;;rrU{;;;;;;r$   )anyr_   r   )r<   rQ   r   s    ` r"   contains_dtypezSchema.contains_dtype#  sP    ,  	:;;;;T[[]];;;;;;M4;;==999r$   r    )r1   r2   r0   r   r   r3   )rB   rC   r   r   )r?   rP   rQ   rR   r   r3   ri   )r   rX   )r   r]   )ra   rb   r   rc   )rp   rq   r   r   )rp   ru   r   r   )rp   r   r   rw   )r   rz   )r   r|   )rQ   r   r   r   r   r   )rj   rk   rl   __doc__rA   rM   rO   r;   r
   r5   r\   r`   ro   r   rt   rF   r   r   __classcell__)r@   s   @r"   r&   r&   7   s       1 1t    "                       D   & & & &) ) ) ) ) ) XZZO O O ZO
! 
! 
! 
!
# 
# 
# 
# XZZ=A 
 
 
 
 
 Z
@ BBB XB14GGGGG XG(, K K K K K K6   C C C C$: : : : : : : :r$   )r   r   r   r   )r   r'   r   r   )2
__future__r   
contextlibcollectionsr   collections.abcr   typingr   r   r   polars._typingr	   polars._utils.unstabler
   polars.datatypesr   r   r   polars.datatypes._parser   polars.datatypes.convertr   polars.exceptionsr   polars.interchange.protocolr   suppressImportErrorpolars._plrr   r   r   r   r   r   rn   ry   r   r   r   polars._dependenciesr#   rP   
BaseSchemar%   r!   __all__r.   r&   r6   r$   r"   <module>r      s   " " " " " " "     # # # # # # # # # # # # 3 3 3 3 3 3 3 3 3 3 ) ) ) ) ) ) + + + + + + E E E E E E E E E E 4 4 4 4 4 4 2 2 2 2 2 2 , , , , , , 3 3 3 3 3 3Z%%                           	3((((((      ++++++++4444444222222$ $ $ $ h'
 (= 8> I  I I I I*   E: E: E: E: E:Z E: E: E: E: E:s    A77A;>A;