
    hy                    \   % S SK Jr  S SKrS SKrS SKJr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  S SKJr  S SKJrJr  S S	K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%  S SK&J'r'  S SK(J)r)  S SK*J+r+J,r,  S SK-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@  S SKAJBrBJCrCJDrD  \(       Ga   S SKJErE  S SKFJGrG  S SKHrIS SKJrKS SKLrMS SKNJOrOJPrPJQrQJRrRJSrSJTrT  S SKUJVrVJWrWJXrXJYrYJZrZJ[r[J\r\  S SK]J^r^  S SK_J`r`Jara  S SKbJcrcJdrdJere  S SKfJgrgJhrh  S SKiJjrj  S SKkJlrl  S SKmJnrnJoroJprpJqrqJrrrJsrsJtrtJuruJvrvJwrwJxrxJyryJzrzJ{r{J|r|J}r}  \"" S\#\h\   \g\   \l\   4   S9r~\"" S5      r\"" S5      r\"" S5      r\"" S 5      r\"" S!5      r\"" S"5      r\"" S#5      r\"" S$S%S9r\Q" S&5      r\"" S'5      r\"" S(5      r\"" S)5      r " S* S+\!5      r " S, S-\!5      r " S. S/\!5      r\"" S05      r\"" S1S2S39r\"" S4S2S39r\"" S5S6S9rS7rS8\S9'   S:rS8\S;'    " S< S=\!\   5      r " S> S?\!\   5      r " S@ SA\!5      r " SB SC\!5      r " SD SE\!5      r " SF SG\\\!5      r " SH S6\\\!5      r " SI SJ\\!5      r " SK SL\5      r " SM SN\'5      r\GR>                  SO\GR@                  SP\GRB                  SQ\GRD                  SR\GRF                  SS\GRH                  SS\GRJ                  ST\GRL                  SU\GRN                  SV\GRP                  SW\GRR                  SX0rSY\SZ'   \GRL                  S[\GR@                  S\\GRF                  S]\GRH                  S^0rS_\S`'    \" SaSb9SSc j5       r\SSd j5       rSSe jrSSf jrSSg jrSSh jr\%      SSi j5       r\%      SSj j5       r\%      SSk j5       r\%      SSl j5       r\%      SSm j5       r\%      SSn j5       r\%      SSo j5       r\%      SSp j5       r\%      SSq j5       r\%      SSr j5       r\%      SSs j5       r\%      SSt j5       r\%      SSu j5       r\%      SSv j5       r\%      SSw j5       rSSx jrSSy jr      SSz 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r    SS jr    SS jrSS jrSS jrSS jr    SS jrSS jrSS jr        SS jrSSS.     SS jjr      SS jrSS jr      SS jrSS jr      SS jr          SS jrSS jrSS jrSS jrSS jr    SS jr    SS jr    SS jr    SS jr    SS jrSS jrSS jrSS jrSS jr        SS jrSS jrSS jrSS jr " S S5      rSS jr " S S5      r      SS jr    GS S jrGSS jrSS.GSS jjr " S S\\   5      rg(      )annotationsN)
Collection	ContainerIterableIteratorMappingSequence)timezone)Enumauto)cache	lru_cachewraps)	find_spec)getattr_staticgetdoc)	token_hex)
TYPE_CHECKINGAnyCallableGenericLiteralProtocolTypeVarUnioncastoverload)
NoAutoEnum)issue_deprecation_warning)assert_never
deprecated)get_cudfget_dask_dataframe
get_duckdbget_ibis	get_modin
get_pandas
get_polarsget_pyarrowget_pyspark_connectget_pyspark_sqlget_sqlframeis_narwhals_seriesis_narwhals_series_intis_numpy_array_1dis_numpy_array_1d_intis_pandas_like_dataframeis_pandas_like_seriesis_polars_seriesis_pyarrow_chunked_array)ColumnNotFoundErrorDuplicateErrorInvalidOperationError)Set)
ModuleType)ConcatenateLiteralString	ParamSpecSelf	TypeAliasTypeIs)CompliantExprCompliantExprTCompliantFrameTCompliantSeriesOrNativeExprT_coCompliantSeriesTNativeFrameT_coNativeSeriesT_co)	EvalNames)EagerAllowedImplementation	Namespace)ArrowStreamExportableIntoArrowTableToNarwhalsT_co	DataFrame	LazyFrameDTypeSeries)CompliantDataFrameCompliantLazyFrameCompliantSeriesDataFrameLikeDTypesIntoSeriesTMultiIndexSelectorSingleIndexSelectorSizedMultiIndexSelectorSizeUnitSupportsNativeNamespaceTimeUnit_1DArray_SliceIndex
_SliceName
_SliceNoneFrameOrSeriesT)bound_T1_T2_T3_T4_T5_T6_T7_FnzCallable[..., Any]PRR1R2c                       \ rS rSr% S\S'   Srg)_SupportsVersionv   str__version__ N__name__
__module____qualname____firstlineno____annotations____static_attributes__rw       bC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\narwhals/_utils.pyrs   rs   v   s    r   rs   c                  "    \ rS rSrSSS jjrSrg)_SupportsGety   Nc                   g Nrw   )selfinstanceowners      r   __get___SupportsGet.__get__z   s    cr   rw   r   )r   r   r   
Any | Nonereturnr   )ry   rz   r{   r|   r   r~   rw   r   r   r   r   y   s    QQr   r   c                  (    \ rS rSr\SS j5       rSrg)_StoresColumns|   c                    g r   rw   r   s    r   columns_StoresColumns.columns}   s    ,/r   rw   N)r   Sequence[str])ry   rz   r{   r|   propertyr   r~   rw   r   r   r   r   |   s    	/ 
/r   r   _T
NativeT_coT)	covariantCompliantT_co	_ContextT_FullContextz&Callable[Concatenate[_ContextT, P], R]r>   _Methodz Callable[Concatenate[_T, P], R2]_Constructorc                  ,    \ 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.Nrw   r   s    r   native_StoresNative.native        	r   rw   N)r   r   )ry   rz   r{   r|   __doc__r   r   r~   rw   r   r   r   r            r   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.Nrw   r   s    r   	compliant_StoresCompliant.compliant   r   r   rw   N)r   r   )ry   rz   r{   r|   r   r   r   r~   rw   r   r   r   r      r   r   r   c                  (    \ rS rSr\SS j5       rSrg)_StoresBackendVersion   c                    g)z#Version tuple for a native package.Nrw   r   s    r   _backend_version&_StoresBackendVersion._backend_version   r   r   rw   Nr   tuple[int, ...])ry   rz   r{   r|   r   r   r~   rw   r   r   r   r      s     r   r   c                       \ rS rSr% S\S'   Srg)_StoresVersion   Version_versionrw   Nrx   rw   r   r   r   r      s    ,r   r   c                       \ rS rSr% S\S'   Srg)_StoresImplementation   Implementation_implementationrw   Nrx   rw   r   r   r   r      s    ##Ir   r   c                      \ rS rSrSrSrg)_LimitedContext   z9Provides 2 attributes.

- `_implementation`
- `_version`
rw   Nry   rz   r{   r|   r   r~   rw   r   r   r   r      s    r   r   c                      \ rS rSrSrSrg)r      zNProvides 3 attributes.

- `_implementation`
- `_backend_version`
- `_version`
rw   Nr   rw   r   r   r   r      s    r   c                  "    \ rS rSrSrSS jrSrg)ValidateBackendVersion   z=Ensure the target `Implementation` is on a supported version.c                8    U R                   R                  5       ng)zRaise if installed version below `nw._utils.MIN_VERSIONS`.

**Only use this when moving between backends.**
Otherwise, the validation will have taken place already.
N)r   r   )r   _s     r   _validate_backend_version0ValidateBackendVersion._validate_backend_version   s       113r   rw   N)r   None)ry   rz   r{   r|   r   r   r~   rw   r   r   r   r      s
    G4r   r   c                      \ rS rS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5       r\SS j5       rSrg)r      c                ~    U [         R                  L a  SSKJn  U$ U [         R                  L a  SSKJn  U$ SSKJn  U$ )Nr   )rI   )r   V1narwhals.stable.v1._namespacerI   V2narwhals.stable.v2._namespacenarwhals._namespace)r   NamespaceV1NamespaceV2rI   s       r   	namespaceVersion.namespace   s5    7::N7::N1r   c                ~    U [         R                  L a  SSKJn  U$ U [         R                  L a  SSKJn  U$ SSKJn  U$ )Nr   )dtypes)r   r   narwhals.stable.v1r   r   narwhals.stable.v2narwhals)r   	dtypes_v1	dtypes_v2r   s       r   r   Version.dtypes   s4    7::>7::>#r   c                ~    U [         R                  L a  SSKJn  U$ U [         R                  L a  SSKJn  U$ SSKJn  U$ )Nr   )rN   )r   r   r   rN   r   r   narwhals.dataframe)r   DataFrameV1DataFrameV2rN   s       r   	dataframeVersion.dataframe   5    7::C7::C0r   c                ~    U [         R                  L a  SSKJn  U$ U [         R                  L a  SSKJn  U$ SSKJn  U$ )Nr   )rO   )r   r   r   rO   r   r   r   )r   LazyFrameV1LazyFrameV2rO   s       r   	lazyframeVersion.lazyframe  r   r   c                ~    U [         R                  L a  SSKJn  U$ U [         R                  L a  SSKJn  U$ SSKJn  U$ )Nr   rR   )r   r   r   rS   r   r   narwhals.series)r   SeriesV1SeriesV2rS   s       r   seriesVersion.series  s2    7::=O7::=O*r   rw   N)r   ztype[Namespace[Any]])r   rX   )r   ztype[DataFrame[Any]])r   ztype[LazyFrame[Any]])r   ztype[Series[Any]])ry   rz   r{   r|   r   r   r   MAINr   r   r   r   r   r   r~   rw   r   r   r   r      sy    	B	B6D         r   r   c                  `   \ rS rSrSrSr Sr Sr Sr Sr	 Sr
 S	r S
r Sr Sr Sr Sr S$S j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r#S*S! jr$S"r%g#)+r   i!  z?Implementation of native object (pandas, Polars, PyArrow, ...).pandasmodincudfpyarrowpysparkpolarsdaskduckdbibissqlframezpyspark[connect]unknownc                ,    [        U R                  5      $ r   )ru   valuer   s    r   __str__Implementation.__str__=  s    4::r   c                V   [        5       [        R                  [        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[        R0                  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,   SQLFRAMEr*   PYSPARK_CONNECTgetUNKNOWN)clsnative_namespacemappings      r   from_native_namespace$Implementation.from_native_namespace@  s     L.//K--J++M>11~55L.// ."5"5L.//J++NN33!>#A#A
 {{+^-C-CDDr   c                T     U " U5      $ ! [          a    [        R                  s $ f = f)zInstantiate Implementation object from a native namespace module.

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

Returns:
    Implementation.
)
ValueErrorr   r  )r  backend_names     r   from_stringImplementation.from_string[  s-    	*|$$ 	*!)))	*s   
 ''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.
)
isinstanceru   r  r   r  )r  backends     r   from_backendImplementation.from_backendl  sR     '3'' OOG$	
 '>22 	

 **73	
r   c                    U [         R                  L a  Sn[        U5      eU R                  5         [        R                  X R                  5      n[        U5      $ )zaReturn the native namespace module corresponding to Implementation.

Returns:
    Native module.
z:Cannot return native namespace from UNKNOWN Implementation)r   r  AssertionErrorr   _IMPLEMENTATION_TO_MODULE_NAMEr  r  _import_native_namespace)r   msgmodule_names      r   to_native_namespace"Implementation.to_native_namespace  sM     >)))NC %%488zzJ'44r   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    r   	is_pandasImplementation.is_pandas       ~,,,,r   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    r   is_pandas_likeImplementation.is_pandas_like  s(     --~/C/C^EXEXYYYr   c                f    U [         R                  [         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  r   s    r   is_spark_likeImplementation.is_spark_like  s1     ""##**
 
 	
r   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    r   	is_polarsImplementation.is_polars  r,  r   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    r   is_cudfImplementation.is_cudf       ~****r   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    r   is_modinImplementation.is_modin  s     ~++++r   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    r   
is_pysparkImplementation.is_pyspark       ~----r   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_connect()
    False
)r   r  r   s    r   is_pyspark_connect!Implementation.is_pyspark_connect  s     ~5555r   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    r   
is_pyarrowImplementation.is_pyarrow  r@  r   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    r   is_daskImplementation.is_dask"  r9  r   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    r   	is_duckdbImplementation.is_duckdb2  r,  r   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    r   is_ibisImplementation.is_ibisB  r9  r   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    r   is_sqlframeImplementation.is_sqlframeR  s     ~....r   c                    [        U 5      $ )zReturns backend version.backend_versionr   s    r   r   Implementation._backend_versionb  s    t$$r   rw   Nr   ru   )r  
type[Self]r  r9   r   r   )r  rX  r  ru   r   r   )r  rX  r  z!str | Implementation | ModuleTyper   r   )r   r9   )r   boolr   )&ry   rz   r{   r|   r   r  r  r  r  r	  r
  r  r  r  r  r  r  r  classmethodr  r  r  r'  r*  r.  r1  r4  r7  r;  r>  rB  rE  rH  rK  rN  rQ  r   r~   rw   r   r   r   r   !  s?   IF EDG!G!F DF DH"(O)G! EE+5E	E E4 **'**	* *  

"C
	
 
&5- Z 
(- + , . 6 . + - + / %r   r   )   r[     )r         )   
   )   )r\     )r         )i  r]  )r[  )   )r\     r   z(Mapping[Implementation, tuple[int, ...]]MIN_VERSIONSzdask.dataframezmodin.pandaszpyspark.sqlzpyspark.sql.connectzMapping[Implementation, str]r#     )maxsizec                    SSK Jn  U" U 5      $ )Nr   )import_module)	importlibrk  )r&  rk  s     r   r$  r$  ~  s    '%%r   c               (   [        U [        5      (       d  [        U 5        U [        R                  L a  Sn[	        U5      eU n[
        R                  X"R                  5      n[        U5      nUR                  5       (       a  SS K
nUR                  nOOUR                  5       (       d  UR                  5       (       a  SS KnUnOUR                  5       (       a  SS KnUnOUn[#        U5      n	U	[$        U   =n
:  a  SU SU
 SU	 3n['        U5      eU	$ )Nz9Cannot return backend version from UNKNOWN Implementationr   zMinimum version of z supported by Narwhals is z	, found: )r  r   r    r  r"  r#  r  r  r$  rQ  sqlframe._versionr   r>  rB  r   rH  r   parse_versionrg  r  )implementationr%  implr&  r  r   into_versionr   r   versionmin_versions              r   rU  rU    s    nn55^$///IS!!D044T::FK/< ((			d5577	'L)Gd!33+4#D6)CK=PYZaYbcoNr   c                n    [        [        U 5      S:X  a  [        U S   5      (       a	  U S   5      $ U 5      $ )Nr[  r   )listlen_is_iterable)argss    r   flattenrz    s1    CIN|DG/D/DQPP4PPr   c                B    [        U [        [        45      (       d  U 4$ U $ r   )r  rv  tuple)args    r   tupleifyr~    s    cD%=))vJr   c                   SSK Jn  [        5       =nb&  [        XR                  UR                  45      (       dI  [        5       =nbW  [        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   rR   z(Expected Narwhals class or scalar, got: z`.

Hint: Perhaps you
- forgot a `nw.from_native` somewhere?
- used `pl.col` instead of `nw.col`?)r   rS   r'   r  rN   r(   ExprrO   qualified_type_name	TypeErrorr   ru   bytes)r}  rS   pdplr%  s        r   rx  rx    s    & |	(Zii=V-W-W|	(sYYr||LMM 77J37O6R S3 3 	 nc8$RZc5&=Q-R)RRr   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\Dr  N)intresub).0vs     r   	<genexpr> parse_version.<locals>.<genexpr>  s'     K4JqRVVE2q)**4Js   .0.)r  ru   rv   r  r  r|  split)rs  version_strs     r   ro  ro    sK     (55'7;N;NK&&[9KKK4E4Ec4JKKKr   c                    g r   rw   
obj_or_clscls_or_tuples     r   isinstance_or_issubclassr    s     r   c                    g r   rw   r  s     r   r  r    s      r   c                    g r   rw   r  s     r   r  r    s     "r   c                    g r   rw   r  s     r   r  r         +.r   c                    g r   rw   r  s     r   r  r    s     %(r   c                    g r   rw   r  s     r   r  r    s     7:r   c                    g r   rw   r  s     r   r  r    r  r   c                    g r   rw   r  s     r   r  r    s	     CFr   c                    g r   rw   r  s     r   r  r  	  s     14r   c                    g r   rw   r  s     r   r  r    s	     ORr   c                    g r   rw   r  s     r   r  r    s     7:r   c                    g r   rw   r  s     r   r  r    s     r   c                    g r   rw   r  s     r   r  r  '  s     =@r   c                    g r   rw   r  s     r   r  r  0  s     r   c                    g r   rw   r  s     r   r  r  B  s     r   c                    SSK Jn  [        X5      (       a  [        X5      $ [        X5      =(       d"    [        U [        5      =(       a    [	        X5      $ )Nr   rP   )narwhals.dtypesrQ   r  type
issubclass)r  r  rQ   s      r   r  r  H  sA    %*$$*33j/ :t$MJ)Mr   c                   ^^ SSK Jm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   rM   c              3  <   >#    U  H  n[        UT5      v   M     g 7fr   r  )r  itemrN   s     r   r  $validate_laziness.<locals>.<genexpr>U  s     
954:dI&&5   c              3  <   >#    U  H  n[        UT5      v   M     g 7fr   r  )r  r  rO   s     r   r  r  V  s     :EDJtY''Er  zGThe items to concatenate should either all be eager, or all lazy, got: )r   rN   rO   allr  r  )itemsr  r%  rN   rO   s      @@r   validate_lazinessr  R  sc    7

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_uniquer  )indexr%  s     r   _validate_index*maybe_align_index.<locals>._validate_index  s    ;CS/! r   _compliant_frameN_compliant_seriesz6Expected `lhs` and `rhs` to have the same length, got z and )r  r   r   r   )narwhals._pandas_like.dataframer  narwhals._pandas_like.seriesr  r   r  getattrr  r   r  _with_compliant_with_nativelocr  rw  r  )lhsrhsr  r  r  lhs_anyrhs_anyr%  s           r   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Jr   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_nativer1   r2   r  )objobj_any
native_objs      r   maybe_get_indexr    sC    : 5#G""$J
++/DZ/P/Pr   )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      (       a`  SSKJ	n	  U(       a  S	n[        U5      eU	" UU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 conditions 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)rp  )narwhals.translater  r   r  rx  r1   r  r  r  r  r2   narwhals._pandas_like.utilsr  r   )
r  column_namesr  r  df_anyr  r%  idxkeysr  s
             r   maybe_set_indexr    sD   ^ -%F!!#JE$5HoEMCo E"" ;@@%3Ys.%@5t4 	 
++%%##001E1Ed1KL
 	
 
z	*	*9CCS/!00@@


 %%f&>&>&K&KJ&WXX3 As   $D<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  r1   __native_namespace___has_default_indexr  r  r  reset_indexr2   r  )r  r  r  r  s       r   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
 	
 Nr   c                ,    [        XR                  5      $ r   )r  
RangeIndex)r  r  s     r   _is_range_indexr  l  s    c6677r   c                    U R                   n[        X!5      =(       aD    UR                  S:H  =(       a.    UR                  [	        U5      :H  =(       a    UR
                  S:H  $ )Nr   r[  )r  r  startstoprw  step)native_frame_or_seriesr  r  s      r   r  r  p  sT     #((E0 	KK1	JJ#e*$	 JJ!O	r   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  r1   r  r  r  convert_dtypesr2   r  )r  ry  kwargsr  r  s        r   maybe_convert_dtypesr  |  s    H 5#G""$J
++&&$$11))4:6:
 	

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

 Nr   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.
>   br  >   kb	kilobytesi   >   mb	megabytesi   >   gb	gigabytesi   @>   tb	terabytesl        z9`unit` must be one of {'b', 'kb', 'mb', 'gb', 'tb'}, got r  )szunitr%  s      r   scale_bytesr    ss     ~		$	$Dy	$	$G|	$	$G|	$	$G|KD8Tor   c                   SSK Jn  U R                  R                  R                  nU R                  nSn[        X15      (       a@  [        U R                  UR                  5      (       a  UR                  R                  S   nU$ U R                  UR                  :X  a  SnU$ U R                  UR                  :w  a  SnU$ U R                  5       n[        U5      (       a%  [        SUR                  5      R                  S:H  nU$ [        U5      (       a!  [!        UR"                  R$                  5      nU$ ['        U5      (       a5  SSKJn  U" UR,                  5      =(       a    UR,                  R$                  nU$ )	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   )InterchangeSeriesF
is_orderedTzpl.Categoricalphysical)is_dictionary)narwhals._interchange.seriesr  r  r   r   r  dtypeCategoricalr   describe_categoricalr   r  r3   r   orderingr2   rY  catorderedr4   narwhals._arrow.utilsr  r  )r   r  r   r   resultr   r  s          r   is_ordered_categoricalr    sJ   T ?%%..55F((IF)//Jf((5 5 !!66|D M 
	$ M 
++	+ M !!#F##*FLL9BBjPF M #6**&**,,-F
 M	 &f--;"6;;/GFKK4G4GFMr   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 versionsz1.13.0r   )n_bytesr   )r   generate_temporary_column_name)r  r   r%  s      r   generate_unique_tokenr    s#    	?  cH5)'KKr   c                z    Sn S[        U S-
  5       3nX1;  a  U$ US-  nUS:  a  SU < SU 3n[        U5      eM9  )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   nwr[  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        r   r  r    sk    , G
 Yw{+,-L1S=*L	3  !%% r   c                  U(       d-  [        [        U R                  5      R                  U5      5      $ [        U5      n[	        X0R                  S9=n(       a  UeU$ )N)	available)rv  setr   intersectioncheck_columns_exist)framesubsetstrictto_droperrors        r   parse_columns_to_dropr  A  sM     C&33F;<<6lG#G}}EEuENr   c                Z    [        U [        5      =(       a    [        U [        5      (       + $ r   )r  r	   ru   )sequences    r   is_sequence_but_not_strr   L  s    h)K*Xs2K.KKr   c                L    [        U [        5      =(       a    U [        S 5      :H  $ r   )r  slicer  s    r   is_slice_noner$  P  s    c5!8cU4[&88r   c                   [        U 5      =(       a=    [        U 5      S:  =(       a    [        U S   [        5      =(       d    [        U 5      S:H  =(       d/    [	        U 5      =(       d    [        U 5      =(       d    [        U 5      $ Nr   )r   rw  r  r  r0   r.   is_compliant_series_intr#  s    r   is_sized_multi_index_selectorr(  T  sl    
 $C( Pc(Q,::c!fc#:NCA	( !%		(
 "#&	( #3'r   c                    [        U 5      =(       d/    [        U 5      =(       d    [        U 5      =(       d    [        U 5      $ r   )r   r/   r-   is_compliant_seriesr#  s    r   is_sequence_liker+  b  s:     	 $ 	$S!	$c"	$ s#	r   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  r  r  r  r#  s    r   is_slice_indexr-  m  sh    c5! 399c" 	Rchh$	Rsxx%P#))t*;PD@Pr   c                "    [        U [        5      $ r   )r  ranger#  s    r   is_ranger0  u  s    c5!!r   c                l    [        [        U [        5      =(       a    [        U [         5      (       + 5      $ r   )rY  r  r  r#  s    r   is_single_index_selectorr2  y  s#    
3$BZT-B)BCCr   c                `    [        U 5      =(       d    [        U 5      =(       d    [        U 5      $ r   )r2  r(  r-  r#  s    r   is_index_selectorr4  }  s+     	!% 	(-	#r   c                r    [        [        U [        5      =(       a    U =(       a    [        U S   U5      5      $ r&  )rY  r  rv  )r  tps     r   
is_list_ofr7    s)    
3%H#H*SVR2HIIr   c                    [        [        U 5      =(       a)    [        [        U 5      S 5      =n=(       a    [	        X!5      5      $ r   )rY  r   nextiterr  )r  r6  firsts      r   is_sequence_ofr<    s<    $ 	"49d++U	"u! r   c               `    U c  Uc  UnU$ U b  Uc	  U (       + nU$ U c  Ub   U$ Sn[        U5      e)Nz,Cannot pass both `strict` and `pass_through`r  )r  r  pass_through_defaultr%  s       r   validate_strict_and_pass_thoughr?    s_     ~,.+  
	 4!z  
L4  =or   r  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   r  ry   )ry  kwdsr  r  r%  fnrA  r@  s        r   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$$r   )ry  P.argsrF  P.kwargsr   ro   )r   )rG  rH  rA  r@  s   ` r   decorate,deprecate_native_namespace.<locals>.decorate  s%    	r	% 	% 
	%* r   )rG  Callable[P, R]r   rN  rw   )r@  rA  rL  s   `` r   deprecate_native_namespacerO    s     2 Or   c                    [        U [        SS9  [        U[        [        S 5      SS9  U S:  a  Sn[        U5      eUb)  US:  a  Sn[        U5      eX:  a  Sn[	        U5      e X4$ U nX4$ )Nwindow_size
param_namemin_samplesr[  z+window_size must be greater or equal than 1z+min_samples must be greater or equal than 1z6`min_samples` must be less or equal than `window_size`)ensure_typer  r  r  r7   )rQ  rT  r%  s      r   _validate_rolling_argumentsrV    s     S];S$t*GQ;o??CS/!$JC',, % ## "##r   c           
         [         R                  " 5       R                  nUR                  5       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   )rw  )r  lines     r   r   generate_repr.<locals>.<genexpr>  s     >3t99   r^  u   ┌u   ─u   ┐
| z|
-u   └u   ┘'   uu   ───────────────────────────────────────u   ┐
|u/   |
| Use `.to_native` to see native output |
└)
osget_terminal_sizer   OSErrorr  getenv
expandtabs
splitlinesmaxrw  )headernative_reprterminal_widthnative_linesmax_native_widthlengthoutputheader_extrastart_extra	end_extrar[  diffs               r   generate_reprrt    s   7--/77 ))+668L>>>!~-%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              r    [        U 5      R                  U5      =n(       a  [        R                  " X!5      $ g r   )r  
differencer5   'from_missing_and_available_column_names)r  r  missings      r   r  r    s9     f+((33w3"JJ
 	
 r   c                2   [        U 5      [        [        U 5      5      :w  ap  SSKJn  U" U 5      nUR	                  5        VVs0 s H  u  p4US:  d  M  X4_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   )Counterr[  r  c              3  8   #    U  H  u  pS U SU S3v   M     g7f)z
- 'z' z timesNrw   )r  kr  s      r   r  0check_column_names_are_unique.<locals>.<genexpr>  s#     L9KaS1#V,9Kr]  z"Expected unique column names, got:)rw  r  collectionsrz  r  joinr6   )r   rz  r  r|  r  
duplicatesr%  s          r   check_column_names_are_uniquer    s    
7|s3w<((''"'.}}@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  ru   r  r
   )	time_unit	time_zone
time_unitstz
time_zoness        r   _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  Datetimer  r  )r   r   r  r  s       r   %dtype_matches_time_unit_and_time_zoner  0  sU     	5//* 	
__
*	
 OOz) Cz!AeooT&Ar   c                   U R                   $ r   r   )r  s    r   get_column_namesr  =  s    ==r   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      r   exclude_column_namesr  A  s#    %*]]L]e6KH]LLLs   	%%c                  ^  SU 4S jjnU$ )Nc                  > T$ r   rw   )_framer  s    r   rG  $passthrough_column_names.<locals>.fnF  s    r   )r  r   r   r   rw   )r  rG  s   ` r   passthrough_column_namesr  E  s     Ir   c                2    [        5       n[        XU5      UL$ r   )objectr   )r  attrsentinels      r   _hasattr_staticr  L  s    xH#X.h>>r   c                    [        U S5      $ )N__narwhals_dataframe__r  r#  s    r   is_compliant_dataframer  Q  s     3 899r   c                    [        U S5      $ )N__narwhals_lazyframe__r  r#  s    r   is_compliant_lazyframer  \  s     3 899r   c                    [        U S5      $ )N__narwhals_series__r  r#  s    r   r*  r*  b  s     3 566r   c                Z    [        U 5      =(       a    U R                  R                  5       $ r   )r*  r   
is_integerr#  s    r   r'  r'  h  s!     s#>		(<(<(>>r   c                    [        U S5      $ )N__narwhals_expr__hasattrr#  s    r   is_compliant_exprr  n  s     3+,,r   c                    U [         R                  [         R                  [         R                  [         R                  [         R
                  1;   $ r   )r   r  r  r  r
  r  r#  s    r   is_eager_allowedr  t  sA      r   c                    [        U S5      $ )Nr  r  r#  s    r   has_native_namespacer  ~  s    3 677r   c                    [        U S5      $ )N__dataframe__r  r#  s    r   _supports_dataframe_interchanger    s    3((r   c                    [        U S5      $ )N__arrow_c_stream__r  r#  s    r   supports_arrow_c_streamr    s    3 455r   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   rw   )r  keyleft_onsuffixs     r   r  (_remap_full_join_keys.<locals>.<genexpr>  s&      ?G7N3%x3xs   )dictzip)r  right_onr  right_keys_suffixeds   ` ` r   _remap_full_join_keysr    s%     ?G H233r   c                   [        S5      (       aR  UR                  R                  R                  S5      R                  nUR
                  R                  XS9R                  $ S[        U 5      < 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   )contextzB'pyarrow>=14.0.0' is required for `from_arrow` for object of type r  )
r   r   r   r  r   
_dataframe
from_arrowr   r  ModuleNotFoundError)datar  r  r%  s       r   _into_arrow_tabler    sq     ''44Y?II}}'''9@@@RSfgkSlRoopq!#&&r   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)
rw   )rG  s    r   unstabler    s	    ( Ir   c                8   ^  [        U 4S jS 5       5      (       + $ )a  Determines if a datetime format string is 'naive', i.e., does not include timezone information.

A format is considered naive if it does not contain any of the following

- '%s': Unix timestamp
- '%z': UTC offset
- 'Z' : UTC timezone designator

Arguments:
    format: The datetime format string to check.

Returns:
    bool: True if the format is naive (does not include timezone info), False otherwise.
c              3  ,   >#    U  H	  oT;   v   M     g 7fr   rw   )r  xformats     r   r  #_is_naive_format.<locals>.<genexpr>  s     :(91;(9s   )z%sz%zZ)any)r  s   `r   _is_naive_formatr    s     :(9::::r   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  aJ  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   )_alias)r   aliass     r   __init__not_implemented.__init__  s	     #(r   c                f    S[        U 5      R                   SU R                   SU R                   3$ )N<z>: r  )r  ry   _name_owner_namer   s    r   __repr__not_implemented.__repr__  s1    4:&&'s4+;+;*<Adjj\JJr   c                Z    UR                   U l        U R                  =(       d    UU l        g r   )ry   r  r  r  )r   r   names      r   __set_name__not_implemented.__set_name__
  s     %++-
r   c               h    Uc  U $ [        USU R                  5      n[        U R                  U5        g )Nr   )r  r  _raise_not_implemented_errorr  )r   r   r   whos       r   r   not_implemented.__get__  s9      K h 143C3CD$TZZ5r   c                $    U R                  S5      $ )Nraise)r   )r   ry  rF  s      r   __call__not_implemented.__call__  s     ||G$$r   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  messager  s      r   r!   not_implemented.deprecated"  s     e'"3''r   )r  r  r  r   )r  z
str | Noner   r   rW  )r   type[_T]r  ru   r   r   )r   z_T | Literal['raise'] | Noner   ztype[_T] | Noner   r   )ry  r   rF  r   r   r   )r  r;   r   r=   )ry   rz   r{   r|   r   r  r  r  r   r  rZ  r!   r~   rw   r   r   r  r    sU    "H(
K. PT4=L	%
 ( (r   r  c               ,    U < SU< S3n[        U5      e)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      r   r  r  2  s,    (+C7 3S 	S 
 c
""r   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_versionru   _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hintr  s       r   rU  requires.backend_versionU  s"     kk#"	
r   c               2    SR                  S U  5       5      $ )Nr  c              3  &   #    U  H  o v   M	     g 7fr   rw   )r  ds     r   r  ,requires._unparse_version.<locals>.<genexpr>g  s     81#s   )r  rT  s    r   _unparse_versionrequires._unparse_versione  s    xx8888r   c          	     N   UR                   U R                  :  a  g U R                  nU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 r  
)r   r  _wrapped_namer   r  r  r  )r   r   methodr  r  foundr%  s          r   _ensure_versionrequires._ensure_versioni  s    $$(9(99##**''(9(9:%%h&?&?@&1'"WIEVW\V__`a::EDJJ<(C!#&&r   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   ry  rF  rG  r   s      r   rH  "requires.__call__.<locals>.wrapperx  s&      *h....r   )r   r   ry  rJ  rF  rK  r   ro   )ry   r
  r   )r   rG  rH  s   `` r   r  requires.__call__u  s,    [[	r	/ 
	/
 r   )r
  N)r  )r  ru   r  r   r   r=   )rU  r   r   ru   )r   r   r   r   )rG  _Method[_ContextT, P, R]r   r  )ry   rz   r{   r|   r   r}   rZ  rU  staticmethodr  r  r  r~   rw   r   r   r  r  ;  sD    , "!J  9 9
'	r   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$ )Nr[  )r  r  r  r  )	str_slicer   r  r  r  s        r   convert_str_slice_to_int_slicer    sX     /8oo.IGMM)//*tE090J7==(1,PTD>>Dr   c                  ^  SU 4S jjnU$ )zSteal the class-level docstring from parent and attach to child `__init__`.

Returns:
    Decorated constructor.

Notes:
    - Passes static typing (mostly)
    - Passes at runtime
c                  > U R                   S:X  a0  [        [        T5      [        5      (       a  [        T5      U l        U $ S[
        R                    SU R                  < ST< 3n[        U5      e)Nr  z`@zL` is only allowed to decorate an `__init__` with a class-level doc.
Method: z	
Parent: )ry   r  r  r   r   inherit_docr{   r  )
init_childr%  	tp_parents     r   rL  inherit_doc.<locals>.decorate  su    *,DOT1R1R!'	!2J [))* +%225 6$-) 
 C. r   )r  _Constructor[_T, P, R2]r   r  rw   )r  rL  s   ` r   r  r    s    
! Or   c                   [        U [        5      (       a  U O
[        U 5      nUR                  S:w  a  UR                  OSnU SUR                   3R	                  S5      $ )Nbuiltinsr  r  )r  r  rz   ry   lstrip)r  r6  modules      r   r  r    sO    3%%49B mmz9R]]rFXQr{{m$++C00r   rR  c              R   [        X5      (       d  SR                  S U 5       5      nSU< S[        U 5      < 3nU(       aZ  Sn[        U 5      n[	        U5      S:  a  [        U 5       S3nU U S3nS	[	        U5      -  S
[	        U5      -  -   nU SU U SU 3n[        U5      eg)am  Validate that an object is an instance of one or more specified types.

Parameters:
    obj: The object to validate.
    *valid_types: One or more valid types that `obj` is expected to match.
    param_name: The name of the parameter being validated.
        Used to improve error message clarity.

Raises:
    TypeError: If `obj` is not an instance of any of the provided `valid_types`.

Examples:
    >>> from narwhals._utils import ensure_type
    >>> ensure_type(42, int, float)
    >>> ensure_type("hello", str)

    >>> ensure_type("hello", int, param_name="test")
    Traceback (most recent call last):
        ...
    TypeError: Expected 'int', got: 'str'
        test='hello'
             ^^^^^^^
    >>> import polars as pl
    >>> import pandas as pd
    >>> df = pl.DataFrame([[1], [2], [3], [4], [5]], schema=[*"abcde"])
    >>> ensure_type(df, pd.DataFrame, param_name="df")
    Traceback (most recent call last):
        ...
    TypeError: Expected 'pandas.core.frame.DataFrame', got: 'polars.dataframe.frame.DataFrame'
        df=polars.dataframe.frame.DataFrame(...)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
z | c              3  8   #    U  H  n[        U5      v   M     g 7fr   )r  )r  r6  s     r   r  ensure_type.<locals>.<genexpr>  s     L"1"55r]  z	Expected z, got: z    (   z(...)=r_  ^r	  N)r  r  r  reprrw  r  )	r  rS  valid_typestp_namesr%  left_padvalassign	underlines	            r   rU  rU    s    B c''::LLL(W-@-E,HIHs)C3x"},S12%8 z*Q/Fs6{*sSX~>IEF8C59+6Cn (r   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)_DeferredIterablei  zLStore a callable producing an iterable to defer collection until we need it.c                   Xl         g r   
_into_iter)r   	into_iters     r   r  _DeferredIterable.__init__  s    6?r   c              #  @   #    U R                  5        S h  vN   g  N7fr   r3  r   s    r   __iter___DeferredIterable.__iter__  s     ??$$$s   c                f    U R                  5       n[        U[        5      (       a  U$ [        U5      $ r   )r4  r  r|  )r   its     r   to_tuple_DeferredIterable.to_tuple  s)    __E**r9b	9r   r3  N)r5  zCallable[[], Iterable[_T]]r   r   )r   zIterator[_T])r   ztuple[_T, ...])	ry   rz   r{   r|   r   r  r8  r<  r~   rw   r   r   r1  r1    s    V@%:r   r1  )r&  ru   r   r9   )rp  r   r   r   )ry  r   r   z	list[Any])r}  r   r   r   )r}  zAny | Iterable[Any]r   rY  )rs  z#str | ModuleType | _SupportsVersionr   r   )r  r  r  r  r   zTypeIs[type[_T]])r  object | typer  r  r   zTypeIs[_T | type[_T]])r  r  r  tuple[type[_T1], type[_T2]]r   zTypeIs[type[_T1 | _T2]])r  r>  r  r?  r   z#TypeIs[_T1 | _T2 | type[_T1 | _T2]])r  r  r  &tuple[type[_T1], type[_T2], type[_T3]]r   zTypeIs[type[_T1 | _T2 | _T3]])r  r>  r  r@  r   z/TypeIs[_T1 | _T2 | _T3 | type[_T1 | _T2 | _T3]])r  r  r  1tuple[type[_T1], type[_T2], type[_T3], type[_T4]]r   z#TypeIs[type[_T1 | _T2 | _T3 | _T4]])r  r>  r  rA  r   z;TypeIs[_T1 | _T2 | _T3 | _T4 | type[_T1 | _T2 | _T3 | _T4]])r  r  r  <tuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5]]r   z)TypeIs[type[_T1 | _T2 | _T3 | _T4 | _T5]])r  r>  r  rB  r   zGTypeIs[_T1 | _T2 | _T3 | _T4 | _T5 | type[_T1 | _T2 | _T3 | _T4 | _T5]])r  r  r  Gtuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5], type[_T6]]r   z/TypeIs[type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6]])r  r>  r  rC  r   zSTypeIs[_T1 | _T2 | _T3 | _T4 | _T5 | _T6 | type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6]])r  r  r  Rtuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5], type[_T6], type[_T7]]r   z5TypeIs[type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6 | _T7]])r  r>  r  rD  r   z_TypeIs[_T1 | _T2 | _T3 | _T4 | _T5 | _T6 | _T7 | type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6 | _T7]])r  r   r  ztuple[type, ...]r   zTypeIs[Any])r  r   r  r   r   rY  )r  zIterable[Any]r   r   )r  rd   r  z-Series[Any] | DataFrame[Any] | LazyFrame[Any]r   rd   )r  z-DataFrame[Any] | LazyFrame[Any] | Series[Any]r   r   r   )r  rd   r  zstr | list[str] | Noner  z6Series[IntoSeriesT] | list[Series[IntoSeriesT]] | Noner   rd   )r  rd   r   rd   )r  r   r  r   r   zTypeIs[pd.RangeIndex])r  zpd.Series[Any] | pd.DataFramer  r   r   rY  )r  rd   ry  rY  r  z
bool | strr   rd   )r  r  r  r]   r   zint | float)r   zSeries[Any]r   rY  )r  r  r   Container[str]r   ru   )r  r   r  zIterable[str]r  rY  r   z	list[str])r  Sequence[_T] | Anyr   TypeIs[Sequence[_T]])r  r   r   zTypeIs[_SliceNone])r  r   r   zCTypeIs[SizedMultiIndexSelector[Series[Any] | CompliantSeries[Any]]])r  rF  r   z-TypeIs[Sequence[_T] | Series[Any] | _1DArray])r  r   r   zTypeIs[_SliceIndex])r  r   r   zTypeIs[range])r  r   r   zTypeIs[SingleIndexSelector])r  r   r   zTTypeIs[SingleIndexSelector | MultiIndexSelector[Series[Any] | CompliantSeries[Any]]])r  r   r6  r  r   zTypeIs[list[_T]])r  r   r6  r  r   rG  )r  bool | Noner  rH  r>  rY  r   rY  )r@  ru   rA  rY  r   z*Callable[[Callable[P, R]], Callable[P, R]])rQ  r  rT  z
int | Noner   ztuple[int, int])ri  ru   rj  ru   r   ru   )r  Collection[str]r  rI  r   zColumnNotFoundError | None)r   rI  r   r   )r  z$TimeUnit | Iterable[TimeUnit] | Noner  z7str | timezone | Iterable[str | timezone | None] | Noner   z%tuple[Set[TimeUnit], Set[str | None]])
r   rQ   r   rX   r  zSet[TimeUnit]r  zSet[str | None]r   rY  )r  r   r   r   )r  r   r  rE  r   r   )r  r   r   zEvalNames[Any])r  r   r  ru   r   rY  )r  z[CompliantDataFrame[CompliantSeriesT, CompliantExprT, NativeFrameT_co, ToNarwhalsT_co] | Anyr   z]TypeIs[CompliantDataFrame[CompliantSeriesT, CompliantExprT, NativeFrameT_co, ToNarwhalsT_co]])r  zICompliantLazyFrame[CompliantExprT, NativeFrameT_co, ToNarwhalsT_co] | Anyr   zKTypeIs[CompliantLazyFrame[CompliantExprT, NativeFrameT_co, ToNarwhalsT_co]])r  z'CompliantSeries[NativeSeriesT_co] | Anyr   z)TypeIs[CompliantSeries[NativeSeriesT_co]])r  zECompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co] | Anyr   zGTypeIs[CompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co]])r  r   r   z"TypeIs[EagerAllowedImplementation])r  r   r   zTypeIs[SupportsNativeNamespace])r  r   r   zTypeIs[DataFrameLike])r  r   r   zTypeIs[ArrowStreamExportable])r  rI  r  rI  r  ru   r   zdict[str, str])r  rK   r  r   r   zpa.Table)rG  rm   r   rm   )r  ru   r   rY  )r  ru   r  ru   r   r  )r  rb   r   r   r   z"tuple[int | None, int | None, Any])r  zCallable[P, R1]r   z<Callable[[_Constructor[_T, P, R2]], _Constructor[_T, P, R2]])r  zobject | type[Any]r   ru   )r  r   r*  z	type[Any]rS  ru   r   r   )
__future__r   rb  r  collections.abcr   r   r   r   r   r	   datetimer
   enumr   r   	functoolsr   r   r   importlib.utilr   inspectr   r   secretsr   typingr   r   r   r   r   r   r   r   r   r   narwhals._enumr   narwhals._exceptionsr   narwhals._typing_compatr    r!   narwhals.dependenciesr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   narwhals.exceptionsr5   r6   r7   r8   typesr9   r   r  r   r  r   patyping_extensionsr:   r;   r<   r=   r>   r?   narwhals._compliantr@   rA   rB   rC   rD   rE   rF   narwhals._compliant.typingrG   r   rH   rI   narwhals._translaterJ   rK   rL   r   rN   rO   r  rQ   r   rS   narwhals.typingrT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rs   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
  r  r  r  r  rg  r#  r$  rU  rz  r~  rx  ro  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r$  r(  r+  r-  r0  r2  r4  r7  r<  r?  rO  rV  rt  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  r  rU  r1  rw   r   r   <module>r_     s	   " 	 	 X X   - - $ *    & : <     * [ Z#     5IYY7%&    & ininfSk&Q RN %.C
%.C
%.C
%.C
%.C
%.C
%.C
%3
4C#AA	B	B8 Rx R0 0
 T]\T2
48K~6	= =<i <HZ( x. H -X -
JH J
+^X (/8 	42H 	4Id IXC%Z C%N
 9)EF""F:4Z:6  ).M""$9	@  <  D 2& &  >QS*L" 
$, 

 
  -5   
 
 
""$?"" 
"
 
..-H.(. 
.
 
(($J("( 
(
 
::-S:4: 
:
 
..$U.(. 
.
 
FFCF AF 
F 
44N4 /4 
4 
RRNR MR 
R 
::Y: 5: 
: 
Y 
 
@@@
 ;@ 
@ 

	 
" 
#3 

\	\K\\~!L ,0W EI	W	W(W B	W
 Wt/d8	9	MP			2	2 $20:22j2BJLL)LL$&N#0@DL9	H	2"D	YJ
 	
 
& &&)-&/&R$$#-$$0<.=""3"F" +"*

 
.;
IX
	
M?
:

:
::	R:P:7	07.7?	0?.?-	N-L-8)644(74AD44,'(.;$R( R(j#C CL$1'A81 IK , ,^: :r   