
    hQ                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  \(       a(  SSKJr  SSKJr  SSKrSSKrSSKJr  SSKJr  \\\4   rO\rS/r " S S\5      rg)zxSchema.

Adapted from Polars implementation at:
https://github.com/pola-rs/polars/blob/main/py-polars/polars/schema.py.
    )annotations)OrderedDict)partial)TYPE_CHECKING)Iterable)Mapping)cast)Implementation)Version)parse_version)Any)ClassVarN)DType)DTypeBackendSchemac                     ^  \ rS rSr% Sr\R                  rS\S'    S   SU 4S jjjr	SS jr
SS jrSS jrSS	 jr S   SS
 jjrSS jrSrU =r$ )r   &   a.  Ordered mapping of column names to their data type.

Arguments:
    schema: Mapping[str, DType] | Iterable[tuple[str, DType]] | None
        The schema definition given by column names and their associated.
        *instantiated* Narwhals data type. Accepts a mapping or an iterable of tuples.

Examples:
    Define a schema by passing *instantiated* data types.

    >>> import narwhals as nw
    >>> schema = nw.Schema({"foo": nw.Int8(), "bar": nw.String()})
    >>> schema
    Schema({'foo': Int8, 'bar': String})

    Access the data type associated with a specific column name.

    >>> schema["foo"]
    Int8

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

    >>> schema.names()
    ['foo', 'bar']
    >>> schema.dtypes()
    [Int8, String]
    >>> schema.len()
    2
zClassVar[Version]_versionc                :   > U=(       d    0 n[         TU ]  U5        g N)super__init__)selfschema	__class__s     A/var/www/html/env/lib/python3.13/site-packages/narwhals/schema.pyr   Schema.__init__G   s     2     c                4    [        U R                  5       5      $ )z@Get the column names of the schema.

Returns:
    Column names.
)listkeysr   s    r   namesSchema.namesN   s     DIIK  r   c                4    [        U R                  5       5      $ )zFGet the data types of the schema.

Returns:
    Data types of schema.
)r    valuesr"   s    r   dtypesSchema.dtypesV   s     DKKM""r   c                    [        U 5      $ )zJGet the number of columns in the schema.

Returns:
    Number of columns.
)lenr"   s    r   r*   
Schema.len^   s     4yr   c                p   ^ ^ SSK nSSKJm  UR                  " UU 4S jT R	                  5        5       5      $ )zConvert Schema to a pyarrow Schema.

Returns:
    A pyarrow Schema.

Examples:
    >>> import narwhals as nw
    >>> schema = nw.Schema({"a": nw.Int64(), "b": nw.Datetime("ns")})
    >>> schema.to_arrow()
    a: int64
    b: timestamp[ns]
r   Nnarwhals_to_native_dtypec              3  R   >#    U  H  u  pUT" UTR                   5      4v   M     g 7fr   r   ).0namedtyper.   r   s      r   	<genexpr>"Schema.to_arrow.<locals>.<genexpr>w   s+      
+ +E4==AB+s   $')pyarrownarwhals._arrow.utilsr.   r   items)r   par.   s   ` @r   to_arrowSchema.to_arrowf   s/     	Byy 
#zz|
 
 	
r   c                   SSK nSSKJn  [        U[        R
                  [        U5      U R                  S9nUb  [        U[        5      (       a)  U R                  5        VVs0 s H  u  pVXT" XaS9_M     snn$ [        U5      n[        U5      [        U 5      :w  aw  SSKJn  SSKJn	  SSKJn
  [        U5      [        U 5      p[        U	" UR#                  U	" U
" U5      U5      5      U5      5      nS	U< S
U< SU SUS    SU S3n[%        U5      e['        U R)                  5       U R+                  5       U5       VVVs0 s H  u  pVnXT" XoS9_M     snnn$ s  snnf s  snnnf )aa  Convert Schema to an ordered mapping of column names to their pandas data type.

Arguments:
    dtype_backend: Backend(s) used for the native types. When providing more than
        one, the length of the iterable must be equal to the length of the schema.

Returns:
    An ordered mapping of column names to their pandas data type.

Examples:
    >>> import narwhals as nw
    >>> schema = nw.Schema({"a": nw.Int64(), "b": nw.Datetime("ns")})
    >>> schema.to_pandas()
    {'a': 'int64', 'b': 'datetime64[ns]'}

    >>> schema.to_pandas("pyarrow")
    {'a': 'Int64[pyarrow]', 'b': 'timestamp[ns][pyarrow]'}
r   Nr-   )implementationbackend_versionversion)r3   dtype_backend)chain)islice)repeatz	Provided z) `dtype_backend`(s), but schema contains z1 field(s).
Hint: instead of
    schema.to_pandas(z+)
you may want to use
    schema.to_pandas(z)
or
    schema.to_pandas())pandasnarwhals._pandas_like.utilsr.   r   r
   PANDASr   r   
isinstancestrr8   tupler*   	itertoolsrA   rB   rC   from_iterable
ValueErrorzipr!   r&   )r   r@   pdr.   to_native_dtyper2   r3   backendsrA   rB   rC   n_usern_actual
suggestionmsgbackends                   r   	to_pandasSchema.to_pandas|   sw   * 	H!$)00)"-MM	
  J}c$B$B $(::<#/KD oEOO#/ 
 ]+H8}D	)+,,#&x=#d)"++F6(3CX,NOQY
  z)RS[R^ _,,4: 6,,4QK= 9,,6<q:  !o% -0		T[[]H,U,U(D oEII,U 76s   #E Ec                   ^ ^^ SSK nSSKJm  [        U5      mUUU 4S jT R	                  5        5       nTS:  a  UR
                  " U5      $ [        S[        U5      5      $ )a8  Convert Schema to a polars Schema.

Returns:
    A polars Schema or plain dict (prior to polars 1.0).

Examples:
    >>> import narwhals as nw
    >>> schema = nw.Schema({"a": nw.Int64(), "b": nw.Datetime("ns")})
    >>> schema.to_polars()
    Schema({'a': Int64, 'b': Datetime(time_unit='ns', time_zone=None)})
r   Nr-   c              3  P   >#    U  H  u  pUT" UTR                   TS 94v   M     g7f))r>   Nr0   )r1   r2   r3   r.   
pl_versionr   s      r   r4   #Schema.to_polars.<locals>.<genexpr>   s6      
  , (4==*  ,s   #&)   r   r   	pl.Schema)polarsnarwhals._polars.utilsr.   r   r8   r   r	   dict)r   plr   r.   r[   s   `  @@r   	to_polarsSchema.to_polars   s^     	C"2&

  $zz|
 Y& IIf	
 k4<0	
r    r   )r   z8Mapping[str, DType] | Iterable[tuple[str, DType]] | NonereturnNone)rf   z	list[str])rf   zlist[DType])rf   int)rf   z	pa.Schema)r@   z%DTypeBackend | Iterable[DTypeBackend]rf   zdict[str, Any])rf   r^   )__name__
__module____qualname____firstlineno____doc__r   MAINr   __annotations__r   r#   r'   r*   r:   rW   rc   __static_attributes____classcell__)r   s   @r   r   r   &   sw    < #*,,H. LP!H! 
! !!#
. FJ>B>	>@
 
r   )rm   
__future__r   collectionsr   	functoolsr   typingr   r   r   r	   narwhals.utilsr
   r   r   r   r   r_   rb   r6   r9   narwhals.dtypesr   narwhals.typingr   rI   
BaseSchema__all__r   re   r   r   <module>r{      si    # #       ) " (%,S%Z(J J*t
Z t
r   