
    h                    L   % S SK Jr  S SKrS SK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  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  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*  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 J0r0  S S'K J1r1  S S(K J2r2  S S)K J3r3  S S*K J4r4  S S+K J5r5  S S,K J6r6  S S-K J7r7  S S.K8J9r9  S S/K8J:r:  S S0K8J;r;  \(       Ga  S S1K<J=r=  S S2KJ>r?  S SK@rAS SKBrCS S3KDJErE  S S4KDJFrF  S S5KDJGrG  S S6KDJHrH  S S7KDJIrI  S S8KDJJrJ  S S9KKJLrL  S S:KKJMrM  S S;KKJNrN  S S<KKJOrO  S S=KKJPrP  S S>KKJQrQ  S S?KKJRrR  S S@KSJTrT  S SAKUJVrV  S SBKUJWrW  S SCKXJYrY  S SDKXJZrZ  S SEK[J\r\  S SFK[J]r]  S SGK^J_r_  S SHK`Jara  S SIKbJcrc  S SJKbJdrd  S SKKbJere  S SLKbJfrf  S SMKbJgrg  S SNKbJhrh  S SOKbJiri  S SPKbJjrj  S SQKbJkrk  S SRKbJlrl  S SSKbJmrm  S STKbJnrn  S SUKbJoro  S SVKbJprp  S SWKbJqrq  S SXKbJrrr  \" SY\\]\   \\\   \a\   4   SZ9rs\" S[5      rt\" S\5      ru\" S]5      rv\" S^5      rw\" S_S`SZ9rx\G" Sa5      ry\" Sb5      rz " Sc Sd\5      r{ " Se Sf\5      r| " Sg Sh\5      r} " Si Sj\5      r~ " Sk Sl\5      r " Sm Sn\~\\5      r " So Sp\}\\5      r " Sq Sr\5      r\" SsStSu9r\" SvStSu9r\" SwSpSZ9rSxrSy\Sz'    " S{ S|\\   5      r " S} S~\\   5      r " S S\5      r " S S\5      r\GR                  S\GR                  S\GR                  S\GR                  S\GR                   S\GR"                  S\GR$                  S\GR&                  S\GR(                  S\GR*                  S0
rS\S'         SS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jr\      SS j5       r\      SS j5       r\      SS j5       r\      SS j5       r\      SS j5       r\      SS j5       r\      SS j5       rSS jrSS jr      SS jrSS jr SSS.       SS jjjrSS jrSS jr      SS jr        SS jrSS jrSS jr      SS jrSS jr        SS jrSS jrSS jrSS jr    SS jrSS jrGS S jrGSS jrGSS jrGSS jrGSS jrGSS jr          GSS jrSSS.     GSS jjr      GSS jrGS	S jrGS
S jrGSS jr      GSS jr          GSS jrGSS jrGSS jrGSS jrGSS jr    GSS jr    GSS jr    GSS jr    GSS jrGSS jrGSS jrGSS jrGSS jr        GSS jrGSS jrGSS jr\(       a#  S SKr\GR                  S:  a  S SKJr  OS SKDJr  OGSS jr " S S5      rGSS jr " S S5      r      GSS jrg(       )annotationsN)timezone)Enum)autowraps)	find_spec)getattr_static)	token_hex)TYPE_CHECKING)Any)Callable)	Container)Iterable)Literal)Protocol)Sequence)TypeVar)Union)cast)overload)warn)get_cudf)get_dask)get_dask_dataframe)
get_duckdb)get_ibis)	get_modin)	get_numpy)
get_pandas)
get_polars)get_pyarrow)get_pyspark)get_pyspark_sql)get_sqlframe)is_cudf_series)is_modin_series)is_narwhals_series)is_numpy_array_1d)is_pandas_dataframe)is_pandas_like_dataframe)is_pandas_like_series)is_pandas_series)is_polars_series)is_pyarrow_chunked_array)ColumnNotFoundError)DuplicateError)InvalidOperationError)
ModuleType)AbstractSet)Concatenate)LiteralString)	ParamSpec)Self)	TypeAlias)TypeIs)CompliantExpr)CompliantExprT)CompliantFrameT)CompliantSeriesOrNativeExprT_co)CompliantSeriesT)NativeFrameT_co)NativeSeriesT_co)	EvalNames)EagerAllowedImplementation	Namespace)ArrowStreamExportable)IntoArrowTable	DataFrame	LazyFrameDTypeSeries)CompliantDataFrame)CompliantLazyFrame)CompliantSeries)DataFrameLike)DTypes)IntoSeriesT)MultiIndexSelector)SingleIndexSelector)SizedMultiIndexSelector)SizeUnit)SupportsNativeNamespace)TimeUnit)_1DArray)_SliceIndex)
_SliceName)
_SliceNoneFrameOrSeriesT)bound_T_T1_T2_T3_FnzCallable[..., Any]PRc                       \ rS rSr% S\S'   Srg)_SupportsVersionn   str__version__ N__name__
__module____qualname____firstlineno____annotations____static_attributes__rn       @/var/www/html/env/lib/python3.13/site-packages/narwhals/utils.pyrj   rj   n   s    rv   rj   c                  "    \ rS rSrSSS jjrSrg)_SupportsGetq   Nc                   g Nrn   )selfinstanceowners      rw   __get___SupportsGet.__get__r   s    crv   rn   r|   )r~   r   r   
Any | Nonereturnr   )rp   rq   rr   rs   r   ru   rn   rv   rw   ry   ry   q   s    QQrv   ry   c                       \ rS rSr% S\S'   Srg)_StoresImplementationt   Implementation_implementationrn   Nro   rn   rv   rw   r   r   t   s    ''Mrv   r   c                       \ rS rSr% S\S'   Srg)_StoresBackendVersionx   tuple[int, ...]_backend_versionrn   Nro   rn   rv   rw   r   r   x   s    ))1rv   r   c                       \ rS rSr% S\S'   Srg)_StoresVersion|   Version_versionrn   Nro   rn   rv   rw   r   r   |   s    0rv   r   c                      \ rS rSrSrSrg)_LimitedContext   z:Provides 2 attributes.

- `_backend_version`
- `_version`
rn   Nrp   rq   rr   rs   __doc__ru   rn   rv   rw   r   r      s    	rv   r   c                      \ rS rSrSrSrg)_FullContext   zNProvides 3 attributes.

- `_implementation`
- `_backend_version`
- `_version`
rn   Nr   rn   rv   rw   r   r      s    	rv   r   c                  (    \ rS rSr\SS j5       rSrg)_StoresColumns   c                    g r|   rn   r}   s    rw   columns_StoresColumns.columns   s    ,/rv   rn   N)r   Sequence[str])rp   rq   rr   rs   propertyr   ru   rn   rv   rw   r   r      s    	/ 
/rv   r   
NativeT_coT)	covariantCompliantT_co	_ContextTz&Callable[Concatenate[_ContextT, P], R]r9   _Methodc                  ,    \ rS rSrSr\SS j5       rSrg)_StoresNative   zProvides access to a native object.

Native objects have types like:

>>> from pandas import Series
>>> from pyarrow import Table
c                    g)zReturn the native object.Nrn   r   s    rw   native_StoresNative.native        	rv   rn   N)r   r   )rp   rq   rr   rs   r   r   r   ru   rn   rv   rw   r   r            rv   r   c                  ,    \ rS rSrSr\SS j5       rSrg)_StoresCompliant   zProvides access to a compliant object.

Compliant objects have types like:

>>> from narwhals._pandas_like.series import PandasLikeSeries
>>> from narwhals._arrow.dataframe import ArrowDataFrame
c                    g)zReturn the compliant object.Nrn   r   s    rw   	compliant_StoresCompliant.compliant   r   rv   rn   N)r   r   )rp   rq   rr   rs   r   r   r   ru   rn   rv   rw   r   r      r   rv   r   c                  0    \ rS rSr\" 5       r\" 5       rSrg)r      rn   N)rp   rq   rr   rs   r   V1MAINru   rn   rv   rw   r   r      s    	B6Drv   r   c                     \ rS rSrSr\" 5       r \" 5       r \" 5       r \" 5       r	 \" 5       r
 \" 5       r \" 5       r \" 5       r \" 5       r \" 5       r \" 5       r \      SS j5       r\      SS j5       r\      SS j5       rSS jrSS jrSS jrSS	 jrSS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSS jr SS jr!\"SS j5       r#SS jr$Sr%g)r      z?Implementation of native object (pandas, Polars, PyArrow, ...).c                &   [        5       [        R                  [        5       [        R                  [        5       [        R                  [        5       [        R                  [        5       [        R                  [        5       [        R                  [        5       [        R                  [        5       [        R                   [#        5       [        R$                  ['        5       [        R(                  0
nUR+                  U[        R,                  5      $ )zInstantiate Implementation object from a native namespace module.

Arguments:
    native_namespace: Native namespace.

Returns:
    Implementation.
)r    r   PANDASr   MODINr   CUDFr"   PYARROWr$   PYSPARKr!   POLARSr   DASKr   DUCKDBr   IBISr%   SQLFRAMEgetUNKNOWN)clsnative_namespacemappings      rw   from_native_namespace$Implementation.from_native_namespace   s     L.//K--J++M>11~55L.// ."5"5L.//J++NN33
 {{+^-C-CDDrv   c                t   [         R                  [         R                  [         R                  [         R                  [         R
                  [         R                  [         R                  [         R                  [         R                  [         R                  S.
nUR                  U[         R                  5      $ )zInstantiate Implementation object from a native namespace module.

Arguments:
    backend_name: Name of backend, expressed as string.

Returns:
    Implementation.
)
pandasmodincudfpyarrowpysparkpolarsdaskduckdbibissqlframe)r   r   r   r   r   r   r   r   r   r   r   r   r   )r   backend_namer   s      rw   from_stringImplementation.from_string   s~     %++#))"''%--%--$++"''$++"''&//
 {{<)?)?@@rv   c                    [        U[        5      (       a  U R                  U5      $ [        U[        5      (       a  U$ U R	                  U5      $ )zInstantiate from native namespace module, string, or Implementation.

Arguments:
    backend: Backend to instantiate Implementation from.

Returns:
    Implementation.
)
isinstancerl   r   r   r   )r   backends     rw   from_backendImplementation.from_backend  sR     '3'' OOG$	
 '>22 	

 **73	
rv   c                   U [         R                  L a  SSKnU$ U [         R                  L a  SSKnUR                  $ U [         R
                  L a  SSKnU$ U [         R                  L a  SSKnU$ U [         R                  L a  SSK
nUR                  $ U [         R                  L a  SSKnU$ U [         R                  L a  SSKnUR                   $ U [         R"                  L a  SSKnU$ U [         R&                  L a  SSKn	U	$ Sn
[+        U
5      e)zaReturn the native namespace module corresponding to Implementation.

Returns:
    Native module.
r   NzNot supported Implementation)r   r   r   r   modin.pandasr   r   r   r   r   pyspark.sqlsqlr   r   r   dask.dataframe	dataframer   r   r   r   AssertionError)r}   pdr   r   par   plr   r   r   msgs              rw   to_native_namespace"Implementation.to_native_namespace   s     >(((I>'''<<>&&&K>))) I>)));;>(((I>&&&!>>!>(((M>***O,S!!rv   c                &    U [         R                  L $ )a  Return whether implementation is pandas.

Returns:
    Boolean.

Examples:
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> df_native = pd.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_pandas()
    True
)r   r   r   s    rw   	is_pandasImplementation.is_pandasP       ~,,,,rv   c                f    U [         R                  [         R                  [         R                  1;   $ )a#  Return whether implementation is pandas, Modin, or cuDF.

Returns:
    Boolean.

Examples:
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> df_native = pd.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_pandas_like()
    True
)r   r   r   r   r   s    rw   is_pandas_likeImplementation.is_pandas_like`  s1     !!  
 
 	
rv   c                H    U [         R                  [         R                  1;   $ )a   Return whether implementation is pyspark or sqlframe.

Returns:
    Boolean.

Examples:
    >>> import pandas as pd
    >>> import narwhals as nw
    >>> df_native = pd.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_spark_like()
    False
)r   r   r   r   s    rw   is_spark_likeImplementation.is_spark_liket  s      ..0G0GHHHrv   c                &    U [         R                  L $ )a  Return whether implementation is Polars.

Returns:
    Boolean.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_native = pl.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_polars()
    True
)r   r   r   s    rw   	is_polarsImplementation.is_polars  r   rv   c                &    U [         R                  L $ )a  Return whether implementation is cuDF.

Returns:
    Boolean.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_native = pl.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_cudf()
    False
)r   r   r   s    rw   is_cudfImplementation.is_cudf       ~****rv   c                &    U [         R                  L $ )a  Return whether implementation is Modin.

Returns:
    Boolean.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_native = pl.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_modin()
    False
)r   r   r   s    rw   is_modinImplementation.is_modin  s     ~++++rv   c                &    U [         R                  L $ )a  Return whether implementation is PySpark.

Returns:
    Boolean.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_native = pl.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_pyspark()
    False
)r   r   r   s    rw   
is_pysparkImplementation.is_pyspark       ~----rv   c                &    U [         R                  L $ )a  Return whether implementation is PyArrow.

Returns:
    Boolean.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_native = pl.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_pyarrow()
    False
)r   r   r   s    rw   
is_pyarrowImplementation.is_pyarrow  r  rv   c                &    U [         R                  L $ )a  Return whether implementation is Dask.

Returns:
    Boolean.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_native = pl.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_dask()
    False
)r   r   r   s    rw   is_daskImplementation.is_dask  r   rv   c                &    U [         R                  L $ )a  Return whether implementation is DuckDB.

Returns:
    Boolean.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_native = pl.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_duckdb()
    False
)r   r   r   s    rw   	is_duckdbImplementation.is_duckdb  r   rv   c                &    U [         R                  L $ )a  Return whether implementation is Ibis.

Returns:
    Boolean.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_native = pl.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_ibis()
    False
)r   r   r   s    rw   is_ibisImplementation.is_ibis  r   rv   c                &    U [         R                  L $ )a  Return whether implementation is SQLFrame.

Returns:
    Boolean.

Examples:
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_native = pl.DataFrame({"a": [1, 2, 3]})
    >>> df = nw.from_native(df_native)
    >>> df.implementation.is_sqlframe()
    False
)r   r   r   s    rw   is_sqlframeImplementation.is_sqlframe  s     ~....rv   c                N   [         R                  S[         R                  S[         R                  S[         R                  S[         R
                  S[         R                  S[         R                  S[         R                  S[         R                  S	[         R                  S
0
nX   $ )z0Friendly name for errors.

Returns:
    String.
PandasPolarsDaskIbisModincuDFPyArrowPySparkDuckDBSQLFrame)r   r   r   r   r   r   r   r   r   r   r   )r}   r   s     rw   _aliasImplementation._alias  s     !!8!!8  '""I""I!!8##Z8
 }rv   c                <   U R                  5       nU [        R                  [        R                  [        R                  1;  a  UnOLU [        R                  L a  [        5       nO.U [        R                  L a  [        5       nOSS KnUR                  n[        U5      $ Nr   )
r   r   r   r   r   r#   r   sqlframe._versionr   parse_version)r}   r   into_versionr   s       rw   r   Implementation._backend_version)  s    ))+""##
 

 "L^+++&=L^(((#:L$#,,L\**rv   rn   N)r   
type[Self]r   r3   r   r   )r   r)  r   rl   r   r   )r   r)  r   z!str | Implementation | ModuleTyper   r   )r   r3   )r   bool)r   r6   )r   r   )&rp   rq   rr   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r   r!  r   ru   rn   rv   rw   r   r      s[   IVF FE6DfG!fG!VF 6DVF 6DvH"fG!EE+5E	E E2 AA'*A	A A2 

"C
	
 
&."`- 
(I - + , . . + - + /   (+rv   r   )r         )   
   )   )r-     )r      r-  )i     )   )   )r-     r   z%dict[Implementation, tuple[int, ...]]MIN_VERSIONSc                N    U[         U    =n:  a  SU  SU SU 3n[        U5      eg )NzMinimum version of z supported by Narwhals is z	, found: )r7  
ValueError)implementationbackend_versionmin_versionr   s       rw   validate_backend_versionr=  K  sC     n)EE+F#N#33Mk]Zcdsctuo Grv   c                    U [         R                  L a  SSKJn  U$ U [         R                  L a  SSKJn  U$ SU  3n[        U5      e)Nr   )dtypesCongratulations, you have entered unreachable code.
Please report an issue at https://github.com/narwhals-dev/narwhals/issues.
Version: )r   r   narwhalsr?  r   narwhals.stable.v1r   )versionr?  	v1_dtypesr   s       rw   import_dtypes_modulerE  S  sL    ',,#	GJJ	:y" 	
 S!!rv   c                   [        U [        5      (       a  U $ [        U S5      (       a  U R                  $ S[         S[	        U 5      R
                  < 3n[        U5      e)Nr   z	Expected z	 but got )r   r   _hasattr_staticr   typerp   	TypeError)objr   s     rw   _into_versionrK  e  sR    #w
	j	)	)||gYiS	(:(:'=
>C
C.rv   c                   [        U 5      n U [        R                  L a  SSKJn  U$ U [        R
                  L a  SSKJn  U$ SU  3n[        U5      e)Nr   rD   r@  )rK  r   r   narwhals._namespacerE   r   narwhals.stable.v1._namespacer   )rC  rE   r   s      rw   import_namespacerO  n  sW    G$G',,1	GJJ	;y" 	
 S!!rv   c                N    U R                  U5      (       a  U [        U5      S  $ U $ r|   )
startswithlen)textprefixs     rw   remove_prefixrU    s'    vCKM""Krv   c                P    U R                  U5      (       a  U S [        U5      *  $ U $ r|   )endswithrR  )rS  suffixs     rw   remove_suffixrY    s)    }}VNs6{l##Krv   c                n    [        [        U 5      S:X  a  [        U S   5      (       a	  U S   5      $ U 5      $ )Nr4  r   )listrR  _is_iterable)argss    rw   flattenr^    s1    CIN|DG/D/DQPP4PPrv   c                B    [        U [        [        45      (       d  U 4$ U $ r|   )r   r[  tuple)args    rw   tupleifyrb    s    cD%=))vJrv   c                   SSK Jn  [        U 5      (       d  [        U 5      (       a  S[	        U 5       S3n[        U5      e[        5       =nbV  [        XR                  UR                  UR                  UR                  45      (       a  S[	        U 5       S3n[        U5      e[        U [        5      =(       a    [        U [        [        U45      (       + $ )Nr   rN   z(Expected Narwhals class or scalar, got: z2. Perhaps you forgot a `nw.from_native` somewhere?z`.

Hint: Perhaps you
- forgot a `nw.from_native` somewhere?
- used `pl.col` instead of `nw.col`?)narwhals.seriesrO   r*   r-   rH  rI  r!   r   ExprrI   rK   r   rl   bytes)ra  rO   r   r   s       rw   r\  r\    s    &3#3C#8#88cCuvnl'Jii",,=- - 7tCyk B3 3 	 nc8$RZc5&=Q-R)RRrv   c                    [        U [        5      (       a  U OU R                  n[        R                  " SSU5      n[        S UR                  S5       5       5      $ )zSimple version parser; split into a tuple of ints for comparison.

Arguments:
    version: Version string, or object with one, to parse.

Returns:
    Parsed version number.
z(\D?dev.*$) c              3  d   #    U  H&  n[        [        R                  " S SU5      5      v   M(     g7f)z\Drh  N)intresub).0vs     rw   	<genexpr> parse_version.<locals>.<genexpr>  s'     K4JqRVVE2q)**4Js   .0.)r   rl   rm   rk  rl  r`  split)rC  version_strs     rw   r&  r&    sK     (55'7;N;NK&&[9KKK4E4Ec4JKKKrv   c                    g r|   rn   
obj_or_clscls_or_tuples     rw   isinstance_or_issubclassrx    s     rv   c                    g r|   rn   ru  s     rw   rx  rx    s      rv   c                    g r|   rn   ru  s     rw   rx  rx    s     "rv   c                    g r|   rn   ru  s     rw   rx  rx    s     +.rv   c                    g r|   rn   ru  s     rw   rx  rx    s     %(rv   c                    g r|   rn   ru  s     rw   rx  rx    s     7:rv   c                    g r|   rn   ru  s     rw   rx  rx    s     rv   c                    SSK Jn  [        X5      (       a  [        X5      $ [        X5      =(       d"    [        U [        5      =(       a    [	        X5      $ )Nr   rL   )narwhals.dtypesrM   r   rH  
issubclass)rv  rw  rM   s      rw   rx  rx    sA    %*$$*33j/ :t$MJ)Mrv   c                   ^^ SSK Jm  SSK Jm  [        U4S jU  5       5      (       d  [        U4S jU  5       5      (       a  g SU  Vs/ s H  n[	        U5      PM     sn 3n[        U5      es  snf )Nr   rH   rJ   c              3  <   >#    U  H  n[        UT5      v   M     g 7fr|   r   )rm  itemrI   s     rw   ro  $validate_laziness.<locals>.<genexpr>  s     
954:dI&&5   c              3  <   >#    U  H  n[        UT5      v   M     g 7fr|   r  )rm  r  rK   s     rw   ro  r    s     :EDJtY''Er  zGThe items to concatenate should either all be eager, or all lazy, got: )narwhals.dataframerI   rK   allrH  rI  )itemsr  r   rI   rK   s      @@rw   validate_lazinessr    sf    ,,

95
999:E:::SlqTrlqdhUYZ^U_lqTrSs
tC
C. Uss   	A.c                :   SSK Jn  SSKJn  SS jn[	        SU 5      n[	        SU5      n[        [        USS5      U5      (       a  [        [        USS5      U5      (       a  U" UR                  R                  R                  5        U" UR                  R                  R                  5        UR                  UR                  R                  UR                  R                  R                  UR                  R                  R                     5      5      $ [        [        USS5      U5      (       a  [        [        USS5      U5      (       a  U" UR                  R                  R                  5        U" UR                  R                  R                  5        UR                  UR                  R                  UR                  R                  R                  UR                  R                  R                     5      5      $ [        [        USS5      U5      (       a  [        [        USS5      U5      (       a  U" UR                  R                  R                  5        U" UR                  R                  R                  5        UR                  UR                  R                  UR                  R                  R                  UR                  R                  R                     5      5      $ [        [        USS5      U5      (       a  [        [        USS5      U5      (       a  U" UR                  R                  R                  5        U" UR                  R                  R                  5        UR                  UR                  R                  UR                  R                  R                  UR                  R                  R                     5      5      $ [        U5      [        U5      :w  a%  S	[        U5       S
[        U5       3n[        U5      eU $ )ar  Align `lhs` to the Index of `rhs`, if they're both pandas-like.

Arguments:
    lhs: Dataframe or Series.
    rhs: Dataframe or Series to align with.

Returns:
    Same type as input.

Notes:
    This is only really intended for backwards-compatibility purposes,
    for example if your library already aligns indices for users.
    If you're designing a new library, we highly encourage you to not
    rely on the Index.
    For non-pandas-like inputs, this only checks that `lhs` and `rhs`
    are the same length.

Examples:
    >>> import pandas as pd
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_pd = pd.DataFrame({"a": [1, 2]}, index=[3, 4])
    >>> s_pd = pd.Series([6, 7], index=[4, 3])
    >>> df = nw.from_native(df_pd)
    >>> s = nw.from_native(s_pd, series_only=True)
    >>> nw.to_native(nw.maybe_align_index(df, s))
       a
    4  2
    3  1
r   )PandasLikeDataFrame)PandasLikeSeriesr   c                @    U R                   (       d  Sn[        U5      eg )Nz'given index doesn't have a unique index)	is_uniquer9  )indexr   s     rw   _validate_index*maybe_align_index.<locals>._validate_index   s    ;CS/! rv   _compliant_frameN_compliant_seriesz6Expected `lhs` and `rhs` to have the same length, got z and )r  r   r   None)narwhals._pandas_like.dataframer  narwhals._pandas_like.seriesr  r   r   getattrr  r   r  _with_compliant_with_nativelocr  rR  r9  )lhsrhsr  r  r  lhs_anyrhs_anyr   s           rw   maybe_align_indexr    sj   B D="
 5#G5#G+T24G 
WW&8$?AT
U
U0077==>0077==>&&$$11((//33G4L4L4S4S4Y4YZ
 	

 +T24G 
WW&94@BR
S
S0077==>1188>>?&&$$11((//33--44::
 	
 ,d35E 
WW&8$?AT
U
U1188>>?0077==>&&%%22))0044,,3399
 	
 ,d35E 
WW&94@BR
S
S1188>>?1188>>?&&%%22))0044--44::
 	
 7|s7|#Fs7|nTYZ]^eZfYghoJrv   c                    [        SU 5      nUR                  5       n[        U5      (       d  [        U5      (       a  UR                  $ g)a`  Get the index of a DataFrame or a Series, if it's pandas-like.

Arguments:
    obj: Dataframe or Series.

Returns:
    Same type as input.

Notes:
    This is only really intended for backwards-compatibility purposes,
    for example if your library already aligns indices for users.
    If you're designing a new library, we highly encourage you to not
    rely on the Index.
    For non-pandas-like inputs, this returns `None`.

Examples:
    >>> import pandas as pd
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_pd = pd.DataFrame({"a": [1, 2], "b": [4, 5]})
    >>> df = nw.from_native(df_pd)
    >>> nw.maybe_get_index(df)
    RangeIndex(start=0, stop=2, step=1)
    >>> series_pd = pd.Series([1, 2])
    >>> series = nw.from_native(series_pd, series_only=True)
    >>> nw.maybe_get_index(series)
    RangeIndex(start=0, stop=2, step=1)
r   N)r   	to_nativer+   r,   r  )rJ  obj_any
native_objs      rw   maybe_get_indexr  [  sC    : 5#G""$J
++/DZ/P/Prv   )r  c                  SSK Jn  [        SU 5      nUR                  5       nUb  Ub  Sn[        U5      eU(       d  Uc  Sn[        U5      eUb/  [	        U5      (       a  U Vs/ s H	  os" USS9PM     snOU" USS9nOUn[        U5      (       a9  UR                  UR                  R                  UR                  U5      5      5      $ [        U5      (       au  SSKJ	n	  U(       a  S	n[        U5      eU	" UUU R                  R                  U R                  R                  S
9nUR                  UR                  R                  U5      5      $ U$ s  snf )aU  Set the index of a DataFrame or a Series, if it's pandas-like.

Arguments:
    obj: object for which maybe set the index (can be either a Narwhals `DataFrame`
        or `Series`).
    column_names: name or list of names of the columns to set as index.
        For dataframes, only one of `column_names` and `index` can be specified but
        not both. If `column_names` is passed and `df` is a Series, then a
        `ValueError` is raised.
    index: series or list of series to set as index.

Returns:
    Same type as input.

Raises:
    ValueError: If one of the following condition happens:

        - none of `column_names` and `index` are provided
        - both `column_names` and `index` are provided
        - `column_names` is provided and `df` is a Series

Notes:
    This is only really intended for backwards-compatibility purposes, for example if
    your library already aligns indices for users.
    If you're designing a new library, we highly encourage you to not
    rely on the Index.

    For non-pandas-like inputs, this is a no-op.

Examples:
    >>> import pandas as pd
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_pd = pd.DataFrame({"a": [1, 2], "b": [4, 5]})
    >>> df = nw.from_native(df_pd)
    >>> nw.to_native(nw.maybe_set_index(df, "b"))  # doctest: +NORMALIZE_WHITESPACE
       a
    b
    4  1
    5  2
r   )r  r   z8Only one of `column_names` or `index` should be providedz3Either `column_names` or `index` should be providedT)pass_through)	set_indexz/Cannot set index using column names on a Series)r:  r;  )narwhals.translater  r   r9  r\  r+   r  r  r  r  r,   narwhals._pandas_like.utilsr  r   r   )
rJ  column_namesr  r  df_anyr  r   idxkeysr  s
             rw   maybe_set_indexr    sS   ^ -%F!!#JE$5HoEMCo E"" ;@@%3Ys.%@5t4 	 
++%%##001E1Ed1KL
 	
 
z	*	*9CCS/!00@@11BB	

 %%f&>&>&K&KJ&WXX5 As   $Ec                   [        SU 5      nUR                  5       n[        U5      (       aY  UR                  5       n[	        X#5      (       a  U$ UR                  UR                  R                  UR                  SS95      5      $ [        U5      (       aY  UR                  5       n[	        X#5      (       a  U$ UR                  UR                  R                  UR                  SS95      5      $ U$ )a  Reset the index to the default integer index of a DataFrame or a Series, if it's pandas-like.

Arguments:
    obj: Dataframe or Series.

Returns:
    Same type as input.

Notes:
    This is only really intended for backwards-compatibility purposes,
    for example if your library already resets the index for users.
    If you're designing a new library, we highly encourage you to not
    rely on the Index.
    For non-pandas-like inputs, this is a no-op.

Examples:
    >>> import pandas as pd
    >>> import polars as pl
    >>> import narwhals as nw
    >>> df_pd = pd.DataFrame({"a": [1, 2], "b": [4, 5]}, index=([6, 7]))
    >>> df = nw.from_native(df_pd)
    >>> nw.to_native(nw.maybe_reset_index(df))
       a  b
    0  1  4
    1  2  5
    >>> series_pd = pd.Series([1, 2])
    >>> series = nw.from_native(series_pd, series_only=True)
    >>> nw.maybe_get_index(series)
    RangeIndex(start=0, stop=2, step=1)
r   T)drop)r   r  r+   __native_namespace___has_default_indexr  r  r  reset_indexr,   r  )rJ  r  r  r   s       rw   maybe_reset_indexr    s    > 5#G""$J
++"779j;;N&&$$11*2H2Hd2H2ST
 	
 Z(("779j;;N&&%%22:3I3It3I3TU
 	
 Nrv   c                ,    [        XR                  5      $ r|   )r   
RangeIndex)rJ  r   s     rw   _is_range_indexr    s    c6677rv   c                    U R                   n[        X!5      =(       aD    UR                  S:H  =(       a.    UR                  [	        U5      :H  =(       a    UR
                  S:H  $ )Nr   r4  )r  r  startstoprR  step)native_frame_or_seriesr   r  s      rw   r  r    sT     #((E0 	KK1	JJ#e*$	 JJ!O	rv   c           	     f   [        SU 5      nUR                  5       n[        U5      (       a:  UR                  UR                  R                  UR                  " U0 UD65      5      $ [        U5      (       a:  UR                  UR                  R                  UR                  " U0 UD65      5      $ U$ )a  Convert columns or series to the best possible dtypes using dtypes supporting ``pd.NA``, if df is pandas-like.

Arguments:
    obj: DataFrame or Series.
    *args: Additional arguments which gets passed through.
    **kwargs: Additional arguments which gets passed through.

Returns:
    Same type as input.

Notes:
    For non-pandas-like inputs, this is a no-op.
    Also, `args` and `kwargs` just get passed down to the underlying library as-is.

Examples:
    >>> import pandas as pd
    >>> import polars as pl
    >>> import narwhals as nw
    >>> import numpy as np
    >>> df_pd = pd.DataFrame(
    ...     {
    ...         "a": pd.Series([1, 2, 3], dtype=np.dtype("int32")),
    ...         "b": pd.Series([True, False, np.nan], dtype=np.dtype("O")),
    ...     }
    ... )
    >>> df = nw.from_native(df_pd)
    >>> nw.to_native(
    ...     nw.maybe_convert_dtypes(df)
    ... ).dtypes  # doctest: +NORMALIZE_WHITESPACE
    a             Int32
    b           boolean
    dtype: object
r   )	r   r  r+   r  r  r  convert_dtypesr,   r  )rJ  r]  kwargsr  r  s        rw   maybe_convert_dtypesr    s    H 5#G""$J
++&&$$11))4:6:
 	

 Z((&&%%22))4:6:
 	

 Nrv   c                    US;   a  U $ US;   a  U S-  $ US;   a  U S-  $ US;   a  U S-  $ US;   a  U S	-  $ S
U< 3n[        U5      e)zScale size in bytes to other size units (eg: "kb", "mb", "gb", "tb").

Arguments:
    sz: original size in bytes
    unit: size unit to convert into

Returns:
    Integer or float.
>   brf  >   kb	kilobytesi   >   mb	megabytesi   >   gb	gigabytesi   @>   tb	terabytesl        z9`unit` must be one of {'b', 'kb', 'mb', 'gb', 'tb'}, got )r9  )szunitr   s      rw   scale_bytesr  R  ss     ~		$	$Dy	$	$G|	$	$G|	$	$G|KD8Torv   c                \   SSK Jn  [        U R                  R                  5      n[        U R                  U5      (       a=  U R                  UR                  :X  a#  U R                  R                  R                  S   $ U R                  UR                  :X  a  gU R                  UR                  :w  a  gU R                  5       n[        U5      (       a  UR                  R                  S:H  $ [        U5      (       a  [        UR                   R"                  5      $ [%        U5      (       a  UR                   R"                  $ ['        U5      (       a  UR                   R"                  $ [)        U5      (       a5  SSKJn  U" UR.                  5      =(       a    UR.                  R"                  $ g)a  Return whether indices of categories are semantically meaningful.

This is a convenience function to accessing what would otherwise be
the `is_ordered` property from the DataFrame Interchange Protocol,
see https://data-apis.org/dataframe-protocol/latest/API.html.

- For Polars:
  - Enums are always ordered.
  - Categoricals are ordered if `dtype.ordering == "physical"`.
- For pandas-like APIs:
  - Categoricals are ordered if `dtype.cat.ordered == True`.
- For PyArrow table:
  - Categoricals are ordered if `dtype.type.ordered == True`.

Arguments:
    series: Input Series.

Returns:
    Whether the Series is an ordered categorical.

Examples:
    >>> import narwhals as nw
    >>> import pandas as pd
    >>> import polars as pl
    >>> data = ["x", "y"]
    >>> s_pd = pd.Series(data, dtype=pd.CategoricalDtype(ordered=True))
    >>> s_pl = pl.Series(data, dtype=pl.Categorical(ordering="physical"))

    Let's define a library-agnostic function:

    >>> @nw.narwhalify
    ... def func(s):
    ...     return nw.is_ordered_categorical(s)

    Then, we can pass any supported library to `func`:

    >>> func(s_pd)
    True
    >>> func(s_pl)
    True
r   )InterchangeSeries
is_orderedTFphysical)is_dictionary)narwhals._interchange.seriesr  rE  r  r   r   dtypeCategoricalr   describe_categoricalr   r  r.   orderingr-   r*  catorderedr'   r&   r/   narwhals._arrow.utilsr  rH  )seriesr  r?  native_seriesr  s        rw   is_ordered_categoricalr  k  sJ   T ?!&":":"C"CDF 	6++->??LLF...''..CCLQQ||v{{"||v)))$$&M&&""++z99&&M%%--..}%%  (((m$$  (((..7]//0O]5G5G5O5OOrv   c                ,    Sn[        USS9  [        XS9$ )Nz}Use `generate_temporary_column_name` instead. `generate_unique_token` is deprecated and it will be removed in future versions1.13.0r   )n_bytesr   )issue_deprecation_warninggenerate_temporary_column_name)r  r   r   s      rw   generate_unique_tokenr    s#    	?  cH5)'KKrv   c                n    Sn [        U 5      nX1;  a  U$ US-  nUS:  a  SU < SU 3n[        U5      eM3  )a  Generates a unique column name that is not present in the given list of columns.

It relies on [python secrets token_hex](https://docs.python.org/3/library/secrets.html#secrets.token_hex)
function to return a string nbytes random bytes.

Arguments:
    n_bytes: The number of bytes to generate for the token.
    columns: The list of columns to check for uniqueness.

Returns:
    A unique token that is not present in the given list of columns.

Raises:
    AssertionError: If a unique token cannot be generated after 100 attempts.

Examples:
    >>> import narwhals as nw
    >>> columns = ["abc", "xyz"]
    >>> nw.generate_temporary_column_name(n_bytes=8, columns=columns) not in columns
    True
r   r4  d   zMInternal Error: Narwhals was not able to generate a column name with n_bytes=z and not in )r   r   )r  r   countertokenr   s        rw   r  r    s]    , G
'"L1S=*L	3  !%% rv   c                   U R                   n[        U5      nU(       a7  U Vs/ s H  oUU;  d  M
  UPM     nnU(       a  [        R                  " XcS9e U$ [        [	        U5      R                  [	        U5      5      5      nU$ s  snf )N)missing_columnsavailable_columns)r   r[  r0   'from_missing_and_available_column_namessetintersection)compliant_framer   strictcolsto_dropxr  s          rw   parse_columns_to_dropr    s    
 ""D7mG&-?g$1g?%MM /   N s4y--c'l;<N @s
   	BBc                Z    [        U [        5      =(       a    [        U [        5      (       + $ r|   )r   r   rl   )sequences    rw   is_sequence_but_not_strr    s    h)K*Xs2K.KKrv   c                L    [        U [        5      =(       a    U [        S 5      :H  $ r|   )r   slicerJ  s    rw   is_slice_noner    s    c5!8cU4[&88rv   c                   [        5       n[        U 5      =(       a=    [        U 5      S:  =(       a    [        U S   [        5      =(       d    [        U 5      S:H  =(       d}    [        U 5      =(       a&    UR                  U R                  UR                  5      =(       d>    [        U 5      =(       d    [        U 5      =(       a    U R                  R                  5       $ r$  )r   r  rR  r   rj  r)   
issubdtyper  integerr(   is_compliant_series
is_integer)rJ  nps     rw   is_sized_multi_index_selectorr    s    	B $C( Pc(Q,::c!fc#:NCA	
 c"Kr}}SYY

'K		
  $@(;C(@ '		$$&
rv   c                    [        U 5      =(       d/    [        U 5      =(       d    [        U 5      =(       d    [        U 5      $ r|   )r  r)   r(   r  r  s    rw   is_sequence_liker    s:     	 $ 	$S!	$c"	$ s#	rv   c                <   [        U [        5      =(       a    [        U R                  [        5      =(       de    [        U R                  [        5      =(       dD    [        U R
                  [        5      =(       a#    U R                  S L =(       a    U R                  S L $ r|   )r   r  r  rj  r  r  r  s    rw   is_slice_indexr	    sh    c5! 399c" 	Rchh$	Rsxx%P#))t*;PD@Prv   c                "    [        U [        5      $ r|   )r   ranger  s    rw   is_ranger    s    c5!!rv   c                l    [        [        U [        5      =(       a    [        U [         5      (       + 5      $ r|   )r*  r   rj  r  s    rw   is_single_index_selectorr  #  s#    
3$BZT-B)BCCrv   c                `    [        U 5      =(       d    [        U 5      =(       d    [        U 5      $ r|   )r  r  r	  r  s    rw   is_index_selectorr  '  s)     % 	(-	#rv   c                r    [        [        U [        5      =(       a    U =(       a    [        U S   U5      5      $ r$  )r*  r   r[  )rJ  tps     rw   
is_list_ofr  /  s)    
3%H#H*SVR2HIIrv   c                    SSK n SSKJn  SSKn[	        U" UR
                  5      R                  5      nU R                  5       nSn U(       aw  U R                  U5      nUR                  U5      (       d4  [        UR                  SS5      =n(       a(  UR                  S5      (       a  UR                  nUS-  nOO
U(       a  Mw   AU$ ! Af = f)zFind the first place in the stack that is not inside narwhals.

Returns:
    Stacklevel.

Taken from:
https://github.com/pandas-dev/pandas/blob/ab89c53f48df67709a533b6a95ce3d911871a0a8/pandas/util/_exceptions.py#L30-L51
r   N)Pathco_qualnamezsingledispatch.r4  )inspectpathlibr  rA  rl   __file__parentcurrentframegetfilerQ  r  f_codef_back)r  r  nwpkg_dirframenfnamequalnames           rw   find_stacklevelr%  4  s     $r{{#**+G   "E	AOOE*E(($U\\=$GGG''(9::Q e  H s   A<C	 C	 	Cc                2    [        U [        [        5       S9  g)zIssue a deprecation warning.

Arguments:
    message: The message associated with the warning.
    _version: Narwhals version when the warning was introduced. Just used for internal
        bookkeeping.
)messagecategory
stacklevelN)r   DeprecationWarningr%  )r'  r   s     rw   r  r  ^  s     	#5/BSTrv   c                   U c  Uc  UnU$ U b  Uc  U(       a  Sn[        USS9  U (       + nU$ U c  Ub   U$ Sn[        U5      e)Nz`strict` in `from_native` is deprecated, please use `pass_through` instead.

Note: `strict` will remain available in `narwhals.stable.v1`.
See https://narwhals-dev.github.io/narwhals/backcompat/ for more information.
r  r  z,Cannot pass both `strict` and `pass_through`)r  r9  )r  r  pass_through_defaultemit_deprecation_warningr   s        rw   validate_strict_and_pass_thoughr.  i  sy     ~,.+  
	 4#b 
 &cH=!z  
L4  =orv   rh  F)warn_versionrequiredc                   ^ ^ SUU 4S jjnU$ )a   Decorator to transition from `native_namespace` to `backend` argument.

Arguments:
    warn_version: Emit a deprecation warning from this version.
    required: Raise when both `native_namespace`, `backend` are `None`.

Returns:
    Wrapped function, with `native_namespace` **removed**.
c               :   >^  [        T 5      SU UU4S jj5       nU$ )Nc                   > UR                  SS 5      nUR                  SS 5      nUb  Uc  T(       a  Sn[        UTS9  UnO;Ub  Ub  Sn[        U5      eUc%  Uc"  T(       a  STR                   S3n[        U5      eX!S'   T" U 0 UD6$ )Nr   r   z`native_namespace` is deprecated, please use `backend` instead.

Note: `native_namespace` will remain available in `narwhals.stable.v1`.
See https://narwhals-dev.github.io/narwhals/backcompat/ for more information.
r  z0Can't pass both `native_namespace` and `backend`z `backend` must be specified in `z`.)popr  r9  rp   )r]  kwdsr   r   r   fnr0  r/  s        rw   wrapper=deprecate_native_namespace.<locals>.decorate.<locals>.wrapper  s    hhy$/G#xx(:DA+j 
 .cLI*!-'2EH o%!)go(8RH o%%Ot$t$$rv   )r]  P.argsr5  P.kwargsr   rh   r   )r6  r7  r0  r/  s   ` rw   decorate,deprecate_native_namespace.<locals>.decorate  s%    	r	% 	% 
	%* rv   )r6  Callable[P, R]r   r=  rn   )r/  r0  r;  s   `` rw   deprecate_native_namespacer>    s     2 Orv   c                z   U S:  a  Sn[        U5      e[        U [        5      (       d'  U R                  R                  nSU S3n[        U5      eUbe  US:  a  Sn[        U5      e[        U[        5      (       d'  UR                  R                  nSU S3n[        U5      eX:  a  Sn[        U5      e X4$ U nX4$ )Nr4  z+window_size must be greater or equal than 1zargument 'window_size': 'z,' object cannot be interpreted as an integerz+min_samples must be greater or equal than 1zargument 'min_samples': 'z6`min_samples` must be less or equal than `window_size`)r9  r   rj  	__class__rp   rI  r2   )window_sizemin_samplesr   _types       rw   _validate_rolling_argumentsrD    s     Q;ok3''%%..'w /( ( 	 n??CS/!+s++))22E+E7 3, ,  C. $JC',, % ## "##rv   c           
         [         R                  " 5       R                  nUR                  5       n[        S U 5       5      nUS-   U::  a  [        U[        U 5      5      nSSU-   S3nU[        U 5      -
  nUSS	US-  -   U  S	US-  US-  -   -   S
3-  nUSSU-   S
3-  nXT-
  S-  nXT-
  S-  XT-
  S-  -   n	U H$  n
USS	U-   U
 S	X-   [        U
5      -
  -   S
3-  nM&     USSU-   S3-  nU$ S[        U 5      -
  nSS SS	US-  -   U  S	US-  US-  -   -   SS S3	$ ! [         a$    [	        [         R
                  " SS5      5      n GN-f = f)NCOLUMNSP   c              3  8   #    U  H  n[        U5      v   M     g 7fr|   )rR  )rm  lines     rw   ro   generate_repr.<locals>.<genexpr>  s     >3t99      u   ┌u   ─u   ┐
| z|
-u   └u   ┘'   uu   ───────────────────────────────────────u   ┐
|u/   |
| Use `.to_native` to see native output |
└)	osget_terminal_sizer   OSErrorrj  getenv
splitlinesmaxrR  )headernative_reprterminal_widthnative_linesmax_native_widthlengthoutputheader_extrastart_extra	end_extrarI  diffs               rw   generate_reprrb    s   7--/77 ))+L>>>!~-%s6{3uv~&e,F+Ac\Q./0PQ@QT`cdTd@d9e8ffijjAcVn%S))0Q6.148QUV7VV	 D#-.tfSI<X[^_c[d<d5e4ffijjF !C's++FD
l^ 419vhsdai$(.B'C&D E9,c	'  7RYYy"567s   D! !*EEc                    Ub>  [        U5      R                  U 5      =n(       a  S[        U5       SU  3n[        U5      eg g )Nz
Column(s) z not found in )r  
differencesortedr0   )r   subsetmissingr   s       rw   check_column_existsrh    sL    #f+*@*@*IIwI6'?+>'C!#&&  Jrv   c                6   [        [        U 5      5      n[        U 5      U:w  ap  SSKJn  U" U 5      nUR	                  5        VVs0 s H  u  pEUS:  d  M  XE_M     nnnSR                  S UR	                  5        5       5      nSU 3n[        U5      eg s  snnf )Nr   )Counterr4  rh  c              3  8   #    U  H  u  pS U SU S3v   M     g7f)z
- 'z' z timesNrn   )rm  krn  s      rw   ro  0check_column_names_are_unique.<locals>.<genexpr>  s#     L9KaS1#V,9KrK  z"Expected unique column names, got:)rR  r  collectionsrj  r  joinr1   )r   len_unique_columnsrj  r  rl  rn  
duplicatesr   s           rw   check_column_names_are_uniquerr    s    S\*
7|))''"'.}}@tq!a%dad
@ggL9I9I9KLL23%8S!! * As   BBc                    U c  1 SkO"[        U [        5      (       a  U 1O
[        U 5      nUc  S 1OF[        U[        [        45      (       a  [        U5      1OU Vs1 s H  o3b  [        U5      OS iM     snnX$4$ s  snf )N>   smsnsus)r   rl   r  r   )	time_unit	time_zone
time_unitstz
time_zoness        rw   _parse_time_unit_and_time_zoner}     s      	  i%% [^   
 i#x11 )n<EFIbc"gT1IF  !! Gs   A;c                    [        XR                  5      =(       aF    U R                  U;   =(       a0    U R                  U;   =(       d    SU;   =(       a    U R                  S L$ )N*)r   Datetimerx  ry  )r  r?  rz  r|  s       rw   %dtype_matches_time_unit_and_time_zoner    sU     	5//* 	
__
*	
 OOz) Cz!AeooT&Arv   c                   U R                   $ r|   r   )r!  s    rw   get_column_namesr  "  s    ==rv   c                T    U R                    Vs/ s H  o"U;  d  M
  UPM     sn$ s  snf r|   r  )r!  namescol_names      rw   exclude_column_namesr  &  s#    %*]]L]e6KH]LLLs   	%%c                  ^  SU 4S jjnU$ )Nc                  > T$ r|   rn   )_framer  s    rw   r6  $passthrough_column_names.<locals>.fn+  s    rv   )r  r   r   r   rn   )r  r6  s   ` rw   passthrough_column_namesr  *  s     Irv   c                2    [        5       n[        XU5      UL$ r|   )objectr
   )rJ  attrsentinels      rw   rG  rG  1  s    xH#X.h>>rv   c                    [        U S5      $ )N__narwhals_dataframe__rG  r  s    rw   is_compliant_dataframer  6       3 899rv   c                    [        U S5      $ )N__narwhals_lazyframe__r  r  s    rw   is_compliant_lazyframer  <  r  rv   c                    [        U S5      $ )N__narwhals_series__r  r  s    rw   r  r  B  s     3 566rv   c                    [        U S5      $ )N__narwhals_expr__hasattrr  s    rw   is_compliant_exprr  H  s     3+,,rv   c                    U [         R                  [         R                  [         R                  [         R                  [         R
                  1;   $ r|   )r   r   r   r   r   r   r  s    rw   is_eager_allowedr  N  sA      rv   c                    [        U S5      $ )Nr  r  r  s    rw   has_native_namespacer  X  s    3.//rv   c                    [        U S5      $ )N__dataframe__r  r  s    rw   _supports_dataframe_interchanger  \  s    3((rv   c                    [        U S5      $ )N__arrow_c_stream__r  r  s    rw   supports_arrow_c_streamr  `  s    3 455rv   c                H   ^ ^ U U4S jU 5       n[        [        X5      5      $ )a+  Remap join keys to avoid collisions.

If left keys collide with the right keys, append the suffix.
If there's no collision, let the right keys be.

Arguments:
    left_on: Left keys.
    right_on: Right keys.
    suffix: Suffix to append to right keys.

Returns:
    A map of old to new right keys.
c              3  >   >#    U  H  oT;   a  U T 3OUv   M     g 7fr|   rn   )rm  keyleft_onrX  s     rw   ro  (_remap_full_join_keys.<locals>.<genexpr>t  s&      ?G7N3%x3xs   )dictzip)r  right_onrX  right_keys_suffixeds   ` ` rw   _remap_full_join_keysr  d  s%     ?G H233rv   c                   [        S5      (       aI  SSKnSSKJn  UR                  nU" [        U5      US9nUR                  R                  XS9R                  $ S[        U 5      R                  < S3n[        U5      e)	zGuards `ArrowDataFrame.from_arrow` w/ safer imports.

Arguments:
    data: Object which implements `__arrow_c_stream__`.
    context: Initialized compliant object.

Returns:
    A PyArrow Table.
r   r   N)ArrowNamespace)r;  rC  )contextz@PyArrow>=14.0.0 is required for `from_arrow` for object of type rq  )r	   r   narwhals._arrow.namespacer  r   r&  
_dataframe
from_arrowr   rH  rp   ModuleNotFoundError)datar  r   r  rC  rv  r   s          rw   _into_arrow_tabler  z  sw     <""M",=wO}}'''9@@@PQUVZQ[QdQdPgghi!#&&rv   c                   U $ )a  Visual-only marker for unstable functionality.

Arguments:
    fn: Function to decorate.

Returns:
    Decorated function (unchanged).

Examples:
    >>> from narwhals.utils import unstable
    >>> @unstable
    ... def a_work_in_progress_feature(*args):
    ...     return args
    >>>
    >>> a_work_in_progress_feature.__name__
    'a_work_in_progress_feature'
    >>> a_work_in_progress_feature(1, 2, 3)
    (1, 2, 3)
rn   )r6  s    rw   unstabler    s	    ( Irv   )r-     
deprecatedc                   SS jnU$ )Nc                   U $ r|   rn   )funcs    rw   r7  deprecated.<locals>.wrapper  s    Krv   )r  rf   r   rf   rn   )r'  r7  s     rw   r  r    s    	 rv   c                  r    \ rS rSrSrSSS jjrSS jrSS jr S     SS jjrSS jr	\
SS	 j5       rS
rg)not_implementedi  aI  Mark some functionality as unsupported.

Arguments:
    alias: optional name used instead of the data model hook [`__set_name__`].

Returns:
    An exception-raising [descriptor].

Notes:
    - Attribute/method name *doesn't* need to be declared twice
    - Allows different behavior when looked up on the class vs instance
    - Allows us to use `isinstance(...)` instead of monkeypatching an attribute to the function

Examples:
    >>> from narwhals.utils import not_implemented
    >>> class Thing:
    ...     def totally_ready(self) -> str:
    ...         return "I'm ready!"
    ...
    ...     not_ready_yet = not_implemented()
    >>>
    >>> thing = Thing()
    >>> thing.totally_ready()
    "I'm ready!"
    >>> thing.not_ready_yet()
    Traceback (most recent call last):
        ...
    NotImplementedError: 'not_ready_yet' is not implemented for: 'Thing'.
    ...
    >>> isinstance(Thing.not_ready_yet, not_implemented)
    True

[`__set_name__`]: https://docs.python.org/3/reference/datamodel.html#object.__set_name__
[descriptor]: https://docs.python.org/3/howto/descriptor.html
Nc                   Xl         g r|   )r!  )r}   aliass     rw   __init__not_implemented.__init__  s	     #(rv   c                f    S[        U 5      R                   SU R                   SU R                   3$ )N<z>: rq  )rH  rp   _name_owner_namer   s    rw   __repr__not_implemented.__repr__  s1    4:&&'s4+;+;*<Adjj\JJrv   c                Z    UR                   U l        U R                  =(       d    UU l        g r|   )rp   r  r!  r  )r}   r   names      rw   __set_name__not_implemented.__set_name__  s     %++-
rv   c               f    Uc  U $ [        USU R                  5      n[        U R                  U5      e)Nr   )r  r  _not_implemented_errorr  )r}   r~   r   whos       rw   r   not_implemented.__get__  s9      K h 143C3CD$TZZ55rv   c                $    U R                  S5      $ )Nraise)r   )r}   r]  r5  s      rw   __call__not_implemented.__call__  s     ||G$$rv   c               2    U " 5       n[        U5      " U5      $ )zAlt constructor, wraps with `@deprecated`.

Arguments:
    message: **Static-only** deprecation message, emitted in an IDE.

Returns:
    An exception-raising [descriptor].

[descriptor]: https://docs.python.org/3/howto/descriptor.html
r  )r   r'  rJ  s      rw   r  not_implemented.deprecated   s     e'"3''rv   )r!  r  r  r|   )r  z
str | Noner   r  )r   rl   )r   type[_T]r  rl   r   r  )r~   z_T | Literal['raise'] | Noner   ztype[_T] | Noner   r   )r]  r   r5  r   r   r   )r'  r6   r   r8   )rp   rq   rr   rs   r   r  r  r  r   r  r+  r  ru   rn   rv   rw   r  r    sU    "H(
K. PT646=L6	6%
 ( (rv   r  c               ,    U < SU< S3n[        U5      $ )Nz is not implemented for: z.

If you would like to see this functionality in `narwhals`, please open an issue at: https://github.com/narwhals-dev/narwhals/issues)NotImplementedError)whatr  r   s      rw   r  r    s,    (+C7 3S 	S 
 s##rv   c                  n    \ rS rSr% SrS\S'   S\S'   \SSS jj5       r\SS j5       r	SS	 jr
SS
 jrSrg)requiresi  a  Method decorator for raising under certain constraints.

Attributes:
    _min_version: Minimum backend version.
    _hint: Optional suggested alternative.

Examples:
    >>> from narwhals.utils import requires, Implementation
    >>> class SomeBackend:
    ...     _implementation = Implementation.PYARROW
    ...     _backend_version = 20, 0, 0
    ...
    ...     @requires.backend_version((9000, 0, 0))
    ...     def really_complex_feature(self) -> str:
    ...         return "hello"
    >>> backend = SomeBackend()
    >>> backend.really_complex_feature()
    Traceback (most recent call last):
        ...
    NotImplementedError: `really_complex_feature` is only available in PyArrow>='9000.0.0', found version '20.0.0'.
r   _min_versionrl   _hintc               @    U R                  U 5      nXl        X#l        U$ )zMethod decorator for raising below a minimum `_backend_version`.

Arguments:
    minimum: Minimum backend version.
    hint: Optional suggested alternative.

Returns:
    An exception-raising decorator.
)__new__r  r  )r   minimumhintrJ  s       rw   r;  requires.backend_version3  s"     kk#"	
rv   c               2    SR                  S U  5       5      $ )Nrq  c              3  &   #    U  H  o v   M	     g 7fr|   rn   )rm  ds     rw   ro  ,requires._unparse_version.<locals>.<genexpr>E  s     81#s   )ro  )r;  s    rw   _unparse_versionrequires._unparse_versionC  s    xx8888rv   c          	     d   UR                   U R                  :  a  g U R                  nUR                  R                  nU R                  U R                  5      nU R                  UR                   5      nSU SU SU< SU< S3	nU R                  (       a  U SU R                   3n[        U5      e)N`z` is only available in z>=z, found version rq  
)r   r  _wrapped_namer   r!  r  r  r  )r}   r~   methodr   r  foundr   s          rw   _ensure_versionrequires._ensure_versionG  s    $$(9(99##**11''(9(9:%%h&?&?@&0	G;FVW\V__`a::EDJJ<(C!#&&rv   c               Z   ^ ^ TR                   T l        [        T5      SUU 4S jj5       nU$ )Nc                >   > TR                  U 5        T" U /UQ70 UD6$ r|   )r  )r~   r]  r5  r6  r}   s      rw   r7  "requires.__call__.<locals>.wrapperV  s&      *h....rv   )r~   r   r]  r9  r5  r:  r   rh   )rp   r  r   )r}   r6  r7  s   `` rw   r  requires.__call__S  s,    [[	r	/ 
	/
 rv   )r  N)rh  )r  rl   r  r   r   r8   )r;  r   r   rl   )r~   r   r   r  )r6  _Method[_ContextT, P, R]r   r   )rp   rq   rr   rs   r   rt   r+  r;  staticmethodr  r  r  ru   rn   rv   rw   r  r    sD    , "!J  9 9
'	rv   r  c                    U R                   b  UR                  U R                   5      OS nU R                  b  UR                  U R                  5      S-   OS nU R                  nX#U4$ )Nr4  )r  r  r  r  )	str_slicer   r  r  r  s        rw   convert_str_slice_to_int_slicer  _  sX     /8oo.IGMM)//*tE090J7==(1,PTD>>Drv   )r:  r   r;  r   r   r  )rC  r   r   rT   )rJ  Version | _StoresVersionr   r   )rC  r  r   ztype[Namespace[Any]])rS  rl   rT  rl   r   rl   )rS  rl   rX  rl   r   rl   )r]  r   r   z	list[Any])ra  r   r   r   )ra  zAny | Iterable[Any]r   r*  )rC  z#str | ModuleType | _SupportsVersionr   r   )rv  rH  rw  r  r   zTypeIs[type[_T]])rv  object | typerw  r  r   zTypeIs[_T | type[_T]])rv  rH  rw  tuple[type[_T1], type[_T2]]r   zTypeIs[type[_T1 | _T2]])rv  r  rw  r  r   z#TypeIs[_T1 | _T2 | type[_T1 | _T2]])rv  rH  rw  &tuple[type[_T1], type[_T2], type[_T3]]r   zTypeIs[type[_T1 | _T2 | _T3]])rv  r  rw  r  r   z/TypeIs[_T1 | _T2 | _T3 | type[_T1 | _T2 | _T3]])rv  r   rw  ztuple[type, ...]r   zTypeIs[Any])rv  r   rw  r   r   r*  )r  zIterable[Any]r   r  )r  r`   r  z-Series[Any] | DataFrame[Any] | LazyFrame[Any]r   r`   )rJ  z-DataFrame[Any] | LazyFrame[Any] | Series[Any]r   r   r|   )rJ  r`   r  zstr | list[str] | Noner  z6Series[IntoSeriesT] | list[Series[IntoSeriesT]] | Noner   r`   )rJ  r`   r   r`   )rJ  r   r   r   r   zTypeIs[pd.RangeIndex])r  zpd.Series[Any] | pd.DataFramer   r   r   r*  )rJ  r`   r]  r*  r  z
bool | strr   r`   )r  rj  r  rY   r   zint | float)r  zSeries[Any]r   r*  )r  rj  r   r   r   rl   )r  r   r   zIterable[str]r  r*  r   z	list[str])r  Sequence[_T] | Anyr   zTypeIs[Sequence[_T]])rJ  r   r   zTypeIs[_SliceNone])rJ  r   r   z$TypeIs[SizedMultiIndexSelector[Any]])rJ  r	  r   z-TypeIs[Sequence[_T] | Series[Any] | _1DArray])rJ  r   r   zTypeIs[_SliceIndex])rJ  r   r   zTypeIs[range])rJ  r   r   zTypeIs[SingleIndexSelector])rJ  r   r   z5TypeIs[SingleIndexSelector | MultiIndexSelector[Any]])rJ  r   r  r  r   zTypeIs[list[_T]])r   rj  )r'  rl   r   rl   r   r  )
r  bool | Noner  r
  r,  r*  r-  r*  r   r*  )r/  rl   r0  r*  r   z*Callable[[Callable[P, R]], Callable[P, R]])rA  rj  rB  z
int | Noner   ztuple[int, int])rW  rl   rX  rl   r   rl   )r   r   rf  zSequence[str] | Noner   r  )r   r   r   r  )rx  z$TimeUnit | Iterable[TimeUnit] | Nonery  z7str | timezone | Iterable[str | timezone | None] | Noner   z%tuple[Set[TimeUnit], Set[str | None]])
r  rM   r?  rT   rz  zSet[TimeUnit]r|  zSet[str | None]r   r*  )r!  r   r   r   )r!  r   r  zContainer[str]r   r   )r  r   r   zEvalNames[Any])rJ  r   r  rl   r   r*  )rJ  zKCompliantDataFrame[CompliantSeriesT, CompliantExprT, NativeFrameT_co] | Anyr   zMTypeIs[CompliantDataFrame[CompliantSeriesT, CompliantExprT, NativeFrameT_co]])rJ  z9CompliantLazyFrame[CompliantExprT, NativeFrameT_co] | Anyr   z;TypeIs[CompliantLazyFrame[CompliantExprT, NativeFrameT_co]])rJ  z'CompliantSeries[NativeSeriesT_co] | Anyr   z)TypeIs[CompliantSeries[NativeSeriesT_co]])rJ  zECompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co] | Anyr   zGTypeIs[CompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co]])rJ  r   r   z"TypeIs[EagerAllowedImplementation])rJ  r   r   zTypeIs[SupportsNativeNamespace])rJ  r   r   zTypeIs[DataFrameLike])rJ  r   r   zTypeIs[ArrowStreamExportable])r  r   r  r   rX  rl   r   zdict[str, str])r  rG   r  r   r   zpa.Table)r6  rf   r   rf   )r'  rl   r   zCallable[[_Fn], _Fn])r  rl   r  rl   r   r  )r  r^   r   r   r   z"tuple[int | None, int | None, Any])
__future__r   rQ  rk  datetimer   enumr   r   	functoolsr   importlib.utilr	   r  r
   secretsr   typingr   r   r   r   r   r   r   r   r   r   r   r   warningsr   narwhals.dependenciesr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   narwhals.exceptionsr0   r1   r2   typesr3   r4   Setr   r   r   r   typing_extensionsr5   r6   r7   r8   r9   r:   narwhals._compliantr;   r<   r=   r>   r?   r@   rA   narwhals._compliant.typingrB   rM  rC   rE   narwhals._translaterF   rG   r  rI   rK   r  rM   rd  rO   narwhals.typingrP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rb   rc   rd   re   rf   rg   rh   rj   ry   r   r   r   r   r   r   r   r   r   r   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r7  r=  rE  rK  rO  rU  rY  r^  rb  r\  r&  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r%  r  r.  r>  rD  rb  rh  rr  r}  r  r  r  r  rG  r  r  r  r  r  r  r  r  r  r  r  sysversion_infor  r  r  r  r  rn   rv   rw   <module>r     s   " 	 	     $ "                * * 4 , * + + , , - - 1 . 0 1 4 3 5 : 7 2 2 : 3 . 5 )-/+&+(123C4344>-92,,%&22/-&+237(7((+**ininfSk&Q RN 
B
%.C
%.C
%.C
%3
4C#AA8 Rx RN N2 21 1/ ,ox 0 0
 \T2
48K~6	= =HZ( x. d 
}+T }+B :*EF:4Z73 "5D	"$"&QS(L" 
$, 

 
  -5   
 
 
""$?"" 
"
 
..-H.(. 
.
 
(($J("( 
(
 
::-S:4: 
:
 
#3 

	\	\K\\~!L ,0X EI	X	X(X B	X
 Xv/d8
	9	MP			2	2 $20:22j2EPLL(LL"&J  	$L9	2"DJ
'TU 	
 # 
6 &&)-&/&R!$!$#-!$!$H<'	""3"F" +"*

 
.;
IX
	
M?
:	T:R::	B:@:7	07.7-	N-L-0)644&34=@44,'2. 
7" 	6>Q( Q(h$C CL$1'rv   