
    ph                        S r SSKJr  SSKJr  SSKJr  SSKJrJ	r	  SSK
JrJr  \(       a,  SSKJrJr  SSKJr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cast)ImplementationVersion)IterableMapping)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: 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     gC:\Users\julio\OneDrive\Documentos\Trabajo\IdeasFrscas\Cabanna\env\Lib\site-packages\narwhals/schema.pyr   Schema.__init__A   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.namesG   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.dtypesO   s     DKKM""r   c                    [        U 5      $ )zJGet the number of columns in the schema.

Returns:
    Number of columns.
)lenr!   s    r   r)   
Schema.lenW   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>p   s+      
+ +E4==AB+   $')pyarrownarwhals._arrow.utilsr-   r   items)r   par-   s   ` @r   to_arrowSchema.to_arrow_   s/     	Byy 
#zz|
 
 	
r   c                   SSK Jn  [        U[        R                  U R
                  S9nUb  [        U[        5      (       a)  U R                  5        VVs0 s H  u  pEXC" XQS9_M     snn$ [        U5      n[        U5      [        U 5      :w  ao  SSKJnJn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  pEnXC" X^S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   r,   )implementation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())narwhals._pandas_like.utilsr-   r   r   PANDASr   
isinstancestrr9   tupler)   	itertoolsrA   rB   rC   from_iterable
ValueErrorzipr    r%   )r   r@   r-   to_native_dtyper2   r3   backendsrA   rB   rC   n_usern_actual
suggestionmsgbackends                  r   	to_pandasSchema.to_pandasu   sj   * 	I!$)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 32s   E*Ec                   ^ ^ SSK nSSKJm  [        R                  R                  5       nUU 4S jT R                  5        5       nU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  R   >#    U  H  u  pUT" UTR                   5      4v   M     g 7fr   r/   r0   s      r   r4   #Schema.to_polars.<locals>.<genexpr>   s+      
+ +E4==AB+r6   )   r   r   	pl.Schema)
polarsnarwhals._polars.utilsr-   r   POLARS_backend_versionr9   r   r   dict)r   pl
pl_versionr   r-   s   `   @r   	to_polarsSchema.to_polars   sf     	C#**;;=

#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;   rU   rc   __static_attributes____classcell__)r   s   @r   r   r   !   su    : #*,,H. RV!N!	! !!#
. FJ9B9	9v
 
r   )rm   
__future__r   collectionsr   	functoolsr   typingr   r   narwhals._utilsr   r	   collections.abcr
   r   r   r   r\   ra   r7   r:   narwhals.dtypesr   narwhals.typingr   rH   
BaseSchema__all__r   re   r   r   <module>r|      sZ    # #  & 31$%,S%Z(J J*h
Z h
r   