
    Wh                      U d dl mZ d dlZd dlZd dlmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZmZmZmZ d dlmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZ d dl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, d dl-m.Z. d dl/m0Z0m1Z1 d dl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZC d dlDmEZEmFZFmGZG e!rkd dlmHZH d dlImJZJ d dlKZLd dlMZNd dlOZPd dlQmRZRmSZSmTZTmUZUmVZVmWZW d dlXmYZYmZZZm[Z[m\Z\m]Z]m^Z^ d dl_m`Z`maZambZb d dlcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZp d dlqmrZrmsZsmtZt d dlumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZ d dlmZmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ eZded<    e'd e(ee"   ee"   ee"   f   !      Z e'd"      Z e'd#      Z e'd$      Z e'd%      Z e'd&      Z e'd'      Z e'd(      Z e'd)d*!      Z eTd+      Z e'd,      Z e'd-      Z e'd.      Z G d/ d0e&      Z G d1 d2e&      Z G d3 d4e&      Z e'd5      Z e'd6d78      Z e'd9d78      Z e'd:d;!      Zd<Zded=<   d>Zded?<    G d@ dAe&e         Z G dB dCe&e         Z G dD dEe&      Z G dF dGe&      Z G dH dIe&      Z G dJ dKeee&      Z G dL d;eee&      Z G dM dNee&      Z G dO dPe      Z G dQ dRe,      Zej                  dSej                  dTej                  dUej                  dVej                  dWej                  dWej                  dXej                  dYej                  dZej                  d[ej                  d\iZd]ed^<   ej                  d_ej                  d`ej                  daej                  dbiZdcedd<   	  edef      ddg       Zeddh       ZddiZddjZddkZddlZe*	 	 	 	 	 	 ddm       Ze*	 	 	 	 	 	 ddn       Ze*	 	 	 	 	 	 ddo       Ze*	 	 	 	 	 	 ddp       Ze*	 	 	 	 	 	 ddq       Ze*	 	 	 	 	 	 ddr       Ze*	 	 	 	 	 	 dds       Ze*	 	 	 	 	 	 ddt       Ze*	 	 	 	 	 	 ddu       Ze*	 	 	 	 	 	 ddv       Ze*	 	 	 	 	 	 ddw       Ze*	 	 	 	 	 	 ddx       Ze*	 	 	 	 	 	 ddy       Ze*	 	 	 	 	 	 ddz       Ze*	 	 	 	 	 	 dd{       Zdd|Zdd}Z	 	 	 	 	 	 dd~ZddZ	 ddd	 	 	 	 	 	 	 ddZddZe!r eed7      Zn#d dlZeݐj                  dk\  r eed7      ZnddZddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 ddZddZddZ	 	 	 	 ddZ	 	 	 	 ddZddZddZddZ	 	 	 	 ddZddZddZ	 	 	 	 	 	 	 	 ddZddd	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 d dZ	 	 	 	 	 	 	 	 	 	 ddZddZddZddZddZ	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 ddZ 	 	 	 	 d	dZd
dZddZddZddZddZ	 	 	 	 	 	 	 	 ddZddZddZ	ddZ
 G d d      ZddZ G d d      Z	 	 	 	 	 	 ddZ	 	 	 	 ddZddZddddZ G d de$e         Z edf      dd       ZddÄZ G dĄ dee   ee&e         Z G dƄ de&e         Z G dȄ dɫ      ZddʄZdd˄Zy(      )annotationsN)
Collection	ContainerIterableIteratorMappingSequence)timezone)Enumauto)cache	lru_cachepartialwraps)	find_spec)getattr_staticgetdoc)chain)
attrgetter)	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)ColumnNotFoundErrorDuplicateErrorInvalidOperationError)Set)
ModuleType)ConcatenateLiteralString	ParamSpecSelf	TypeAliasTypeIs)CompliantExprCompliantExprTCompliantFrameTCompliantSeriesOrNativeExprT_coCompliantSeriesTNativeSeriesT_co)	EvalNamesNativeDataFrameTNativeLazyFrameT)	Namespace_NativeArrow_NativeCuDF_NativeDask_NativeDuckDB_NativeIbis_NativeModin_NativePandas_NativePandasLike_NativePolars_NativePySpark_NativePySparkConnect_NativeSQLFrame)ArrowStreamExportableIntoArrowTableToNarwhalsT_co)BackendIntoBackend
_ArrowImpl	_CuDFImpl	_DaskImpl_DuckDBImpl_EagerAllowedImpl	_IbisImpl_LazyAllowedImpl_LazyFrameCollectImpl
_ModinImpl_PandasImpl_PandasLikeImpl_PolarsImpl_PySparkConnectImpl_PySparkImpl_SQLFrameImpl	DataFrame	LazyFrameDTypeSeries)CompliantDataFrameCompliantLazyFrameCompliantSeriesDTypes
FileSourceIntoSeriesTMultiIndexSelectorSingleIndexSelectorSizedMultiIndexSelectorSizeUnitSupportsNativeNamespaceTimeUnit_1DArray_SliceIndex
_SliceName
_SliceNoner?   UnknownBackendNameFrameOrSeriesT)bound_T1_T2_T3_T4_T5_T6_T7_FnzCallable[..., Any]PRR1R2c                      e Zd ZU ded<   y)_SupportsVersionstr__version__N__name__
__module____qualname____annotations__     I/var/www/html/jupyter_env/lib/python3.12/site-packages/narwhals/_utils.pyr   r      s    r   r   c                      e Zd ZdddZy)_SupportsGetNc                    y Nr   selfinstanceowners      r   __get__z_SupportsGet.__get__   s    r   r   )r   r   r   
Any | Nonereturnr   )r   r   r   r   r   r   r   r   r      s    Qr   r   c                      e Zd Zedd       Zy)_StoresColumnsc                     y r   r   r   s    r   columnsz_StoresColumns.columns   s    ,/r   N)r   Sequence[str])r   r   r   propertyr   r   r   r   r   r      s    	/ 
/r   r   _T
NativeT_coT)	covariantCompliantT_co	_ContextT_FullContextz&Callable[Concatenate[_ContextT, P], R]_Methodz Callable[Concatenate[_T, P], R2]_Constructorc                  "    e Zd ZdZedd       Zy)_StoresNativezProvides access to a native object.

    Native objects have types like:

    >>> from pandas import Series
    >>> from pyarrow import Table
    c                     y)zReturn the native object.Nr   r   s    r   nativez_StoresNative.native        	r   N)r   r   )r   r   r   __doc__r   r   r   r   r   r   r            r   r   c                  "    e Zd ZdZedd       Zy)_StoresCompliantzProvides access to a compliant object.

    Compliant objects have types like:

    >>> from narwhals._pandas_like.series import PandasLikeSeries
    >>> from narwhals._arrow.dataframe import ArrowDataFrame
    c                     y)zReturn the compliant object.Nr   r   s    r   	compliantz_StoresCompliant.compliant   r   r   N)r   r   )r   r   r   r   r   r   r   r   r   r   r      r   r   r   c                      e Zd Zedd       Zy)_StoresBackendVersionc                     y)z#Version tuple for a native package.Nr   r   s    r   _backend_versionz&_StoresBackendVersion._backend_version   r   r   Nr   tuple[int, ...])r   r   r   r   r   r   r   r   r   r      s     r   r   c                      e Zd ZU ded<   y)_StoresVersionVersion_versionNr   r   r   r   r   r      s    ,r   r   c                      e Zd ZU ded<   y)_StoresImplementationImplementation_implementationNr   r   r   r   r   r      s    ##Ir   r   c                      e Zd ZdZy)_LimitedContextzEProvides 2 attributes.

    - `_implementation`
    - `_version`
    Nr   r   r   r   r   r   r   r   r      s    r   r   c                      e Zd ZdZy)r   z^Provides 3 attributes.

    - `_implementation`
    - `_backend_version`
    - `_version`
    Nr   r   r   r   r   r      s    r   c                      e Zd ZdZddZy)ValidateBackendVersionz=Ensure the target `Implementation` is on a supported version.c                8    | j                   j                         }y)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_versionz0ValidateBackendVersion._validate_backend_version   s       113r   N)r   None)r   r   r   r   r   r   r   r   r   r      s
    G4r   r   c                      e Zd Z e       Z e       Z e       Zedd       Zedd       Z	ed	d       Z
ed
d       Zedd       Zy)r   c                z    | t         j                  u rddlm} |S | t         j                  u rddlm} |S ddlm} |S )Nr   )rJ   )r   V1narwhals.stable.v1._namespacerJ   V2narwhals.stable.v2._namespacenarwhals._namespace)r   NamespaceV1NamespaceV2rJ   s       r   	namespacezVersion.namespace   s5    7::N7::N1r   c                z    | t         j                  u rddlm} |S | t         j                  u rddlm} |S ddlm} |S )Nr   )dtypes)r   r   narwhals.stable.v1r   r   narwhals.stable.v2narwhals)r   	dtypes_v1	dtypes_v2r   s       r   r   zVersion.dtypes
  s4    7::>7::>#r   c                z    | t         j                  u rddlm} |S | t         j                  u rddlm} |S ddlm} |S )Nr   )rl   )r   r   r   rl   r   r   narwhals.dataframe)r   DataFrameV1DataFrameV2rl   s       r   	dataframezVersion.dataframe  5    7::C7::C0r   c                z    | t         j                  u rddlm} |S | t         j                  u rddlm} |S ddlm} |S )Nr   )rm   )r   r   r   rm   r   r   r   )r   LazyFrameV1LazyFrameV2rm   s       r   	lazyframezVersion.lazyframe&  r   r   c                z    | t         j                  u rddlm} |S | t         j                  u rddlm} |S ddlm} |S )Nr   rp   )r   r   r   rq   r   r   narwhals.series)r   SeriesV1SeriesV2rq   s       r   serieszVersion.series4  s2    7::=O7::=O*r   N)r   ztype[Namespace[Any]])r   ru   )r   ztype[DataFrame[Any]])r   ztype[LazyFrame[Any]])r   ztype[Series[Any]])r   r   r   r   r   r   MAINr   r   r   r   r   r   r   r   r   r   r      sy    	B	B6D         r   r   c                  &   e Zd ZdZdZ	 dZ	 dZ	 dZ	 dZ	 dZ		 dZ
	 d	Z	 d
Z	 dZ	 dZ	 dZ	 d"dZe	 	 	 	 	 	 d#d       Zed$d       Ze	 	 	 	 	 	 d%d       Zd&dZd'dZd'dZd'dZd'dZd'dZd'dZd'dZd'dZd'dZd'dZd'dZ d'dZ!d'dZ"d(d Z#y!))r   z?Implementation of native object (pandas, Polars, PyArrow, ...).pandasmodincudfpyarrowpysparkpolarsdaskduckdbibissqlframezpyspark[connect]unknownc                ,    t        | j                        S r   )r   valuer   s    r   __str__zImplementation.__str___  s    4::r   c                V   t               t        j                  t               t        j                  t               t        j                  t               t        j                  t               t        j                  t               t        j                  t               t        j                  t               t        j                   t#               t        j$                  t'               t        j(                  t+               t        j,                  i}|j/                  |t        j0                        S )zInstantiate Implementation object from a native namespace module.

        Arguments:
            native_namespace: Native namespace.
        )r*   r   PANDASr)   MODINr%   CUDFr,   PYARROWr.   PYSPARKr+   POLARSr&   DASKr'   DUCKDBr(   IBISr/   SQLFRAMEr-   PYSPARK_CONNECTgetUNKNOWN)clsnative_namespacemappings      r   from_native_namespacez$Implementation.from_native_namespaceb  s     L.//K--J++M>11~55L.// ."5"5L.//J++NN33!>#A#A
 {{+^-C-CDDr   c                R    	  | |      S # t         $ r t        j                  cY S w xY w)zInstantiate Implementation object from a native namespace module.

        Arguments:
            backend_name: Name of backend, expressed as string.
        )
ValueErrorr   r  )r  backend_names     r   from_stringzImplementation.from_stringz  s-    	*|$$ 	*!)))	*s   
 &&c                    t        |t              r| j                  |      S t        |t              r|S | j	                  |      S )zInstantiate from native namespace module, string, or Implementation.

        Arguments:
            backend: Backend to instantiate Implementation from.
        )
isinstancer   r  r   r  )r  backends     r   from_backendzImplementation.from_backend  sL     '3' OOG$	
 '>2 	

 **73	
r   c                    | t         j                  u rd}t        |      | j                          t        j                  | | j                        }t        |      S )zCReturn the native namespace module corresponding to Implementation.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_namespacez"Implementation.to_native_namespace  sM    >)))NC %%488tzzJ'44r   c                &    | t         j                  u S )a7  Return whether implementation is pandas.

        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_pandaszImplementation.is_pandas       ~,,,,r   c                d    | t         j                  t         j                  t         j                  hv S )aL  Return whether implementation is pandas, Modin, or cuDF.

        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_likezImplementation.is_pandas_like  s(     --~/C/C^EXEXYYYr   c                d    | t         j                  t         j                  t         j                  hv S )aI  Return whether implementation is pyspark or sqlframe.

        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_likezImplementation.is_spark_like  s1     ""##**
 
 	
r   c                &    | t         j                  u S )a7  Return whether implementation is Polars.

        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_polarszImplementation.is_polars  r-  r   c                &    | t         j                  u S )a4  Return whether implementation is cuDF.

        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_cudfzImplementation.is_cudf       ~****r   c                &    | t         j                  u S )a6  Return whether implementation is Modin.

        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_modinzImplementation.is_modin  s     ~++++r   c                &    | t         j                  u S )a:  Return whether implementation is PySpark.

        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_pysparkzImplementation.is_pyspark       ~----r   c                &    | t         j                  u S )aB  Return whether implementation is PySpark.

        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_connectz!Implementation.is_pyspark_connect   s     ~5555r   c                &    | t         j                  u S )a:  Return whether implementation is PyArrow.

        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_pyarrowzImplementation.is_pyarrow  r;  r   c                &    | t         j                  u S )a4  Return whether implementation is Dask.

        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_daskzImplementation.is_dask  r6  r   c                &    | t         j                  u S )a8  Return whether implementation is DuckDB.

        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_duckdbzImplementation.is_duckdb'  r-  r   c                &    | t         j                  u S )a4  Return whether implementation is Ibis.

        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_ibiszImplementation.is_ibis4  r6  r   c                &    | t         j                  u S )a<  Return whether implementation is SQLFrame.

        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_sqlframezImplementation.is_sqlframeA  s     ~....r   c                    t        |       S )zReturns backend version.backend_versionr   s    r   r   zImplementation._backend_versionN  s    t$$r   Nr   r   )r  
type[Self]r  r:   r   r   )r  rL  r  r   r   r   )r  rL  r"  z)IntoBackend[Backend] | UnknownBackendNamer   r   )r   r:   )r   boolr   )$r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r	  classmethodr  r  r#  r*  r,  r/  r1  r3  r5  r8  r:  r=  r?  rA  rC  rE  rG  r   r   r   r   r   r   C  s'   IF EDG!G!F DF DH"(O)G! EE+5E	E E. 	* 	* 

"K
	
 
 5-Z
"-+,.6.+-+/%r   r   )   rO     )r         )   
   )   )rP     )r         )i  rQ  )rO  )   )rP     r   z(Mapping[Implementation, tuple[int, ...]]MIN_VERSIONSzdask.dataframezmodin.pandaszpyspark.sqlzpyspark.sql.connectzMapping[Implementation, str]r&     )maxsizec                    ddl m}  ||       S )Nr   )import_module)	importlibr_  )r)  r_  s     r   r'  r'  j  s    '%%r   c                  t        | t              st        |        | t        j                  u rd}t	        |      | }t
        j                  ||j                        }t        |      }|j                         rdd l
}|j                  }n@|j                         s|j                         rdd l}|}n|j                         rdd l}|}n|}t#        |      }	|	t$        |   x}
k  rd| d|
 d|	 }t'        |      |	S )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'  rG  sqlframe._versionr   r:  r=  r   rA  r  parse_versionr[  r  )implementationr(  implr)  r  r  into_versionr   r  versionmin_versions              r   rJ  rJ  t  s    nn5^$///IS!!D044T4::FK/< ((		d557	'L)Gd!33+4#D6)CK=PYZaYbcoNr   c                b    t        t        |       dk(  rt        | d         r	| d         S |       S )NrO  r   )listlen_is_iterable)argss    r   flattenrn    s.    CIN|DG/DQPP4PPr   c                8    t        | t        t        f      s| fS | S r   )r!  rj  tuple)args    r   tupleifyrr    s    cD%=)vJr   c                z   ddl m} t               x}"t        | |j                  |j                  f      sDt               x}Rt        | |j                  |j                  |j                  |j                  f      rdt        |       d}t        |      t        | t              xr t        | t        t        |f       S )Nr   rp   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   rq   r*   r!  rl   r+   Exprrm   qualified_type_name	TypeErrorr   r   bytes)rq  rq   pdplr(  s        r   rl  rl    s    & |	(Zbii=V-W|	(sRYYr||LM 77J37O6R S3 3 	 nc8$RZc5&=Q-R)RRr   c                    t        | t              r| n| j                  }t        j                  dd|      }t        d |j                  d      D              S )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  \   K   | ]$  }t        t        j                  d d|             & yw)z\Dr{  N)intresub).0vs     r   	<genexpr>z parse_version.<locals>.<genexpr>  s"     KqRVVE2q)*Ks   *,.)r!  r   r   r~  r  rp  split)rg  version_strs     r   rc  rc    sH     (5'7;N;NK&&[9KKK4E4Ec4JKKKr   c                     y r   r   
obj_or_clscls_or_tuples     r   isinstance_or_issubclassr    s     r   c                     y r   r   r  s     r   r  r          r   c                     y r   r   r  s     r   r  r    s     "r   c                     y r   r   r  s     r   r  r         +.r   c                     y r   r   r  s     r   r  r    s     %(r   c                     y r   r   r  s     r   r  r    s     7:r   c                     y r   r   r  s     r   r  r    r  r   c                     y r   r   r  s     r   r  r    s	     CFr   c                     y r   r   r  s     r   r  r    s     14r   c                     y r   r   r  s     r   r  r    s	     ORr   c                     y r   r   r  s     r   r  r    s     7:r   c                     y r   r   r  s     r   r  r  
  s     r   c                     y r   r   r  s     r   r  r    s     =@r   c                     y r   r   r  s     r   r  r    s     r   c                     y r   r   r  s     r   r  r  .  s     r   c                    ddl m} t        | |      rt        | |      S t        | |      xs t        | t              xr t	        | |      S )Nr   rn   )narwhals.dtypesro   r!  type
issubclass)r  r  ro   s      r   r  r  4  sF    %*e$*l33j,/ :t$MJ)Mr   c                    ddl mm t        fd| D              st        fd| D              ry d| D cg c]  }t	        |       c} }t        |      c c}w )Nr   rk   c              3  6   K   | ]  }t        |        y wr   r!  )r  itemrl   s     r   r  z$validate_laziness.<locals>.<genexpr>A  s     
94:dI&
9   c              3  6   K   | ]  }t        |        y wr   r  )r  r  rm   s     r   r  z$validate_laziness.<locals>.<genexpr>B  s     :DJtY':r  zGThe items to concatenate should either all be eager, or all lazy, got: )r   rl   rm   allr  rv  )itemsr  r(  rl   rm   s      @@r   validate_lazinessr  >  sW    7

95
99:E::SlqTrdhUYZ^U_TrSs
tC
C. Uss   Ac                   ddl m} ddlm} dd}t	        d|       }t	        d|      }t        t        |dd      |      rt        t        |dd      |      r ||j                  j                  j                          ||j                  j                  j                         |j                  |j                  j                  |j                  j                  j                  |j                  j                  j                                 S t        t        |dd      |      rt        t        |dd      |      r ||j                  j                  j                          ||j                  j                  j                         |j                  |j                  j                  |j                  j                  j                  |j                  j                  j                                 S t        t        |dd      |      rt        t        |dd      |      r ||j                  j                  j                          ||j                  j                  j                         |j                  |j                  j                  |j                  j                  j                  |j                  j                  j                                 S t        t        |dd      |      rt        t        |dd      |      r ||j                  j                  j                          ||j                  j                  j                         |j                  |j                  j                  |j                  j                  j                  |j                  j                  j                                 S t        |      t        |      k7  r%d	t        |       d
t        |       }t        |      | S )a  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                6    | j                   sd}t        |      y )Nz'given index doesn't have a unique index)	is_uniquer  )indexr(  s     r   _validate_indexz*maybe_align_index.<locals>._validate_indexm  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  rk  r  )lhsrhsr  r  r  lhs_anyrhs_anyr(  s           r   maybe_align_indexr  I  sJ   B D="
 5#G5#G+T24G
WW&8$?AT
U0077==>0077==>&&$$11((//33G4L4L4S4S4Y4YZ
 	

 +T24G
WW&94@BR
S0077==>1188>>?&&$$11((//33--44::
 	
 ,d35E
WW&8$?AT
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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                    t        d|       }|j                         }t        |      st        |      r|j                  S y)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_nativer4   r5   r  )objobj_any
native_objs      r   maybe_get_indexr    s=    : 5#G""$J
+/DZ/Pr   )r  c               V   ddl m} t        d|       }|j                         }||d}t        |      |s|d}t        |      |.t	        |      r|D cg c]  } ||d       c}n	 ||d      }n|}t        |      r9|j                  |j                  j                  |j                  |                  S t        |      r^ddlm	}	 |rd	}t        |       |	||| j                  j                  
      }|j                  |j                  j                  |            S |S c c}w )a  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)rd  )narwhals.translater  r   r  rl  r4   r  r  r  r  r5   narwhals._pandas_like.utilsr  r   )
r  column_namesr  r  df_anyr  r(  idxkeysr  s
             r   maybe_set_indexr    s7   ^ -%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M1 As   D&c                   t        d|       }|j                         }t        |      rX|j                         }t	        ||      r|S |j                  |j                  j                  |j                  d                  S t        |      rX|j                         }t	        ||      r|S |j                  |j                  j                  |j                  d                  S |S )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  r4   __native_namespace___has_default_indexr  r  r  reset_indexr5   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   )strict)rP  rT  c                    t        |       dk  rt        |  S ddfd}dfd}t        |       }t        t	        |       |             }t        t        t        |            t        t        |g  |             S )NrR  Fc               3     K   d y w)NTr   )first_stoppeds   r   
first_tailzzip_strict.<locals>.first_tailh  s      $s   c               3  x   K   sd} t        |       t        j                        D ]  }d} t        |        y w)Nz$zip_strict: first iterable is longerz%zip_strict: first iterable is shorter)r  r   from_iterable)r(  r   r  rests     r   zip_tailzzip_strict.<locals>.zip_tailo  sB     $@C$S/),,T2 AAC$S/)s   7:)r   r   )rk  zipiterr   nextrj  map)	iterablesr  r  iterables_itfirstr  r  s        @@r   
zip_strictr  a  sp    9~!I&!M  	?L$|,jl;ED,/0DU*T*HJ77r   c                .    t        | |j                        S r   )r!  
RangeIndex)r  r  s     r   _is_range_indexr    s    c+6677r   c                    | j                   }t        ||      xr: |j                  dk(  xr) |j                  t	        |      k(  xr |j
                  dk(  S )Nr   rO  )r  r  startstoprk  step)native_frame_or_seriesr  r  s      r   r  r    sW     #((E/0 	KK1	JJ#e*$	 JJ!O	r   c           	     R   t        d|       }|j                         }t        |      r:|j                  |j                  j                   |j                  |i |            S t        |      r:|j                  |j                  j                   |j                  |i |            S |S )aW  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  r4   r  r  r  convert_dtypesr5   r  )r  rm  kwargsr  r  s        r   maybe_convert_dtypesr    s    H 5#G""$J
+&&$$11)
))4:6:
 	

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

 Nr   c                v    |dv r| S |dv r| dz  S |dv r| dz  S |dv r| dz  S |dv r| d	z  S d
|}t        |      )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.
    >   brw  >   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|Gx
PC
S/r   c                   ddl m} | j                  j                  j                  }| j                  }d}t        ||      r;t        | j                  |j                        r|j                  j                  d   }|S | j                  |j                  k(  rd}|S | j                  |j                  k7  rd}|S | j                         }| j                  }|j                         r8|j                         dk  r%t        d|j                        j                   dk(  }|S |j#                         r!t%        |j&                  j(                        }|S |j+                         r0dd	lm}  ||j0                        xr |j0                  j(                  }|S )
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="lexical"))

        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)
        False
    r   )InterchangeSeriesF
is_orderedT)rO      zpl.Categoricalphysical)is_dictionary)narwhals._interchange.seriesr  r  r   r   r!  dtypeCategoricalr   describe_categoricalr   r  rd  r3  r   r   orderingr/  rM  catorderedr?  narwhals._arrow.utilsr  r  )r   r  r   r   resultr   re  r  s           r   is_ordered_categoricalr    sa   T ?%%..55F((IF)./Jf((5 !!66|D& M% 
	$" M! 
++	+ M !!#$$>> 5 5 7' A *FLL9BBjPF M   "&**,,-F
 M	 __;"6;;/GFKK4G4GFMr   c                :    d}t        |d       t        | |      S )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)'7KKr   c                r    d}	 dt        | dz
         }||vr|S |dz  }|dkD  rd| d| }t        |      5)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   nwrO  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  0  sm    , G
 Yw{+,-L1S=*L	3  !%% r   c                  |s-t        t        | j                        j                  |            S t        |      }t	        || j                        x}r||S )N)	available)rj  setr   intersectioncheck_columns_exist)framesubsetr  to_droperrors        r   parse_columns_to_dropr   W  sO     C&33F;<<6lG#Gu}}EEuENr   c                H    t        | t              xr t        | t               S r   )r!  r	   r   )sequences    r   is_sequence_but_not_strr#  b  s    h)K*Xs2K.KKr   c                B    t        | t              xr | t        d       k(  S r   )r!  slicer  s    r   is_slice_noner'  f  s    c5!8cU4[&88r   c                    t        |       xr3 t        |       dkD  xr t        | d   t              xs t        |       dk(  xs% t	        |       xs t        |       xs t        |       S Nr   )r#  rk  r!  r}  r3   r1   is_compliant_series_intr&  s    r   is_sized_multi_index_selectorr+  j  sl    
 $C( Pc(Q,::c!fc#:NCA	( !%		(
 "#&	( #3'r   c                f    t        |       xs% t        |       xs t        |       xs t        |       S r   )r#  r2   r0   is_compliant_seriesr&  s    r   is_sequence_liker.  x  s:     	 $ 	$S!	$c"	$ s#	r   c                
   t        | t              xrr t        | j                  t              xsV t        | j                  t              xs: t        | j
                  t              xr | j                  d u xr | j                  d u S r   )r!  r%  r  r}  r  r  r&  s    r   is_slice_indexr0    sh    c5! 399c" 	Rchh$	Rsxx%P#))t*;PD@Pr   c                "    t        | t              S r   )r!  ranger&  s    r   is_ranger3    s    c5!!r   c                Z    t        t        | t              xr t        | t                      S r   )rM  r!  r}  r&  s    r   is_single_index_selectorr5    s#    
3$BZT-B)BCCr   c                L    t        |       xs t        |       xs t        |       S r   )r5  r+  r0  r&  s    r   is_index_selectorr7    s+     	!% 	(-	#r   c                ^    t        t        | t              xr | xr t        | d   |            S r)  )rM  r!  rj  )r  tps     r   
is_list_ofr:    s)    
3%H#H*SVR2HIIr   c                x    t        t        |       xr% t        t        |       d       x}xr t	        ||            S r   )rM  r#  r  r  r!  )r  r9  r  s      r   is_sequence_ofr<    s>    $ 	"49d++U	"ub! r   c               L    | ||}|S | ||  }|S | |	 |S d}t        |      )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                     d fd}|S )a8  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               6     t               d fd       }|S )Nc                     |j                  dd       }|j                  dd       }||rd}t        |       |}n2||d}t        |      ||rdj                   d}t        |      ||d<    | i |S )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  r   )rm  kwdsr"  r  r(  fnrA  r@  s        r   wrapperz=deprecate_native_namespace.<locals>.decorate.<locals>.wrapper  s    hhy$/G#xx(:DA+j 
 .cLI*!-'2EH o%!)go(8RH o%%DOt$t$$r   )rm  P.argsrF  P.kwargsr   r   )r   )rG  rH  rA  r@  s   ` r   decoratez,deprecate_native_namespace.<locals>.decorate  s     	r	% 
	%* r   )rG  Callable[P, R]r   rL  r   )r@  rA  rK  s   `` r   deprecate_native_namespacerM    s    2 Or   c                    t        | t        d       t        |t        t        d       d       | dk  rd}t        |      |(|dk  rd}t        |      || kD  rd}t	        |      | |fS | }| |fS )Nwindow_size
param_namemin_samplesrO  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  r8   )rO  rR  r(  s      r   _validate_rolling_argumentsrT    s     S];S$t*GQ;o??CS/!$JC',, ## "##r   c           
        	 t        j                         j                  }|j                         j                         }t        d |D              }|dz   |k  rt        |t        |             }dd|z   d}|t        |       z
  }|dd	|dz  z   |  d	|dz  |dz  z   z   d
z  }|dd|z   d
z  }||z
  dz  }||z
  dz  ||z
  dz  z   }	|D ]$  }
|dd	|z   |
 d	|	|z   t        |
      z
  z   d
z  }& |dd|z   dz  }|S dt        |       z
  }dd dd	|dz  z   |  d	|dz  |dz  z   z   dd d	S # t        $ r# t	        t        j
                  dd            }Y :w xY w)NCOLUMNSP   c              3  2   K   | ]  }t        |        y wr   )rk  )r  lines     r   r  z generate_repr.<locals>.<genexpr>  s     >3t9>   rR  u   ┌u   ─u   ┐
| z|
-u   └u   ┘'   uu   ───────────────────────────────────────u   ┐
|u/   |
| Use `.to_native` to see native output |
└)
osget_terminal_sizer   OSErrorr}  getenv
expandtabs
splitlinesmaxrk  )headernative_reprterminal_widthnative_linesmax_native_widthlengthoutputheader_extrastart_extra	end_extrarY  diffs               r   generate_reprrq    s   7--/77 ))+668L>>>!~-%s6{3uv~&e,F+Ac\Q./0PQ@QT`cdTd@d9e8ffijjAcVn%S)) 00Q6..14AQ8QUV7VV	  	kD#-.tfSIHX<X[^_c[d<d5e4ffijjF	kC's++FD
l^ 419vhsdai$(.B'C&D E9,c	'  7RYYy"567s   D/ /(EEc              h    t        |       j                  |      x}rt        j                  ||      S y r   )r  
differencer6   'from_missing_and_available_column_names)r  r  missings      r   r  r    s;     f+((33w3"JJY
 	
 r   c                *   t        |       t        t        |             k7  rmddlm}  ||       }|j	                         D ci c]  \  }}|dkD  s|| }}}dj                  d |j	                         D              }d| }t        |      y c c}}w )Nr   )CounterrO  r{  c              3  4   K   | ]  \  }}d | d| d  yw)z
- 'z' z timesNr   )r  kr  s      r   r  z0check_column_names_are_unique.<locals>.<genexpr>,  s#     LAaS1#V,Ls   z"Expected unique column names, got:)rk  r  collectionsrw  r  joinr7   )r   rw  r  ry  r  
duplicatesr(  s          r   check_column_names_are_uniquer}  &  s    
7|s3w<((''"'.}}@tq!!a%ad@
@ggL9I9I9KLL23%8S!! ) As   BBc                    | h dnt        | t              r| hn
t        |       }|d hn>t        |t        t        f      rt        |      hn|D ch c]  }|t        |      nd  c}}||fS c c}w )N>   smsnsus)r!  r   r  r
   )	time_unit	time_zone
time_unitstz
time_zoness        r   _parse_time_unit_and_time_zoner  1  s      	  i% [^   
 i#x1 )n<EFbc"gT1F  z!! Gs   A-c                    t        | |j                        xr4 | j                  |v xr$ | j                  |v xs d|v xr | j                  d uS )N*)r!  Datetimer  r  )r  r   r  r  s       r   %dtype_matches_time_unit_and_time_zoner  F  sW     	5&//* 	
__
*	
 OOz) Cz!AeooT&Ar   c                   | j                   S r   r   )r  s    r   get_column_namesr  S  s    ==r   c                J    | j                   D cg c]	  }||vs| c}S c c}w r   r  )r  namescol_names      r   exclude_column_namesr  W  s!    %*]]Lhe6KHLLLs   	  c                    d fd}|S )Nc                   S r   r   )_framer  s    r   rG  z$passthrough_column_names.<locals>.fn\  s    r   )r  r   r   r   r   )r  rG  s   ` r   passthrough_column_namesr  [  s     Ir   c                4    t               }t        | ||      |uS r   )objectr   )r  attrsentinels      r   _hasattr_staticr  b  s    xH#tX.h>>r   c                    t        | d      S )N__narwhals_dataframe__r  r&  s    r   is_compliant_dataframer  g  s     3 899r   c                    t        | d      S )N__narwhals_lazyframe__r  r&  s    r   is_compliant_lazyframer  r  s     3 899r   c                    t        | d      S )N__narwhals_series__r  r&  s    r   r-  r-  x  s     3 566r   c                P    t        |       xr | j                  j                         S r   )r-  r  
is_integerr&  s    r   r*  r*  ~  s!     s#>		(<(<(>>r   c                    t        | d      S )N__narwhals_expr__)hasattrr&  s    r   is_compliant_exprr    s     3+,,r   c                   | t         j                  t         j                  t         j                  t         j                  t         j
                  hv S )z.Return True if `impl` allows eager operations.)r   r  r  r  r  r  re  s    r   is_eager_allowedr    sA      r   c               d    | t         j                  t         j                  t         j                  hv S )z4Return True if `LazyFrame.collect(impl)` is allowed.)r   r  r  r  r  s    r   can_lazyframe_collectr    s&    N))>+@+@.BXBXYYYr   c                   | t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  hv S )z1Return True if `DataFrame.lazy(impl)` is allowed.)r   r  r  r  r  r  r  r  r  s    r   is_lazy_allowedr    sS    &&  r   c                    t        | d      S )Nr  r  r&  s    r   has_native_namespacer    s    3 677r   c                    t        | d      S )N__arrow_c_stream__r  r&  s    r   supports_arrow_c_streamr    s    3 455r   c                H      fd|D        }t        t        ||            S )aO  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  6   K   | ]  }|v r|  n|  y wr   r   )r  keyleft_onsuffixs     r   r  z(_remap_full_join_keys.<locals>.<genexpr>  s*      8;C7N3%x3r  )dictr  )r  right_onr  right_keys_suffixeds   ` ` r   _remap_full_join_keysr    s(     ?G H1233r   c                   t        d      rV|j                  j                  j                  d      j                  }|j
                  j                  | |      j                  S dt        |       d}t        |      )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   ru  ModuleNotFoundError)datar  r  r(  s       r   _into_arrow_tabler    sp     ''44Y?II}}''b'9@@@NObcgOhNkkl
mC
c
""r   c                   | S )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)
    r   )rG  s    r   unstabler    s	    ( Ir   c                .     t         fddD               S )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  &   K   | ]  }|v  
 y wr   r   )r  xformats     r   r  z#_is_naive_format.<locals>.<genexpr>  s     :11;:s   )z%sz%zZ)any)r  s   `r   _is_naive_formatr    s     :(9::::r   c                  Z    e Zd ZdZd	d
dZddZddZ	 d		 	 	 	 	 ddZddZe	dd       Z
y)not_implementeda  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                   || _         y r   )_alias)r   aliass     r   __init__znot_implemented.__init__&  s     #(r   c                f    dt        |       j                   d| j                   d| j                   S )N<z>: r  )r  r   _name_owner_namer   s    r   __repr__znot_implemented.__repr__+  s1    4:&&'s4+;+;*<Adjj\JJr   c                P    |j                   | _        | j                  xs || _        y r   )r   r  r  r  r   r   names      r   __set_name__znot_implemented.__set_name__.  s     %++-
r   c               f    || S t        |d| j                        }t        | j                  |       y )Nr   )r  r  _raise_not_implemented_errorr  )r   r   r   whos       r   r   znot_implemented.__get__3  s9      K h 143C3CD$TZZ5r   c                $    | j                  d      S )Nraise)r   )r   rm  rF  s      r   __call__znot_implemented.__call__A  s     ||G$$r   c               2     |        } t        |      |      S )zAlt constructor, wraps with `@deprecated`.

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

        [descriptor]: https://docs.python.org/3/howto/descriptor.html
        )r$   )r  messager  s      r   r$   znot_implemented.deprecatedF  s     e"z'"3''r   r   )r  z
str | Noner   r   rK  )r   type[_T]r  r   r   r   )r   z_T | Literal['raise'] | Noner   ztype[_T] | Noner   r   )rm  r   rF  r   r   r   )r  r<   r   r>   )r   r   r   r   r  r  r  r   r  rN  r$   r   r   r   r  r    sU    "H(
K. PT4=L	%
 	( 	(r   r  c               (    | d|d}t        |      )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  S  s,    (+C7 3S 	S 
 c
""r   c                  \    e Zd ZU dZded<   ded<   eddd       Zedd       ZddZ	dd	Z
y
)requiresa#  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_versionr   _hintc               D    | j                  |       }||_        ||_        |S )zMethod decorator for raising below a minimum `_backend_version`.

        Arguments:
            minimum: Minimum backend version.
            hint: Optional suggested alternative.
        )__new__r  r  )r  minimumhintr  s       r   rJ  zrequires.backend_versionv  s&     kk#"	
r   c               2    dj                  d | D              S )Nr  c              3  "   K   | ]  }|  	 y wr   r   )r  ds     r   r  z,requires._unparse_version.<locals>.<genexpr>  s     811#8s   )r{  rI  s    r   _unparse_versionzrequires._unparse_version  s    xx8888r   c          	     @   |j                   | j                  k\  ry | j                  }|j                  }| j	                  | j                        }| j	                  |j                         }d| d| d| d|d	}| j
                  r| d| j
                   }t        |      )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_versionzrequires._ensure_version  s    $$(9(99##**''(9(9:%%h&?&?@&1'"WIEVW\V__`a::EDJJ<(C!#&&r   c               V     j                    _        t              d fd       }|S )Nc                >    j                  |         | g|i |S r   )r  )r   rm  rF  rG  r   s      r   rH  z"requires.__call__.<locals>.wrapper  s&      *h....r   )r   r   rm  rI  rF  rJ  r   r   )r   r  r   )r   rG  rH  s   `` r   r  zrequires.__call__  s,    [[	r	/ 
	/
 r   N)r{  )r  r   r  r   r   r>   )rJ  r   r   r   )r   r   r   r   )rG  _Method[_ContextT, P, R]r   r  )r   r   r   r   r   rN  rJ  staticmethodr  r  r  r   r   r   r  r  \  sD    , "!J
 
 9 9
'	r   r  c                    | j                   |j                  | j                         nd }| j                  |j                  | j                        dz   nd }| j                  }|||fS )NrO  )r  r  r  r  )	str_slicer   r  r  r  s        r   convert_str_slice_to_int_slicer    sZ     /8oo.IGMM)//*tE090J7==(1,PTD>>D4r   c                    d fd}|S )zSteal the class-level docstring from parent and attach to child `__init__`.

    Returns:
        Decorated constructor.

    Notes:
        - Passes static typing (mostly)
        - Passes at runtime
    c                   | j                   dk(  r+t        t              t              rt              | _        | S dt
        j                    d| j                  d}t        |      )Nr  z`@zL` is only allowed to decorate an `__init__` with a class-level doc.
Method: z	
Parent: )r   r  r  r   r   inherit_docr   rv  )
init_childr(  	tp_parents     r   rK  zinherit_doc.<locals>.decorate  sp    *,DOT1R!'	!2J%%& '!..1 2 m% 	
 nr   )r	  _Constructor[_T, P, R2]r   r  r   )r
  rK  s   ` r   r  r    s    	 Or   c                   t        | t              r| n
t        |       }|j                  dk7  r|j                  nd}| d|j                   j	                  d      S )Nbuiltinsr{  r  )r!  r  r   r   lstrip)r  r9  modules      r   ru  ru    sL    3%49B mmz9R]]rFXQr{{m$++C00r   rP  c              :   t        | |      sdj                  d |D              }d|dt        |       }|rYd}t        |       }t	        |      dkD  rt        |        d}| | d}d	t	        |      z  d
t	        |      z  z   }| d| | d| }t        |      y)a  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  2   K   | ]  }t        |        y wr   )ru  )r  r9  s     r   r  zensure_type.<locals>.<genexpr>  s     L"1"5LrZ  z	Expected z, got: z    (   z(...)=r\  ^r  N)r!  r{  ru  reprrk  rv  )	r  rQ  valid_typestp_namesr(  left_padvalassign	underlines	            r   rS  rS    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                  (    e Zd ZdZddZddZddZy)	_DeferredIterablezLStore a callable producing an iterable to defer collection until we need it.c                   || _         y r   
_into_iter)r   	into_iters     r   r  z_DeferredIterable.__init__  s	    6?r   c              #  @   K   | j                         E d {    y 7 wr   r  r   s    r   __iter__z_DeferredIterable.__iter__  s     ??$$$s   c                \    | j                         }t        |t              r|S t        |      S r   )r   r!  rp  )r   its     r   to_tuplez_DeferredIterable.to_tuple  s&    __E*r9b	9r   N)r!  zCallable[[], Iterable[_T]]r   r   )r   zIterator[_T])r   ztuple[_T, ...])r   r   r   r   r  r#  r&  r   r   r   r  r    s    V@%:r   r  @   c                J    |rdj                  | g|      n| }t        |      S )Nr  )r{  r   )r  nestedr  s      r   deep_attrgetterr*    s%    (.388TOFO$DDdr   c                &     t        |g| |       S )z+Perform a nested attribute lookup on `obj`.)r*  )r  name_1r)  s      r   deep_getattrr-    s    +?6+F+C00r   c                      e Zd Zy)	CompliantN)r   r   r   r   r   r   r/  r/    s    r   r/  c                  "    e Zd ZdZedd       Zy)Narwhalsa  Minimal *Narwhals-level* protocol.

    Provides access to a compliant object:

        obj: Narwhals[NativeT_co]]
        compliant: Compliant[NativeT_co] = obj._compliant

    Which itself exposes:

        implementation: Implementation = compliant.implementation
        native: NativeT_co = compliant.native

    This interface is used for revealing which `Implementation` member is associated with **either**:
    - One or more [nominal] native type(s)
    - One or more [structural] type(s)
      - where the true native type(s) are [assignable to] *at least* one of them

    These relationships are defined in the `@overload`s of `_Implementation.__get__(...)`.

    [nominal]: https://typing.python.org/en/latest/spec/glossary.html#term-nominal
    [structural]: https://typing.python.org/en/latest/spec/glossary.html#term-structural
    [assignable to]: https://typing.python.org/en/latest/spec/glossary.html#term-assignable
    c                     y r   r   r   s    r   
_compliantzNarwhals._compliant0  s    36r   N)r   zCompliant[NativeT_co])r   r   r   r   r   r3  r   r   r   r1  r1    s    0 6 6r   r1  c                  j   e Zd ZdZddZedd       Zedd       Zedd       Zedd       Ze	 	 	 	 	 	 dd       Zedd       Ze	 	 	 	 	 	 dd	       Zedd
       Ze	 	 	 	 	 	 dd       Zedd       Zedd       Ze	 	 	 	 	 	 d d       Zed!d       Ze	 	 	 	 	 	 d"d       Zed#d       Zd$dZy)%_ImplementationzDescriptor for matching an opaque `Implementation` on a generic class.

    Based on [pyright comment](https://github.com/microsoft/pyright/issues/3071#issuecomment-1043978070)
    c                    || _         y r   )r   r  s      r   r  z_Implementation.__set_name__:  s	    !r   c                     y r   r   r   s      r   r   z_Implementation.__get__=      UXr   c                     y r   r   r   s      r   r   z_Implementation.__get__?  r8  r   c                     y r   r   r   s      r   r   z_Implementation.__get__A      SVr   c                     y r   r   r   s      r   r   z_Implementation.__get__C      QTr   c                     y r   r   r   s      r   r   z_Implementation.__get__E  s     r   c                     y r   r   r   s      r   r   z_Implementation.__get__I  r;  r   c                     y r   r   r   s      r   r   z_Implementation.__get__K  s     25r   c                     y r   r   r   s      r   r   z_Implementation.__get__O  r8  r   c                     y r   r   r   s      r   r   z_Implementation.__get__Q  s     r   c                     y r   r   r   s      r   r   z_Implementation.__get__U  r=  r   c                     y r   r   r   s      r   r   z_Implementation.__get__W  r=  r   c                     y r   r   r   s      r   r   z_Implementation.__get__Y  s     .1r   c                     y r   r   r   s      r   r   z_Implementation.__get__^  s    KNr   c                     y r   r   r   s      r   r   z_Implementation.__get__`  r  r   c                     y r   r   r   s      r   r   z_Implementation.__get__d  r=  r   c                6    || S |j                   j                  S r   )r3  r   r   s      r   r   z_Implementation.__get__f  s    'tPX-@-@-P-PPr   N)r   	type[Any]r  r   r   r   )r   zNarwhals[_NativePolars]r   r   r   rg   )r   zNarwhals[_NativePandas]r   r   r   re   )r   zNarwhals[_NativeModin]r   r   r   rd   )r   zNarwhals[_NativeCuDF]r   r   r   r]   )r   zNarwhals[_NativePandasLike]r   r   r   rf   )r   zNarwhals[_NativeArrow]r   r   r   r\   )r   z6Narwhals[_NativePolars | _NativeArrow | _NativePandas]r   r   r   z&_PolarsImpl | _PandasImpl | _ArrowImpl)r   zNarwhals[_NativeDuckDB]r   r   r   r_   )r   zNarwhals[_NativeSQLFrame]r   r   r   rj   )r   zNarwhals[_NativeDask]r   r   r   r^   )r   zNarwhals[_NativeIbis]r   r   r   ra   )r   z0Narwhals[_NativePySpark | _NativePySparkConnect]r   r   r   z"_PySparkImpl | _PySparkConnectImpl)r   r   r   ztype[Narwhals[Any]]r   r>   )r   zDataFrame[Any] | Series[Any]r   r   r   r`   )r   zLazyFrame[Any]r   r   r   rb   )r   zNarwhals[Any] | Noner   r   r   r   )r   r   r   r   r  r    r   r   r   r   r5  r5  4  s|   
" X XX XV VT T3<?	  V V5N5WZ5	/5 5 X X1:=	  T TT T1H1QT1	+1 1 N N 4 =@ 	    T TQr   r5  c                p    dd l }t        | |j                        r|j                  j	                  |       S | S r)  )r   r!  RecordBatchReaderTablefrom_batches)tblpas     r   to_pyarrow_tablerQ  j  s/    #r++,xx$$S))Jr   c               T    t        | t              r| S ddlm} t         ||             S )Nr   )Path)r!  r   pathlibrS  )sourcerS  s     r   normalize_pathrV  r  s#    &#tF|r   )r)  r   r   r:   )rd  r   r   r   )rm  r   r   z	list[Any])rq  r   r   r   )rq  zAny | Iterable[Any]r   rM  )rg  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  rW  r  rX  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  rW  r  rY  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  rW  r  rZ  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  rW  r  r[  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  rW  r  r\  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  rW  r  r]  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   rM  )r  Iterable[Any]r   r   )r  r   r  z-Series[Any] | DataFrame[Any] | LazyFrame[Any]r   r   )r  z-DataFrame[Any] | LazyFrame[Any] | Series[Any]r   r   r   )r  r   r  zstr | list[str] | Noner  z6Series[IntoSeriesT] | list[Series[IntoSeriesT]] | Noner   r   )r  r   r   r   )r  r^  r   zIterable[tuple[Any, ...]])r  r   r  r   r   zTypeIs[pd.RangeIndex])r  zpd.Series[Any] | pd.DataFramer  r   r   rM  )r  r   rm  rM  r  z
bool | strr   r   )r  r}  r  r{   r   zint | float)r   zSeries[Any]r   rM  )r  r}  r   Container[str]r   r   )r  r   r  zIterable[str]r  rM  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  r`  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   r9  r  r   zTypeIs[list[_T]])r  r   r9  r  r   ra  )r  bool | Noner  rb  r>  rM  r   rM  )r@  r   rA  rM  r   z*Callable[[Callable[P, R]], Callable[P, R]])rO  r}  rR  z
int | Noner   ztuple[int, int])rf  r   rg  r   r   r   )r  Collection[str]r  rc  r   zColumnNotFoundError | None)r   rc  r   r   )r  z$TimeUnit | Iterable[TimeUnit] | Noner  z7str | timezone | Iterable[str | timezone | None] | Noner   z%tuple[Set[TimeUnit], Set[str | None]])
r  ro   r   ru   r  zSet[TimeUnit]r  zSet[str | None]r   rM  )r  r   r   r   )r  r   r  r_  r   r   )r  r   r   zEvalNames[Any])r  r   r  r   r   rM  )r  z\CompliantDataFrame[CompliantSeriesT, CompliantExprT, NativeDataFrameT, ToNarwhalsT_co] | Anyr   z^TypeIs[CompliantDataFrame[CompliantSeriesT, CompliantExprT, NativeDataFrameT, ToNarwhalsT_co]])r  zJCompliantLazyFrame[CompliantExprT, NativeLazyFrameT, ToNarwhalsT_co] | Anyr   zLTypeIs[CompliantLazyFrame[CompliantExprT, NativeLazyFrameT, ToNarwhalsT_co]])r  z'CompliantSeries[NativeSeriesT_co] | Anyr   z)TypeIs[CompliantSeries[NativeSeriesT_co]])r  zECompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co] | Anyr   zGTypeIs[CompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co]])re  r   r   zTypeIs[_EagerAllowedImpl])re  r   r   zTypeIs[_LazyFrameCollectImpl])re  r   r   zTypeIs[_LazyAllowedImpl])r  r   r   zTypeIs[SupportsNativeNamespace])r  r   r   zTypeIs[ArrowStreamExportable])r  rc  r  rc  r  r   r   zdict[str, str])r  rX   r  r   r   pa.Table)rG  r   r   r   )r  r   r   rM  )r  r   r  r   r   r  )r  r   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   r   )r  r   r  rJ  rQ  r   r   r   )r  r   r)  r   r   zattrgetter[Any])r  r   r,  r   r)  r   r   r   )rO  zpa.Table | pa.RecordBatchReaderr   rd  )rU  rv   r   r   (  
__future__r   r_  r~  collections.abcr   r   r   r   r   r	   datetimer
   enumr   r   	functoolsr   r   r   r   importlib.utilr   inspectr   r   	itertoolsr   operatorr   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/   r0   r1   r2   r3   r4   r5   narwhals.exceptionsr6   r7   r8   r9   typesr:   r   rx  r  ry  r   rP  typing_extensionsr;   r<   r=   r>   r?   r@   narwhals._compliantrA   rB   rC   rD   rE   rF   narwhals._compliant.typingrG   rH   rI   r   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   narwhals._translaterW   rX   rY   narwhals._typingrZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   r   rl   rm   r  ro   r   rq   narwhals.typingrr   rs   rt   ru   rv   rw   rx   ry   rz   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   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'  rJ  rn  rr  rl  rc  r  r  r  r  r  r  r  r  sysversion_infor  r  r  r  r  r  r  r   r#  r'  r+  r.  r0  r3  r5  r7  r:  r<  r?  rM  rT  rq  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  rS  r  r*  r-  r/  r1  r5  rQ  rV  r   r   r   <module>r~     s
   " 	 	 X X   6 6 $ *      & : <    & [ Z#    YX    ZY    & 8%&    & %(	'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M%Z M%b 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V EI	V	V(V B	V
 Vr/d T*J
7"S.
	8<8	9	MP			2	2 $20:22j0FRLL)LL$&N#0@DL9	H	2"D	YJ
 	
 
& &&)-&/&R$$#-$$0<.=""3"F" +"*

 
.;
IX
	
M?
:

:
::	S:Q:7	07.7?	0?.?-	N-L-Z

8644(74AD44,#&.;$O( O(d#@ @F$1'A61 IK ,^: : 2 
1
*4hz6J
7x
# 7:3Q 3Qlr   