
    Lpj^                       S SK Jr  S SKrS SKJr  S SKJr  S SKJ	r	J
r
JrJrJr  S SKJr  S SKJrJr  S SKJrJrJrJr  S S	KJrJrJrJrJrJr  S S
KJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,  \	(       a@  S SK-J.r.  S SK/J0r0  S SK1J2r2J3r3J4r4J5r5J6r6J7r7  S SK8J9r9J:r:  S SK;J<r<  S SK=J>r>J?r?J@r@JArAJBrBJCrCJDrDJErEJFrF  \" S5      rG\H\I\J\K\L\M\4rN\R                  \R                  \R                  4rR\SS.     S2S jj5       rS\SS.     S3S jj5       rS\SS.     S4S jj5       rS\S5S j5       rSSS.     S6S jjrS\S7S j5       rT\S8S j5       rT\      S9S j5       rT\S:S j5       rT\      S;S j5       rT\      S<S j5       rT\      S=S  j5       rT\      S>S! j5       rT\      S?S" j5       rT\      S@S# j5       rT\SAS$ j5       rT\            SBS% j5       rTSSSSS&.           SCS' jjrTSSS(.               SDS) jjrUSSS(.               SES* jjrVSFS+ jrW    SFS, jrX SGS-SSS-S&.           SHS. jjjrYSIS/ jrZSJS0 jr[/ S1Qr\g)K    )annotationsN)Decimalwraps)TYPE_CHECKINGAnyLiteralTypeVaroverload)plugins)EPOCHMS_PER_SECOND)is_native_arrowis_native_pandas_likeis_native_polarsis_native_spark_like)ImplementationVersionhas_native_namespaceis_compliant_dataframeis_compliant_lazyframeis_compliant_series)get_dask_expr	get_numpy
get_pandasis_cupy_scalaris_dask_dataframeis_duckdb_relationis_ibis_tableis_numpy_scalaris_pandas_like_dataframeis_polars_lazyframeis_polars_seriesis_pyarrow_scalaris_pyarrow_table)Callable)Unpack)AllowAny	AllowLazyAllowSeriesExcludeSeries
OnlySeriesPassThroughUnknown	DataFrame	LazyFrameSeries)	
DataFrameTFrameIntoDataFrameT	IntoFrameIntoLazyFrameT
IntoSeriesIntoSeriesT
LazyFrameTSeriesTT.pass_throughc                   g N narwhals_objectr>   s     N/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/narwhals/translate.py	to_nativerE   I            c                   g r@   rA   rB   s     rD   rE   rE   M   rF   rG   c                   g r@   rA   rB   s     rD   rE   rE   Q   s     rG   c                   g r@   rA   rB   s     rD   rE   rE   U   s    CFrG   Fc                   SSK Jn  SSKJn  [	        X5      (       a  U R
                  R                  $ [	        X5      (       a  U R                  R                  $ U(       d  S[        U 5       S3n[        U5      eU $ )a=  Convert Narwhals object to native one.

Arguments:
    narwhals_object: Narwhals object.
    pass_through: Determine what happens if `narwhals_object` isn't a Narwhals class

        - `False` (default): raise an error
        - `True`: pass object through as-is

Returns:
    Object of class that user started with.
r   )	BaseFramer1   zExpected Narwhals object, got .)narwhals.dataframerL   narwhals.seriesr2   
isinstance_compliant_frame_native_frame_compliant_seriesnativetype	TypeError)rC   r>   rL   r2   msgs        rD   rE   rE   Y   sk    & -&/--//===/**00777.tO/D.EQGnrG   c                    g r@   rA   native_objectkwdss     rD   from_nativer\   z   s    PSrG   c                    g r@   rA   rY   s     rD   r\   r\   |   s    QTrG   c                    g r@   rA   rY   s     rD   r\   r\   ~   s     rG   c                    g r@   rA   rY   s     rD   r\   r\      s    UXrG   c                    g r@   rA   rY   s     rD   r\   r\           !$rG   c                    g r@   rA   rY   s     rD   r\   r\           rG   c                    g r@   rA   rY   s     rD   r\   r\      rc   rG   c                    g r@   rA   rY   s     rD   r\   r\      ra   rG   c                    g r@   rA   rY   s     rD   r\   r\      s     7:rG   c                    g r@   rA   rY   s     rD   r\   r\      s	     SVrG   c                    g r@   rA   rY   s     rD   r\   r\      s    LOrG   c                   g r@   rA   rZ   r>   
eager_onlyseries_onlyallow_seriess        rD   r\   r\      s     rG   r>   rk   rl   rm   c          
     <    [        U UUSUU[        R                  S9$ )a5  Convert `native_object` to Narwhals Dataframe, Lazyframe, or Series.

Arguments:
    native_object: Raw object from user.
        Depending on the other arguments, input object can be

        - a Dataframe / Lazyframe / Series supported by Narwhals (pandas, Polars, PyArrow, ...)
        - an object which implements `__narwhals_dataframe__`, `__narwhals_lazyframe__`,
          or `__narwhals_series__`
    pass_through: Determine what happens if the object can't be converted to Narwhals

        - `False` (default): raise an error
        - `True`: pass object through as-is
    eager_only: Whether to only allow eager objects

        - `False` (default): don't require `native_object` to be eager
        - `True`: only convert to Narwhals if `native_object` is eager
    series_only: Whether to only allow Series

        - `False` (default): don't require `native_object` to be a Series
        - `True`: only convert to Narwhals if `native_object` is a Series
    allow_series: Whether to allow Series (default is only Dataframe / Lazyframe)

        - `False` or `None` (default): don't convert to Narwhals if `native_object` is a Series
        - `True`: allow `native_object` to be a Series

Returns:
    DataFrame, LazyFrame, Series, or original object, depending
        on which combination of parameters was passed.
Fr>   rk   eager_or_interchange_onlyrl   rm   version)_from_native_implr   MAINrj   s        rD   r\   r\      s+    V !"'! rG   )r>   rk   c               h   [        U 5      (       aJ  U(       a  U(       d  Sn[        U5      eU $ UR                  U R                  5       R	                  U5      SS9$ [        U 5      (       an  U(       a  U(       d  Sn[        U5      eU $ U(       d  U(       a  U(       d  Sn[        U5      eU $ UR                  U R                  5       R	                  U5      SS9$ [        U 5      (       aJ  U(       d  U(       d  Sn[        U5      eU $ UR                  U R                  5       R	                  U5      SS9$ g )Nz,Cannot only use `series_only` with dataframefulllevelz,Cannot only use `series_only` with lazyframezJCannot only use `eager_only` or `eager_or_interchange_only` with lazyframe4Please set `allow_series=True` or `series_only=True`)r   rV   	dataframe__narwhals_dataframe___with_versionr   	lazyframe__narwhals_lazyframe__r   series__narwhals_series__)compliant_objectr>   rk   rq   rl   rm   rr   rW   s           rD   _translate_if_compliantr      s4    .//Dn$##  335CCGLTZ ! 
 	
 .//Dn$##2bn$##  335CCGLTZ ! 
 	
 +,,Ln$##~~002@@IQW  
 	
 rG   c          
        SSK Jn  SSKJnJn	  SSKJn
  [        XU	45      (       aj  U(       dc  U R                  UL a  U $ U R                  5       nUR                  R                  U5      R                  R                  U5      R                  5       $ [        X
5      (       aq  U(       d  U(       ac  U R                  UL a  U $ U R                  5       nUR                  R                  U5      R                  R                  U5      R                  5       $ U(       a  USL a  Sn[        U5      eSnU(       a  U(       a  Sn[        U5      e[!        U UUUUUUS	9=n b  U$ [#        U 5      (       a  U(       a<  [%        U 5      (       d,  U(       d#  S
['        U 5      R(                   3n[+        U5      eU $ U(       d  U(       a&  [-        U 5      (       a  U(       d  Sn[+        U5      eU $ U(       d&  [%        U 5      (       a  U(       d  Sn[+        U5      eU $ UR                  R                  U 5      R                  R                  U 5      R                  5       $ [/        U 5      (       a  [1        U 5      (       a4  U(       a,  U(       d#  S
['        U 5      R(                   3n[+        U5      eU $ OU(       d  U(       d  Sn[+        U5      eU $ UR                  R                  U 5      R                  R                  U 5      R                  5       $ [3        U 5      (       a  [5        U 5      (       a4  U(       a,  U(       d#  S
['        U 5      R(                   3n[+        U5      eU $ OU(       d  U(       d  Sn[+        U5      eU $ UR                  R                  U 5      R                  R                  U 5      R                  5       $ [7        U 5      (       a  U(       a  U(       d  Sn[+        U5      eU $ U(       d  U(       a  U(       d  Sn[+        U5      eU $ [8        R:                  R=                  5       S::  a  [?        5       c  Sn[A        U5      eUR                  RC                  [8        R:                  5      R                  R                  U 5      R                  5       $ [E        U 5      (       af  U(       d  U(       a  U(       d  Sn[+        U5      eU $ UR                  R                  U 5      R                  R                  U 5      R                  5       $ [G        U 5      (       af  U(       d  U(       a  U(       d  Sn[+        U5      eU $ UR                  R                  U 5      R                  R                  U 5      R                  5       $ [I        U 5      (       a}  UR                  R                  U 5      nU(       d  U(       d  U(       a$  U(       d  SURJ                   S3n[+        U5      eU $ UR                  R                  U 5      R                  5       $ U[L        RN                  L a[  U" U 5      (       aN  SSK J(n  U(       d  U(       a  U(       d  Sn[+        U5      eU $ [L        RN                  RS                  U" U 5      SS9$ [T        R                  " X5      =nb  [!        UUUUUUUS	9$ U(       dG  S['        U 5       3n[T        RV                  " ['        U 5      5      =n(       a  USU-   -  n[+        U5      eU $ )Nr   )supports_dataframe_interchanger.   r1   FzJInvalid parameter combination: `series_only=True` and `allow_series=False`TzUInvalid parameter combination: `eager_only=True` and `eager_or_interchange_only=True`rp   z#Cannot only use `series_only` with zQCannot only use `eager_only` or `eager_or_interchange_only` with polars.LazyFramery   z1Cannot only use `series_only` with dask DataFramezOCannot only use `eager_only` or `eager_or_interchange_only` with dask DataFrame)i        zPlease install dask-exprzNCannot only use `series_only=True` or `eager_only=False` with DuckDBPyRelationzHCannot only use `series_only=True` or `eager_only=False` with ibis.TablezPCannot only use `series_only`, `eager_only` or `eager_or_interchange_only` with z
 DataFrame)InterchangeFramezhCannot only use `series_only=True` or `eager_only=False` with object which only implements __dataframe__interchangerw   z!Unsupported dataframe type, got: z

),narwhals._interchange.dataframer   rN   r/   r0   rO   r2   rP   _versionrE   	namespacefrom_native_object	compliantr\   to_narwhals
ValueErrorr   r   r#   rU   __qualname__rV   r"   r   r!   r   r%   r   r   DASK_backend_versionr   ImportErrorfrom_backendr   r   r   implementationr   V1r   rz   r   _show_suggestions)rZ   r>   rk   rq   rl   rm   rr   r   r/   r0   r2   real_native_objectrW   
translatedns_sparkr   r   hints                     rD   rs   rs     s    O7& -Y!788!!W,  *446001CDY{{#56[]	

 -((k\!!W,  *446001CDY{{#56[]	
 5 ^CS/!/eo .%!&?#%
 	

 
  &&/>>;D<O<\<\;]^n$  39L:
 :
  in$  "2="A"ALn$  00?Y{{=1[]	
 ]++#M22#?]@S@`@`?abC#C.($$	 
 Ln$  00?Y{{=1[]	
 }%%M**#?]@S@`@`?abC#C.($$	 
 Ln$  00?Y{{=1[]	
 ''In$  2gn$  002mC',Cc""**>+>+>?Y{{=1[]	
 -((fn$  00?Y{{=1[]	
 ]##`n$  00?Y{{=1[]	
 M**$$77F*(A$334J@   n$  !!--m<HHJJ '**!?!N!NDF   n$  zz##$4]$C=#YY#//GGT&%!&?#%
 	
 1$}2E1FG,,T--@AA4A6D= CnrG   c                     U (       d  Sn[        U5      eU  Vs1 s H  n[        U5      iM     nn[        U5      S:w  a  SU S3n[        U5      eUR                  5       $ s  snf )a[  Get native namespace from object.

Arguments:
    obj: Dataframe, Lazyframe, or Series. Multiple objects can be
        passed positionally, in which case they must all have the
        same native namespace (else an error is raised).

Returns:
    Native module.

Examples:
    >>> import polars as pl
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> df = nw.from_native(pd.DataFrame({"a": [1, 2, 3]}))
    >>> nw.get_native_namespace(df)
    <module 'pandas'...>
    >>> df = nw.from_native(pl.DataFrame({"a": [1, 2, 3]}))
    >>> nw.get_native_namespace(df)
    <module 'polars'...>
z=At least one object must be passed to `get_native_namespace`.r   z0Found objects with different native namespaces: rM   )r    _get_native_namespace_single_objlenpop)objrW   xresults       rD   get_native_namespacer     sf    , Mo;>?3a.q13F?
6{a@Jo::<	 @s   A c                    [        U 5      (       a  U R                  5       $ [        R                  R                  R                  U 5      R                  R                  5       $ r@   )r   __native_namespace__r   rt   r   r   r   to_native_namespace)r   s    rD   r   r   	  sL     C  ''))<<!!44n((*+rG   Tc               :   ^^^^ SUUUU4S jjnU c  U$ U" U 5      $ )a,  Decorate function so it becomes dataframe-agnostic.

This will try to convert any dataframe/series-like object into the Narwhals
respective DataFrame/Series, while leaving the other parameters as they are.
Similarly, if the output of the function is a Narwhals DataFrame or Series, it will be
converted back to the original dataframe/series type, while if the output is another
type it will be left as is.
By setting `pass_through=False`, then every input and every output will be required to be a
dataframe/series-like object.

Arguments:
    func: Function to wrap in a `from_native`-`to_native` block.
    pass_through: Determine what happens if the object can't be converted to Narwhals

        - `False`: raise an error
        - `True` (default): pass object through as-is
    eager_only: Whether to only allow eager objects

        - `False` (default): don't require `native_object` to be eager
        - `True`: only convert to Narwhals if `native_object` is eager
    series_only: Whether to only allow Series

        - `False` (default): don't require `native_object` to be a Series
        - `True`: only convert to Narwhals if `native_object` is a Series
    allow_series: Whether to allow Series (default is only Dataframe / Lazyframe)

        - `False` or `None`: don't convert to Narwhals if `native_object` is a Series
        - `True` (default): allow `native_object` to be a Series

Returns:
    Decorated function.

Examples:
    Instead of writing

    >>> import narwhals as nw
    >>> def agnostic_group_by_sum(df):
    ...     df = nw.from_native(df, pass_through=True)
    ...     df = df.group_by("a").agg(nw.col("b").sum())
    ...     return nw.to_native(df)

    you can just write

    >>> @nw.narwhalify
    ... def agnostic_group_by_sum(df):
    ...     return df.group_by("a").agg(nw.col("b").sum())
c                >   >^  [        T 5      SUUU UU4S jj5       nU$ )Nc                   > U  Vs/ s H  n[        UTTTTS9PM     nnUR                  5        VVs0 s H  u  pEU[        UTTTTS9_M     nnn/ UQUR                  5       Q7 Vs1 s H   n[        USS 5      =n(       d  M  U" 5       iM"     n	n[	        U	5      S:  a  Sn
[        U
5      eT" U0 UD6n[        UTS9$ s  snf s  snnf s  snf )Nrn   r   r   z_Found multiple backends. Make sure that all dataframe/series inputs come from the same backend.r=   )r\   itemsvaluesgetattrr   r   rE   )argskwargsargargs_nwnamevalue	kwargs_nwvbbackendsrW   r   rm   rk   funcr>   rl   s               rD   wrapper.narwhalify.<locals>.decorator.<locals>.wrapperL  s     	  C !-) +!-    	& $*<<>	 $2KD k!-) +!-  $2  	 978Y%5%5%788A $:DAAAA 8   8}q w o%70i0FV,??E		s   B=C&CC)r   r   r   r   returnr   r   )r   r   rm   rk   r>   rl   s   ` rD   	decoratornarwhalify.<locals>.decoratorK  s)    	t#	@ #	@ 
#	@J rG   )r   Callable[..., Any]r   r   rA   )r   r>   rk   rl   rm   r   s    ```` rD   
narwhalifyr     s&    p' 'R |T?rG   c                4   [        5       nU b  [        U [        5      (       a  U nU$ [        5       =n(       a^  [        XR                  5      (       aD  U R
                  S:X  a4  U R                  5       [        -  n[        [        R                  " US9-   nU$ [        U 5      (       d  [        U 5      (       a  U R                  5       nU$ U(       a,  [        XR                  5      (       a  U R                  5       nU$ U(       a,  [        XR                  5      (       a  U R!                  5       nU$ [        U ["        5      (       a  U nU$ [%        U 5      (       a  SnU$ ['        U 5      (       a  U R)                  5       nU$ S[+        U 5       SU < 3n[-        U5      e)a  If a scalar is not Python native, converts it to Python native.

Arguments:
    scalar_like: Scalar-like value.

Raises:
    ValueError: If the object is not convertible to a scalar.

Examples:
    >>> import narwhals as nw
    >>> import pandas as pd
    >>> df = nw.from_native(pd.DataFrame({"a": [1, 2, 3]}))
    >>> nw.to_py_scalar(df["a"].item(0))
    1
    >>> import pyarrow as pa
    >>> df = nw.from_native(pa.table({"a": [1, 2, 3]}))
    >>> nw.to_py_scalar(df["a"].item(0))
    1
    >>> nw.to_py_scalar(1)
    1
Nzdatetime64[ns])microsecondsz/Expected object convertible to a scalar, found z.
)r   rP   NON_TEMPORAL_SCALAR_TYPESr   
datetime64dtypeitemr   r   dt	timedeltar    r   	Timestampto_pydatetime	Timedeltato_pytimedeltaTEMPORAL_SCALAR_TYPES_is_pandas_nar$   as_pyrU   r   )scalar_likepdscalarnpmsrW   s         rD   to_py_scalarr   z  s   . 
Bj6OPP8 M5 {		{MM22!11=0266* M) 
	%	%)D)D!!#& M% 

;55**," M! 

;55++- M 
K!6	7	7 M 
{	#	# M 
;	'	'""$ M	 >d;>O=PPSo 	 orG   c                    [        [        5       =n=(       a=    UR                  R                  R	                  U 5      =(       a    UR                  U 5      5      $ r@   )boolr   apitypes	is_scalarisna)r   r   s     rD   r   r     s:    z|#U)?)?)DUQTVVrG   )r   r   rE   r   )rC   DataFrame[IntoDataFrameT]r>   Literal[False]r   r5   )rC   LazyFrame[IntoLazyFrameT]r>   r   r   r7   )rC   Series[IntoSeriesT]r>   r   r   r9   )rC   r   r>   r   r   r   )rC   KDataFrame[IntoDataFrameT] | LazyFrame[IntoLazyFrameT] | Series[IntoSeriesT]r>   r   r   z3IntoDataFrameT | IntoLazyFrameT | IntoSeriesT | Any)rZ   r;   r[   Unpack[OnlySeries]r   r;   )rZ   r;   r[   Unpack[AllowSeries]r   r;   )rZ   r3   r[   Unpack[ExcludeSeries]r   r3   )rZ   r:   r[   Unpack[AllowLazy]r   r:   )rZ   r5   r[   r   r   r   )rZ   r9   r[   r   r   r   )rZ   r9   r[   r   r   r   )rZ   r7   r[   r   r   r   )rZ   zIntoDataFrameT | IntoSeriesTr[   r   r   z/DataFrame[IntoDataFrameT] | Series[IntoSeriesT])rZ   z-IntoDataFrameT | IntoLazyFrameT | IntoSeriesTr[   zUnpack[AllowAny]r   r   )rZ   r<   r[   zUnpack[PassThroughUnknown]r   r<   )rZ   r   r>   r   rk   r   rl   r   rm   bool | Noner   r   )rZ   zJIntoLazyFrameT | IntoDataFrameT | IntoSeriesT | IntoFrame | IntoSeries | Tr>   r   rk   r   rl   r   rm   r   r   zOLazyFrame[IntoLazyFrameT] | DataFrame[IntoDataFrameT] | Series[IntoSeriesT] | T)r   r   r>   r   rk   r   rq   r   rl   r   rm   r   rr   r   r   r   )rZ   r   r>   r   rk   r   rq   r   rl   r   rm   r   rr   r   r   r   )r   z,Frame | Series[Any] | IntoFrame | IntoSeriesr   r   r@   )r   zCallable[..., Any] | Noner>   r   rk   r   rl   r   rm   r   r   r   )r   r   r   r   )r   r   r   r   )]
__future__r   datetimer   decimalr   	functoolsr   typingr   r   r	   r
   r   narwhalsr   narwhals._constantsr   r   narwhals._nativer   r   r   r   narwhals._utilsr   r   r   r   r   r   narwhals.dependenciesr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   collections.abcr&   typing_extensionsr'   narwhals._translater(   r)   r*   r+   r,   r-   rN   r/   r0   rO   r2   narwhals.typingr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r   bytesstrintfloatcomplexr   dater   timer   rE   r\   r   rs   r   r   r   r   r   __all__rA   rG   rD   <module>r      s   "    A A  4       ((  8&
 
 
 CL!5#sE7GL ",,8  
RU.AO 
 
RU.AO 
 
LO(;I 
 
 F 
 F 
  9B 
 S 
 S	 T 
 T	'< 
 
 X 
 X	$!$+@$$ 
$ 
(: 
 
(; 
 
$!$+<$$ 
$ 
:/:9L:4: 
: 
V@VJZVPV 
V 
 O 
 O	  	
   	 
   $33 3 3 3 3 U3r 	,, , 	,  $, , , , 	,d 	XX X 	X  $X X X X 	Xv@+	5++ '+d  $d
#d d 	d
 d d dN5pW NrG   