
    }iG                      U d dl mZ d dl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" d dl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZI d dlJmKZKmLZLmMZM e$rd dlmNZN d dlOmPZP d dlQZRd dlSZTd dlUZVd dlWmXZXmYZYmZZZm[Z[m\Z\m]Z] d dl^m_Z_m`Z`maZa d dlbmcZc d dldmeZemfZfmgZgmhZh d dlimjZj d dlkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZw d dlxmyZymzZzm{Z{ d dl|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZ d dlmZ d dlmZ d d lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ eZd!ed"<    e+d#e,ee%         ee%         ee%         f         $          Z e+d%          Z e+d&          Z e+d'          Z e+d(d)$          Z eZd*          Z e+d+          Z e+d,          Z e+d-          Z G d. d/e*          Z G d0 d1e*          Z G d2 d3e*          Z e+d4          Z e+d5d67          Z e+d8d67          Zd9Zd!ed:<    e+d;e$          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 dMeee*          Z G dN dOee*          Z G dP dQe          Z G dR dSe0          ZǐdxdWZej        dXej        dYej        dZej        d[ej        d\ej        d\ej        d]ej        d^ej        d_ej        d`ej        daiZdbedc<   ej        ddej        deej        dfej        dgiZdhedi<   	  edjk          dydo            Zedzdq            Zאd{duZؐd|dwZِd}dyZڐd~d}ZېddZe.dd            Ze.dd            Ze.dd            Ze.dd            Ze.dd            Ze.dd            Ze.dd            ZݐddZݐddZސddZߐddZ	 dddddZddZe$r eed6          Zn"d dlZej        dk    r eed6          ZnddZddZddZddZddZddZ	 dddǄZ	 dddȄZdd΄Zdd҄ZddԄZddքZdd؄ZddڄZdd܄ZddބZddZddZddZddZddZddZddZdddddZddZddZddZddZ dd
ZddZddZddZddZ e            Zded<   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d1Zdd3Zdd5Zdd:Zdd?ZddAZddCZ G dD dE          ZddIZ G dJ dK          ZddOZddSZddUZddVddZZ G d[ d\e(e                   Z ed]k          dd`            Z dÐdbZ! G dc ddee         ee*e                   Z" G de dfe*e                   Z# G dg dh          Z$dĐdkZ%ej&        dlk    rdŐdoZ'ndŐdpZ'dƐduZ( G dv dwe          Z)e)j*        Z* e+d          Z,dS (      )annotationsN)
Collection	ContainerIterableIteratorMappingSequence)timezone)Enumauto)cache	lru_cachepartialwraps)	find_spec)getattr_staticgetdoc)chain)
attrgetter)Path)	token_hex)TYPE_CHECKINGAnyCallableFinal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_boolis_narwhals_series_intis_numpy_array_1dis_numpy_array_1d_boolis_numpy_array_1d_intis_pandas_like_dataframeis_pandas_like_series)ColumnNotFoundErrorDuplicateErrorInvalidOperationError)Set)
ModuleType)ConcatenateLiteralString	ParamSpecSelf	TypeAliasTypeIs)CompliantExprTCompliantSeriesTNativeSeriesT_co)NamespaceAccessor)Accessor	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NestedLiteralSingleIndexSelectorSizedMultiBoolSelectorSizedMultiIndexSelectorSizeUnitSupportsNativeNamespaceTimeUnit_1DArray_SliceIndex
_SliceName
_SliceNonerC   UnknownBackendNameFrameOrSeriesT)bound_T1_T2_T3_FnzCallable[..., Any]PRR1R2c                      e Zd ZU ded<   dS )_SupportsVersionstr__version__N__name__
__module____qualname____annotations__     C/home/jrussi/.local/lib/python3.11/site-packages/narwhals/_utils.pyr   r      s         r   r   c                      e Zd Zdd	dZdS )
_SupportsGetNinstancer   owner
Any | Nonereturnc                   d S Nr   selfr   r   s      r   __get__z_SupportsGet.__get__   s      r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r      s        QQQQQQQr   r   c                  &    e Zd Zedd            ZdS )_StoresColumnsr   Sequence[str]c                    d S r   r   r   s    r   columnsz_StoresColumns.columns   s    ,/Cr   N)r   r   )r   r   r   propertyr   r   r   r   r   r      s&        	/// 
///r   r   _T
NativeT_coT)	covariantCompliantT_coz._FullContext | NamespaceAccessor[_FullContext]_IntoContext_IntoContextTz*Callable[Concatenate[_IntoContextT, P], R]_Methodz Callable[Concatenate[_T, P], R2]_Constructorc                  *    e Zd ZdZedd            ZdS )_StoresNativezProvides access to a native object.

    Native objects have types like:

    >>> from pandas import Series
    >>> from pyarrow import Table
    r   r   c                    dS )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      >             X  r   r   c                  *    e Zd ZdZedd            ZdS )_StoresCompliantzProvides access to a compliant object.

    Compliant objects have types like:

    >>> from narwhals._pandas_like.series import PandasLikeSeries
    >>> from narwhals._arrow.dataframe import ArrowDataFrame
    r   r   c                    dS )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dS )_StoresBackendVersionr   tuple[int, ...]c                    dS )z#Version tuple for a native package.Nr   r   s    r   _backend_versionz&_StoresBackendVersion._backend_version   r   r   Nr   r   )r   r   r   r   r   r   r   r   r   r      s2           X  r   r   c                      e Zd ZU ded<   dS )_StoresVersionVersion_versionNr   r   r   r   r   r      s         ,,r   r   c                      e Zd ZU ded<   dS )_StoresImplementationImplementation_implementationNr   r   r   r   r   r      s         ####IIr   r   c                      e Zd ZdZdS )_LimitedContextzEProvides 2 attributes.

    - `_implementation`
    - `_version`
    Nr   r   r   r   r   r   r   r   r                 r   r   c                      e Zd ZdZdS )_FullContextzMProvides 2 attributes.

    - `_implementation`
    - `_backend_version`
    Nr   r   r   r   r   r      r   r   r   c                      e Zd ZdZddZdS )ValidateBackendVersionz=Ensure the target `Implementation` is on a supported version.r   Nonec                8    | j                                         }dS )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3r   N)r   r   )r   r   r   r   r   r   r   r   r   r      s.        GG4 4 4 4 4 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dS )r   r   type[Namespace[Any]]c                j    | 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   V1narwhals.stable.v1._namespacerN   V2narwhals.stable.v2._namespacenarwhals._namespace)r   NamespaceV1NamespaceV2rN   s       r   	namespacezVersion.namespace   sd    7:NNNNNN7:NNNNNN111111r   ry   c                j    | 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  sc    7:>>>>>>7:>>>>>>######r   type[DataFrame[Any]]c                j    | 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   rp   r   r   narwhals.dataframe)r   DataFrameV1DataFrameV2rp   s       r   	dataframezVersion.dataframe  d    7:CCCCCC7:CCCCCC000000r   type[LazyFrame[Any]]c                j    | t           j        u rddlm} |S | t           j        u rddlm} |S ddlm} |S )Nr   )rq   )r   r   r   rq   r   r   r   )r   LazyFrameV1LazyFrameV2rq   s       r   	lazyframezVersion.lazyframe(  r   r   type[Series[Any]]c                j    | t           j        u rddlm} |S | t           j        u rddlm} |S ddlm} |S )Nr   rt   )r   r   r   ru   r   r   narwhals.series)r   SeriesV1SeriesV2ru   s       r   serieszVersion.series6  sa    7:======O7:======O******r   N)r   r   )r   ry   )r   r   )r   r   )r   r   )r   r   r   r   r   r   MAINr   r   r   r   r   r  r   r   r   r   r      s        	B	B466D   X    X    X    X    X  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d0d            Zd1dZd2dZd2dZd2dZd2d Zd2d!Zd2d"Zd2d#Zd2d$Zd2d%Zd2d&Zd2d'Z d2d(Z!d2d)Z"d3d+Z#d,S )4r   z?Implementation of native object (pandas, Polars, PyArrow, ...).pandasmodincudfpyarrowpysparkpolarsdaskduckdbibissqlframezpyspark[connect]unknownr   r   c                *    t          | j                  S r   )r   valuer   s    r   __str__zImplementation.__str__a  s    4:r   cls
type[Self]native_namespacer>   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}|                    |t          j                  S )zInstantiate Implementation object from a native namespace module.

        Arguments:
            native_namespace: Native namespace.
        )r,   r   PANDASr+   MODINr'   CUDFr.   PYARROWr0   PYSPARKr-   POLARSr(   DASKr)   DUCKDBr*   IBISr1   SQLFRAMEr/   PYSPARK_CONNECTgetUNKNOWN)r  r  mappings      r   from_native_namespacez$Implementation.from_native_namespaced  s     LL./KK-JJ+MM>1~5LL./  ."5LL./JJ+NNN3!!>#A
 {{+^-CDDDr   backend_namec                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  r%  s     r   from_stringzImplementation.from_string|  sA    	*3|$$$ 	* 	* 	*!))))	*s   
 &&backend)IntoBackend[Backend] | UnknownBackendNamec                    t          |t                    r|                     |          n+t          |t                    r|n|                     |          S )zInstantiate from native namespace module, string, or Implementation.

        Arguments:
            backend: Backend to instantiate Implementation from.
        )
isinstancer   r(  r   r$  )r  r)  s     r   from_backendzImplementation.from_backend  sU     '3''4COOG$$$ '>224**733	
r   c                    | t           j        u rd}t          |          |                                  t                              | | 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  sZ    >)))NC %%%488tzJJ'444r   boolc                    | 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                L    | 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^EXYYYr   c                L    | 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  s(     "#*
 
 	
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  r8  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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  rF  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  rA  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)  r8  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_ibis6  rA  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_sqlframeC  s     ~...r   r   c                     t          |           S )zReturns backend version.backend_versionr   s    r   r   zImplementation._backend_versionP  s    t$$$r   Nr   r   )r  r  r  r>   r   r   )r  r  r%  r   r   r   )r  r  r)  r*  r   r   )r   r>   )r   r5  r   )$r   r   r   r   r  r  r  r  r  r  r  r  r  r  r   r"  r  classmethodr$  r(  r-  r4  r7  r:  r<  r>  r@  rC  rE  rH  rJ  rL  rN  rP  rR  r   r   r   r   r   r   E  s"       IIF EDG!G!F DF DH"(O)G!    E E E [E. 	* 	* 	* [	* 
 
 
 [
 5 5 5 5- - - -Z Z Z Z
 
 
 
"- - - -+ + + +, , , ,. . . .6 6 6 6. . . .+ + + +- - - -+ + + +/ / / /% % % % % %r   r   implementationr   r5  c                    |                                  p|                                 o|                                 dk     S )zJWhether implementation is PySpark (or PySpark Connect) with version < 4.0.)   r   )rE  rH  r   rX  s    r   is_pyspark_pre_4r\  U  sB     	!!##J~'H'H'J'J5

)
)
+
+f
45r   )   r]     )r         )   
   )   )r^     )r      rZ  )i  r_  )r]  r]  )   )r^     r   z(Mapping[Implementation, tuple[int, ...]]MIN_VERSIONSzdask.dataframezmodin.pandaszpyspark.sqlzpyspark.sql.connectzMapping[Implementation, str]r0     )maxsizer3  r   r>   c                $    ddl m}  ||           S )Nr   )import_module)	importlibrl  )r3  rl  s     r   r1  r1  s  s$    ''''''=%%%r   r   c                   t          | t                    st          |            | t          j        u rdS | }t                              ||j                  }t          |          }|                                rdd l	}|j
        }nL|                                s|                                rdd l}|}n|                                rdd l}|}n|}t!          |          }|t"          |         x}	k     rd| d|	 d| }
t%          |
          |S )N)r   r   r   r   zMinimum version of z supported by Narwhals is z	, found: )r,  r   r%   r"  r0  r!  r  r1  rR  sqlframe._versionr   rE  rH  r  rL  r
  parse_versionrh  r'  )rX  implr3  r  r  into_versionr  r
  versionmin_versionr2  s              r   rU  rU  }  s4   nn55 %^$$$///yD044T4:FFK/<< (    (			 	(d5577 	(	 ('L))Gd!33+44cDccKccZaccooNr   argsr   	list[Any]c                    t          t          |           dk    rt          | d                   r| d         n|           S )Nr]  r   )listlen_is_iterable)ru  s    r   flattenr{    s6    CIINN|DG/D/DNQ4PPPr   argc                D    t          | t          t          f          s| fS | S r   )r,  rx  tuple)r|  s    r   tupleifyr    s$    cD%=)) vJr   Any | Iterable[Any]c                   ddl m} t                      x}t          | |j        |j        f          s8t                      x}Jt          | |j        |j        |j        |j        f          r"dt          |           d}t          |          t          | t                    ot          | t          t          |f           S )Nr   rt   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   ru   r,   r,  rp   r-   Exprrq   qualified_type_name	TypeErrorr   r   bytes)r|  ru   pdplr2  s        r   rz  rz    s    &&&&&& ||	(Zbi=V-W-W(||	(sRYr|LMM 	)
37J37O7O 3 3 3 	 nnc8$$RZc5&=Q-R-R)RRr   valIterable[_T] | AnyTypeIs[Iterator[_T]]c                ,    t          | t                    S r   )r,  r   )r  s    r   is_iteratorr    s    c8$$$r   rs  #str | ModuleType | _SupportsVersionc                    t          | t                    r| n| j        }t          j        dd|          }t          d |                    d          D                       S )zSimple version parser; split into a tuple of ints for comparison.

    Arguments:
        version: Version string, or object with one, to parse.
    z(\D?dev.*$) c              3  \   K   | ]'}t          t          j        d d|                    V  (dS )z\Dr  N)intresub).0vs     r   	<genexpr>z parse_version.<locals>.<genexpr>  s8      KKqRVE2q))**KKKKKKr   .)r,  r   r   r  r  r~  split)rs  version_strs     r   rp  rp    s]     (55N''7;NK&[99KKKK4E4Ec4J4JKKKKKKr   
obj_or_clstypecls_or_tupletype[_T]TypeIs[type[_T]]c                    d S r   r   r  r  s     r   isinstance_or_issubclassr    s	     sr   object | typeTypeIs[_T | type[_T]]c                    d S r   r   r  s     r   r  r    	      Cr   tuple[type[_T1], type[_T2]]TypeIs[type[_T1 | _T2]]c                    d S r   r   r  s     r   r  r    s	     "cr   #TypeIs[_T1 | _T2 | type[_T1 | _T2]]c                    d S r   r   r  s     r   r  r    s	     +.#r   &tuple[type[_T1], type[_T2], type[_T3]]TypeIs[type[_T1 | _T2 | _T3]]c                    d S r   r   r  s     r   r  r    s	     %(Cr   /TypeIs[_T1 | _T2 | _T3 | type[_T1 | _T2 | _T3]]c                    d S r   r   r  s     r   r  r    s	     7:cr   tuple[type, ...]TypeIs[Any]c                    d S r   r   r  s     r   r  r    s	     #r   c                    ddl m} t          | |          rt          | |          S t          | |          p$t          | t                    ot	          | |          S )Nr   rr   )narwhals.dtypesrs   r,  r  
issubclass)r  r  rs   s      r   r  r    si    %%%%%%*e$$ 4*l333j,// :t$$MJ)M)Mr   itemsIterable[Any]r   c                    ddl mm t          fd| D                       st          fd| D                       rd S dd | D              }t	          |          )Nr   ro   c              3  8   K   | ]}t          |          V  d S r   r,  )r  itemrp   s     r   r  z$validate_laziness.<locals>.<genexpr>  s-      
9
94:dI&&
9
9
9
9
9
9r   c              3  8   K   | ]}t          |          V  d S r   r  )r  r  rq   s     r   r  z$validate_laziness.<locals>.<genexpr>  s-      ::DJtY''::::::r   zGThe items to concatenate should either all be eager, or all lazy, got: c                ,    g | ]}t          |          S r   )r  )r  r  s     r   
<listcomp>z%validate_laziness.<locals>.<listcomp>  s#    TrTrTrdhUYZ^U_U_TrTrTrr   )r   rp   rq   allr  )r  r2  rp   rq   s     @@r   validate_lazinessr    s    77777777

9
9
9
95
9
9
999 ::::E::::: 	
tTrTrlqTrTrTr
t
tC
C..r   lhsrhs-Series[Any] | DataFrame[Any] | LazyFrame[Any]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	                                     S t          t          |d	d
          |          rt          t          |dd
          |          r ||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	                                     S t          t          |dd
          |          rt          t          |dd
          |          r ||j        j        j	                    ||j        j        j	                   |
                    |j                            |j        j        j        |j        j        j	                                     S t          |          t          |          k    r1d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.

    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)PandasLikeSeriesindexr   r   r   c                6    | j         sd}t          |          d S )Nz'given index doesn't have a unique index)	is_uniquer'  )r  r2  s     r   _validate_indexz*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  ry  r'  )r  r  r  r  r  lhs_anyrhs_anyr2  s           r   maybe_align_indexr    s   < DCCCCC======" " " "
 5#G5#G+T224G  	

WW&8$??AT
U
U	
 	07=>>>07=>>>&&$11(/3G4L4S4YZ 
 
 	

 +T224G  

WW&94@@BR
S
S
 	07=>>>18>???&&$11(/3-4: 
 
 	
 ,d335E  

WW&8$??AT
U
U
 	18>???07=>>>&&%22)04,39 
 
 	
 ,d335E  

WW&94@@BR
S
S
 	18>???18>???&&%22)04-4: 
 
 	
 7||s7||##hs7||hhZ]^eZfZfhhooJr   obj-DataFrame[Any] | LazyFrame[Any] | Series[Any]r   c                    t          d|           }|                                }t          |          st          |          r|j        S dS )a  Get the index of a DataFrame or a Series, if it's pandas-like.

    Arguments:
        obj: Dataframe or 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 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_nativer8   r9   r  )r  obj_any
native_objs      r   maybe_get_indexr  h  sR    4 5#G""$$J
++  /DZ/P/P  4r   )r  column_namesstr | list[str] | Noner  6Series[IntoSeriesT] | list[Series[IntoSeriesT]] | Nonec                  ddl m t          d|           }|                                }||d}t          |          |s|d}t          |          |+t	          |          rfd|D             n |d	          }n|}t          |          r@|                    |j                            |	                    |                              S t          |          r^dd
lm	} |rd}t          |           |||| j        j                  }|                    |j                            |                    S |S )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.

    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   Nz8Only one of `column_names` or `index` should be providedz3Either `column_names` or `index` should be providedc                *    g | ]} |d           S )Tpass_throughr   )r  idxr  s     r   r  z#maybe_set_index.<locals>.<listcomp>  s(    @@@3YYs...@@@r   Tr  )	set_indexz/Cannot set index using column names on a Seriesr[  )narwhals.translater  r!   r'  rz  r8   r  r  r  r  r9   narwhals._pandas_like.utilsr  r   )	r  r  r  df_anyr  r2  keysr  r  s	           @r   maybe_set_indexr    s   X -,,,,,%F!!##JE$5Hoo EMCoo E""5@@@@%@@@@5t444 	 
++ 
%%#001E1Ed1K1KLL
 
 	
 Z(( Y999999 	"CCS//!Y0@
 
 


 %%f&>&K&KJ&W&WXXXMr   c                &   t          d|           }|                                }t          |          rg|                                }t	          ||          r|S |                    |j                            |                    d                              S t          |          rg|                                }t	          ||          r|S |                    |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.

    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  r8   __native_namespace___has_default_indexr  r  r  reset_indexr9   r  )r  r  r  r  s       r   maybe_reset_indexr    s   8 5#G""$$J
++ 
"7799j*:;; 	N&&$11*2H2Hd2H2S2STT
 
 	
 Z(( 
"7799j*:;; 	N&&%22:3I3It3I3T3TUU
 
 	
 Nr   )strict)r^  rb  	iterablesIterable[tuple[Any, ...]]c                 N   t          |           dk     r	t          |  S ddfd}dfd}t          |           }t          t	          |           |                      }t          t          t          |                    t          t          |gR   |                      S )Nr`  Fr   r   c               3     K   d d S )NTr   )first_stoppeds   r   
first_tailzzip_strict.<locals>.first_tail  s       $r   c               3     K   sd} t          |           t          j                  D ]}d} t          |           d S )Nz$zip_strict: first iterable is longerz%zip_strict: first iterable is shorter)r'  r   from_iterable)r2  r   r  rests     r   zip_tailzzip_strict.<locals>.zip_tail&  sU      $ *@C$S//),T22  AAC$S//) r   )r   r   )ry  zipiterr   nextrx  map)r  r  r  iterables_itfirstr  r  s        @@r   
zip_strictr    s    9~~!!I&!M             	??L$|,,jjll;;ED,//00DU*T***HHJJ777r   r  TypeIs[pd.RangeIndex]c                ,    t          | |j                  S r   )r,  
RangeIndex)r  r  s     r   _is_range_indexr  6  s    c+6777r   native_frame_or_seriespd.Series[Any] | pd.DataFramec                    | j         }t          ||          o-|j        dk    o"|j        t	          |          k    o
|j        dk    S )Nr   r]  )r  r  startstopry  step)r  r  r  s      r   r  r  :  sS     #(E/00 	K1	J#e**$	 J!O	r   kwargs
bool | strc           	         | j                                         s| S |                     | j                             |                                 j        |i |                    }t          d|          S )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.

    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   )rX  r:  r  
_compliantr  r  convert_dtypesr!   )r  ru  r  results       r   maybe_convert_dtypesr  F  sw    B ,,.. 
  ##$BCMMOO$BD$SF$S$STT F  &)))r   szr  unitr   int | floatc                ~    |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
    >   br  >   kb	kilobytesi   >   mb	megabytesi   >   gb	gigabytesi   @>   tb	terabytesl        z9`unit` must be one of {'b', 'kb', 'mb', 'gb', 'tb'}, got r'  )r  r  r2  s      r   scale_bytesr"  o  s     ~	"""Dy"""G|"""G|"""G|
P
P
PC
S//r   r  Series[Any]c                   ddl m} | j        j        j        }| j        }d}t          ||          r-t          | j        |j                  r|j        j	        d         }n| j        |j
        k    rd}n| j        |j        k    rd}n|                                 }| j        }|                                r7|                                dk     rt          d|j                  j        dk    }nd|                                rt%          |j        j                  }n6|                                r"dd	lm}  ||j                  o|j        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.

    Examples:
        >>> import narwhals as nw
        >>> import pandas as pd
        >>> import polars as pl
        >>> data = ["x", "y"]
        >>>
        >>> s_pd = nw.from_native(
        ...     pd.Series(data, dtype=pd.CategoricalDtype(ordered=True)), series_only=True
        ... )
        >>> nw.is_ordered_categorical(s_pd)
        True
        >>> s_pl = nw.from_native(
        ...     pl.Series(data, dtype=pl.Categorical()), series_only=True
        ... )
        >>> nw.is_ordered_categorical(s_pl)
        False
    r   )InterchangeSeriesF
is_orderedT)r]      zpl.Categoricalphysical)is_dictionary)narwhals._interchange.seriesr%  r  r   r   r,  dtypeCategoricalr   describe_categoricalr   r  rX  r>  r   r!   orderingr:  r5  catorderedrJ  narwhals._arrow.utilsr)  r  )r  r%  r   r   r  r   rq  r)  s           r   is_ordered_categoricalr2    sq   F ?>>>>>%.5F(IF).// HJf(5 5 H !6|D		$	$	+	+	+!!##$>> 
	H 5 5 7 7' A A *FL99BjPFF  "" 	H&*,--FF__ 	H;;;;;;"]6;//GFK4GFMr   nwn_bytesr   Container[str]prefixc                L    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   )r4  r   r6  )r$   generate_temporary_column_name)r4  r   r6  r2  s       r   generate_unique_tokenr:    s7    	?  cH5555)'7SYZZZZr   c                    d}	 | t          | dz
             x}|vr|S |dz  }|dk    rd| d| }t          |          ?)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.
        prefix: prefix with which the temporary column name should start with.

    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
        >>> temp_name = nw.generate_temporary_column_name(
        ...     n_bytes=8, columns=columns, prefix="foo"
        ... )
        >>> temp_name not in columns and temp_name.startswith("foo")
        True
    r   Tr]  d   zMInternal Error: Narwhals was not able to generate a column name with n_bytes=z and not in )r   r/  )r4  r   r6  countertokenr2  s         r   r9  r9    s    < G
&8	'A+ 6 6888EHHL1S==33 3)03 3  !%%%
&r   framesubsetIterable[str]r  	list[str]c                  |s4t          t          | j                                      |                    S t          |          }t	          || j                  x}r||S )N)	available)rx  setr   intersectioncheck_columns_exist)r?  r@  r  to_droperrors        r   parse_columns_to_droprJ    sc      =C&&33F;;<<<6llG#Gu}EEEEu Nr   sequenceSequence[_T] | AnyTypeIs[Sequence[_T]]c                X    t          | t                    ot          | t                     S r   )r,  r	   r   )rK  s    r   is_sequence_but_not_strrO    s$    h))K*Xs2K2K.KKr   TypeIs[_SliceNone]c                R    t          | t                    o| t          d           k    S r   )r,  slicer  s    r   is_slice_nonerT    s"    c5!!8cU4[[&88r   CTypeIs[SizedMultiIndexSelector[Series[Any] | CompliantSeries[Any]]]c                    t          |           o:t          |           dk    rt          | d                   pt          |           dk    p,t          |           pt	          |           pt          |           S Nr   )rO  ry  is_single_index_selectorr7   r4   is_compliant_series_intrS  s    r   is_sized_multi_index_selectorrZ    s    
 $C(( Yc((Q,C#;CF#C#CWSUV	( !%%		(
 "#&&	( #3''r   -TypeIs[Sequence[_T] | Series[Any] | _1DArray]c                z    t          |           p,t          |           pt          |           pt          |           S r   )rO  r5   r2   is_compliant_seriesrS  s    r   is_sequence_liker^    sF     	 $$ 	$S!!	$c""	$ s##	r   TypeIs[_SliceIndex]c                    t          | t                    oft          | j        t                    pLt          | j        t                    p2t          | j        t          t          f          o| j        d u o| j        d u S r   )r,  rR  r
  r  r  r  NoneTyperS  s    r   is_slice_indexrb  )  st    c5!! 39c"" 	
ch$$	
 sx#x11 !	T!!D r   TypeIs[range]c                ,    t          | t                    S r   )r,  rangerS  s    r   is_rangerf  5  s    c5!!!r   TypeIs[SingleIndexSelector]c                r    t          t          | t                    ot          | t                                S r   )r5  r,  r  rS  s    r   rX  rX  9  s,    
3$$BZT-B-B)BCCCr   TTypeIs[SingleIndexSelector | MultiIndexSelector[Series[Any] | CompliantSeries[Any]]]c                \    t          |           pt          |           pt          |           S r   )rX  rZ  rb  rS  s    r   is_index_selectorrk  =  s4     	!%% 	(--	#r   BTypeIs[SizedMultiBoolSelector[Series[Any] | CompliantSeries[Any]]]c                    t          |           r.t          |           dk    rt          | d         t                    p,t	          |           pt          |           pt          |           S rW  )rO  ry  r,  r5  r6   r3   is_compliant_series_boolrS  s    r   is_boolean_selectorro  G  sh     
!	%	%	U3s88a<+TJs1vt<T<T 	)!#&&	)"3''	) $C((	r   tpTypeIs[list[_T]]c                v    t          t          | t                    o| ot          | d         |                    S rW  )r5  r,  rx  )r  rp  s     r   
is_list_ofrs  R  s2    
3%%H#H*SVR2H2HIIIr   
predicatesCollection[Any]TypeIs[Collection[list[bool]]]c                4    t          d | D                       S )Nc              3  @   K   | ]}t          |t                    V  d S r   )rs  r5  )r  preds     r   r  z3predicates_contains_list_of_bool.<locals>.<genexpr>Z  s,      ==$z$%%======r   any)rt  s    r    predicates_contains_list_of_boolr|  W  s!     ==*======r   c                    t          t          |           o.t          t          |           d           x}ot	          ||                    S r   )r5  rO  r  r  r,  )r  rp  r  s      r   is_sequence_ofr~  ]  sN    $$ 	"499d+++U	"ub!!  r   TypeIs[NestedLiteral]c                F    t          | t          t          t          f          S r   )r,  rx  r~  dictrS  s    r   is_nested_literalr  f  s    cD%.///r   bool | Noner  pass_through_defaultc               P    | ||}n| ||  }n| |nd}t          |          |S )Nz,Cannot pass both `strict` and `pass_through`r!  )r  r  r  r2  s       r   validate_strict_and_pass_thoughr  j  sM     ~,.+		 4!z	L4<oor   r  F)warn_versionrequiredr  r  *Callable[[Callable[P, R]], Callable[P, R]]c                     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**.
    fnCallable[P, R]r   c               D     t                     d fd            }|S )	Nru  P.argskwdsP.kwargsr   r   c                    |                     dd           }|                     dd           }||rd}t          |           |}n5||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.
r8  z0Can't pass both `native_namespace` and `backend`z `backend` must be specified in `z`.)popr$   r'  r   )ru  r  r)  r  r2  r  r  r  s        r   wrapperz=deprecate_native_namespace.<locals>.decorate.<locals>.wrapper  s    hhy$//G#xx(:DAA+ Jj 
 .cLIIII*!-'2EH oo%!)go(oHHHH oo%%DO2t$t$$$r   )ru  r  r  r  r   r   )r   )r  r  r  r  s   ` r   decoratez,deprecate_native_namespace.<locals>.decorate  sC    	r	% 	% 	% 	% 	% 	% 	% 
	%* r   )r  r  r   r  r   )r  r  r  s   `` r   deprecate_native_namespacer  |  s.          2 Or   window_sizemin_samples
int | Nonetuple[int, int]c                   t          | t          d           t          |t          t          d           d           | dk     rd}t          |          |/|dk     rd}t          |          || k    rd}t	          |          n| }| |fS )Nr  
param_namer  r]  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'  r<   )r  r  r2  s      r   _validate_rolling_argumentsr    s     S];;;;S$t**GGGGQ;oo???CS//!$$JC',,, % "##r   headernative_reprc           
        	 t          j                    j        }n2# t          $ r% t	          t          j        dd                    }Y nw xY w|                                                                }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 )NCOLUMNSP   c              3  4   K   | ]}t          |          V  d S r   )ry  )r  lines     r   r  z generate_repr.<locals>.<genexpr>  s(      >>3t99>>>>>>r   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maxry  )r  r  terminal_widthnative_linesmax_native_widthlengthoutputheader_extrastart_extra	end_extrar  diffs               r   generate_reprr    sE   7-//7 7 7 7RYy"55667))++6688L>>>>>>>!~--%s6{{33,uv~,,,F+jc\Q./jjPQ@QT`cdTd@d9ejjjj)cVn)))) 00Q6..14AQ8QUV7VV	  	k 	kDj#-jtjSIHX<X[^_c[d[d<d5ejjjjFF+++++FD	l 	 	419	%	'*dai$(.B'C	 	 	 	 	s    ,A
	A
Collection[str]rD  ColumnNotFoundError | Nonec              x    t          |                               |          x}rt          j        ||          S d S r   )rE  
differencer:   'from_missing_and_available_column_names)r@  rD  missings      r   rG  rG    sF     f++((333w 
"JY
 
 	
 4r   c                H   t          |           t          t          |                     k    rtddlm}  ||           }d |                                D             }d                    d |                                D                       }d| }t          |          d S )Nr   )Counterc                &    i | ]\  }}|d k    ||S )r]  r   r  kr  s      r   
<dictcomp>z1check_column_names_are_unique.<locals>.<dictcomp>  s#    @@@tq!!a%%a%%%r   r  c              3  .   K   | ]\  }}d | d| dV  dS )z
- 'z' z timesNr   r  s      r   r  z0check_column_names_are_unique.<locals>.<genexpr>  s:      LLA,a,,1,,,LLLLLLr   z"Expected unique column names, got:)ry  rE  collectionsr  r  joinr;   )r   r  r=  
duplicatesr2  s        r   check_column_names_are_uniquer    s    
7||s3w<<((((''''''''""@@w}}@@@
ggLL9I9I9K9KLLLLL8388S!!! )(r   	time_unit$TimeUnit | Iterable[TimeUnit] | None	time_zone7str | timezone | Iterable[str | timezone | None] | None%tuple[Set[TimeUnit], Set[str | None]]c                    | h dn&t          | t                    r| hnt          |           }|d hn7t          |t          t          f          rt          |          hnd |D             }||fS )N>   smsnsusc                4    h | ]}|t          |          nd S r   )r   )r  tzs     r   	<setcomp>z1_parse_time_unit_and_time_zone.<locals>.<setcomp>   s&    FFFbc"gggTFFFr   )r,  r   rE  r
   )r  r  
time_units
time_zoness       r   _parse_time_unit_and_time_zoner    s      	  i%%i[[^^   
 i#x11Gc)nnFFIFFF  z!!r   r+  rs   r   ry   r  Set[TimeUnit]r  Set[str | None]c                j    t          | |j                  o| j        |v o| j        |v pd|v o| j        d uS )N*)r,  Datetimer  r  )r+  r   r  r  s       r   %dtype_matches_time_unit_and_time_zoner    sR     	5&/** 	
_
*	
 Oz) Cz!AeoT&Ar   r   c                   | j         S r   r   )r?  s    r   get_column_namesr    s
    =r   namesc                *    fd| j         D             S )Nc                    g | ]}|v|	S r   r   )r  col_namer  s     r   r  z(exclude_column_names.<locals>.<listcomp>  s#    LLLhe6K6KH6K6K6Kr   r  )r?  r  s    `r   exclude_column_namesr    s    LLLLU]LLLLr   EvalNames[Any]c                    d fd}|S )N_framer   r   r   c                   S r   r   )r  r  s    r   r  z$passthrough_column_names.<locals>.fn  s    r   )r  r   r   r   r   )r  r  s   ` r   passthrough_column_namesr    s(          Ir   r   	_SENTINELattrc                <    t          | |t                    t          uS r   )r   r  )r  r  s     r   _hasattr_staticr  $  s    #tY//y@@r   \CompliantDataFrame[CompliantSeriesT, CompliantExprT, NativeDataFrameT, ToNarwhalsT_co] | Any^TypeIs[CompliantDataFrame[CompliantSeriesT, CompliantExprT, NativeDataFrameT, ToNarwhalsT_co]]c                "    t          | d          S )N__narwhals_dataframe__r  rS  s    r   is_compliant_dataframer  (  s     3 8999r   JCompliantLazyFrame[CompliantExprT, NativeLazyFrameT, ToNarwhalsT_co] | AnyLTypeIs[CompliantLazyFrame[CompliantExprT, NativeLazyFrameT, ToNarwhalsT_co]]c                "    t          | d          S )N__narwhals_lazyframe__r  rS  s    r   is_compliant_lazyframer  3  s     3 8999r   'CompliantSeries[NativeSeriesT_co] | Any)TypeIs[CompliantSeries[NativeSeriesT_co]]c                "    t          | d          S )N__narwhals_series__r  rS  s    r   r]  r]  9  s     3 5666r   c                R    t          |           o| j                                        S r   )r]  r+  
is_integerrS  s    r   rY  rY  ?  %     s##>	(<(<(>(>>r   c                R    t          |           o| j                                        S r   )r]  r+  
is_booleanrS  s    r   rn  rn  E  r  r   'TypeIs[NamespaceAccessor[_FullContext]]c                B    t          | d          ot          | d          S )Nr   	_accessorr  rS  s    r   _is_namespace_accessorr
  K  s#     3,,Rk1R1RRr   rq  TypeIs[_EagerAllowedImpl]c               x    | 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  rq  s    r   is_eager_allowedr  U  s2      r   TypeIs[_LazyFrameCollectImpl]c               L    | 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)>+@.BXYYYr   TypeIs[_LazyAllowedImpl]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  e  s>    &  r   TypeIs[SupportsNativeNamespace]c                "    t          | d          S )Nr  r  rS  s    r   has_native_namespacer  r  s    3 6777r   TypeIs[ArrowStreamExportable]c                "    t          | d          S )N__arrow_c_stream__r  rS  s    r   supports_arrow_c_streamr  v  s    3 4555r   left_onright_onsuffixdict[str, str]c                ^      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  0   K   | ]}|v r|  n|V  d S r   r   )r  keyr  r  s     r   r  z(_remap_full_join_keys.<locals>.<genexpr>  sL        8;C7NN3     r   )r  r  )r  r  r  right_keys_suffixeds   ` ` r   _remap_full_join_keysr$  z  sM         ?G   H122333r   datar\   contextpa.Tablec                   t          d          rE|j        j                            d          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.
    r  )r&  zB'pyarrow>=14.0.0' is required for `from_arrow` for object of type r  )
r   r   r   r-  r   
_dataframe
from_arrowr   r  ModuleNotFoundError)r%  r&  r  r2  s       r   _into_arrow_tabler,    sw      A'44Y??I}''b'99@@
mObcgOhOh
m
m
mC
c
"
""r   r  c                   | S )a  Visual-only marker for unstable functionality.

    Arguments:
        fn: Function to decorate.

    Returns:
        Decorated function (unchanged).

    Examples:
        >>> @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   )r  s    r   unstabler.    s	    & Ir   formatc                <     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 V  	d S r   r   )r  xr/  s     r   r  z#_is_naive_format.<locals>.<genexpr>  s'      ::11;::::::r   )z%sz%zZrz  )r/  s   `r   _is_naive_formatr4    s,     ::::(9:::::::r   c                  X    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
dS )!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:
        >>> 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
    Nalias
str | Noner   r   c                   || _         d S r   )_alias)r   r7  s     r   __init__znot_implemented.__init__  s     #(r   r   c                P    dt          |           j         d| j         d| j         S )N<z>: r  )r  r   _name_owner_namer   s    r   __repr__znot_implemented.__repr__  s.    J4::&JJ4+;JJdjJJJr   r   r  namec                :    |j         | _        | j        p|| _        d S r   )r   r>  r:  r?  r   r   rA  s      r   __set_name__znot_implemented.__set_name__  s     %+-


r   r   _T | Literal['raise'] | Nonetype[_T] | Noner   c                   || S t          |dt          j                  }|t          j        urt          |          }n| j        }t          | j        |           d S )Nr   )r  r   r"  reprr>  _raise_not_implemented_errorr?  )r   r   r   rX  whos        r   r   znot_implemented.__get__  sd      K !+<n>TUU!777~&&CC"C$TZ555tr   ru  r  c                ,    |                      d          S )Nraise)r   )r   ru  r  s      r   __call__znot_implemented.__call__  s     ||G$$$r   messager@   rB   c               F     |             } 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  rN  r  s      r   r&   znot_implemented.deprecated  s'     cee"z'""3'''r   r   )r7  r8  r   r   rV  )r   r  rA  r   r   r   )r   rE  r   rF  r   r   )ru  r   r  r   r   r   )rN  r@   r   rB   )r   r   r   r   r;  r@  rD  r   rM  rW  r&   r   r   r   r6  r6    s        ! !F( ( ( ( (
K K K K. . . . PT    $% % % %
 	( 	( 	( [	( 	( 	(r   r6  whatrJ  NotImplementedErrorc               0    | 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)rQ  )rP  rJ  r2  s      r   rI  rI    s:     	S 	SC 	S 	S 	S 
 c
"
""r   c                      e Zd ZU dZded<   ded<   ded<   	 eddd            Zedd            ZddZ	d dZ
d!dZd"dZdS )#requiresa  Method decorator for raising under certain constraints.

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

    Examples:
        >>> 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   _hint_wrapped_namer  hintminimumr   rB   c               L    |                      |           }||_        ||_        |S )zMethod decorator for raising below a minimum `_backend_version`.

        Arguments:
            minimum: Minimum backend version.
            hint: Optional suggested alternative.
        )__new__rU  rV  )r  rY  rX  r  s       r   rU  zrequires.backend_versionD  s)     kk#"	
r   rU  c               @    d                     d | D                       S )Nr  c              3     K   | ]}| V  d S r   r   )r  ds     r   r  z,requires._unparse_version.<locals>.<genexpr>S  s$      8811888888r   )r  rT  s    r   _unparse_versionzrequires._unparse_versionQ  s#    xx88888888r   r6  rI   r   c               >    d| j         vr| d| j          | _         d S d S Nr  )rW  )r   r6  s     r   _qualify_accessor_namezrequires._qualify_accessor_nameU  s7    d((($*!A!AT-?!A!AD )(r   r   r   tuple[tuple[int, ...], str]c                   t          |          r"|                     |j                   |j        }n|}|j        t          |j                  fS r   )r
  rb  r	  r   r   r   r   )r   r   r   s      r   _unwrap_contextzrequires._unwrap_contextZ  sQ    !(++ 	!''(:;;; *II I)3y/H+I+IIIr   c          	        |                      |          \  }}|| j        k    rd S |                     | j                  }|                     |          }d| j         d| d| d|d	}| j        r| d| j         }t          |          )N`z` is only available in 'z>=z', found version r  
)re  rU  r_  rW  rV  rQ  )r   r   rs  r)  rY  foundr2  s          r   _ensure_versionzrequires._ensure_versionb  s    //99d'''F''(9::%%g..m$$mmgmmmmchmmm: 	)((DJ((C!#&&&r   r  _Method[_IntoContextT, P, R]c               Z     j          _        t                    d
 fd	            }|S )Nr   r   ru  r  r  r  r   r   c                F                         |             | g|R i |S r   )rj  )r   ru  r  r  r   s      r   r  z"requires.__call__.<locals>.wrapperr  s7      ***2h.......r   )r   r   ru  r  r  r  r   r   )r   rW  r   )r   r  r  s   `` r   rM  zrequires.__call__m  sJ      [	r	/ 	/ 	/ 	/ 	/ 	/ 
	/
 r   N)r  )rX  r   rY  r   r   rB   )rU  r   r   r   )r6  rI   r   r   )r   r   r   rc  )r   r   r   r   )r  rk  r   rk  )r   r   r   r   r   rW  rU  staticmethodr_  rb  re  rj  rM  r   r   r   rT  rT  &  s          * "!!!JJJ
 
 
 
 
 [
 9 9 9 \9B B B B
J J J J	' 	' 	' 	'     r   rT  	str_slicer   "tuple[int | None, int | None, Any]c                    | j         |                    | j                   nd }| j        |                    | j                  dz   nd }| j        }|||fS )Nr]  )r
  r  r  r  )ro  r   r
  r  r  s        r   convert_str_slice_to_int_slicerr  {  s\     /8o.IGMM)/***tE090J7==((1,,PTD>D4r   	tp_parentCallable[P, R1]<Callable[[_Constructor[_T, P, R2]], _Constructor[_T, P, R2]]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
    
init_child_Constructor[_T, P, R2]r   c                   | j         dk    r8t          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   r  )rw  r2  rs  s     r   r  zinherit_doc.<locals>.decorate  s    *,,DOOT1R1R,!'	!2!2J%% % %!.% % % % 	
 nnr   )rw  rx  r   rx  r   )rs  r  s   ` r   rz  rz    s(    	 	 	 	 	 	 Or   object | type[Any]c                   t          | t                    r| nt          |           }|j        dk    r|j        nd}| d|j                             d          S )Nbuiltinsr  r  )r,  r  r   r   lstrip)r  rp  modules      r   r  r    s[    3%%	4499B mz99R]]rF$$r{$$++C000r   r  valid_types	type[Any]r  c                 t          | |          sd                    d |D                       }d|dt          |           }|rnd}t          |           }t	          |          dk    rt          |            d}| | d}d	t	          |          z  d
t	          |          z  z   }| d| | d| }t          |          dS )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:
        >>> 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.DataFrame', got: 'polars.dataframe.frame.DataFrame'
            df=polars.dataframe.frame.DataFrame(...)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    z | c              3  4   K   | ]}t          |          V  d S r   )r  )r  rp  s     r   r  zensure_type.<locals>.<genexpr>  s+      LL"1"55LLLLLLr   z	Expected z, got: z    (   z(...)=r  ^rh  N)r,  r  r  rH  ry  r  )	r  r  r  tp_namesr2  left_padr  assign	underlines	            r   r  r    s    @ c;'' ::LLLLLLLI(II-@-E-EII 	7Hs))C3xx"}},S11888 /*///Fs6{{*sSXX~>I66F6C66966Cnn r   c                  *    e Zd ZdZddZddZdd
ZdS )_DeferredIterablezLStore a callable producing an iterable to defer collection until we need it.	into_iterCallable[[], Iterable[_T]]r   r   c                   || _         d S r   
_into_iter)r   r  s     r   r;  z_DeferredIterable.__init__  s    6?r   Iterator[_T]c              #  >   K   |                                  E d {V  d S r   r  r   s    r   __iter__z_DeferredIterable.__iter__  s.      ??$$$$$$$$$$$r   tuple[_T, ...]c                v    |                                  }t          |t                    r|nt          |          S r   )r  r,  r~  )r   its     r   to_tuplez_DeferredIterable.to_tuple  s0    __E**9rrb		9r   N)r  r  r   r   )r   r  )r   r  )r   r   r   r   r;  r  r  r   r   r   r  r    sZ        VV@ @ @ @% % % %: : : : : :r   r  @   nestedattrgetter[Any]c                Z    |rd                     | g|R           n| }t          |          S ra  )r  r   )r  r  rA  s      r   deep_attrgetterr    s3    (.8388TOFOO$$$DDdr   name_1c                .     t          |g|R  |           S )z+Perform a nested attribute lookup on `obj`.)r  )r  r  r  s      r   deep_getattrr    s"    +?6+F+++C000r   c                      e Zd ZdS )	CompliantN)r   r   r   r   r   r   r  r    s        3r   r  c                  *    e Zd ZdZedd            ZdS )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
    r   Compliant[NativeT_co]c                    d S r   r   r   s    r   r  zNarwhals._compliant  s    363r   N)r   r  )r   r   r   r   r   r  r   r   r   r  r    s2         0 666 X666r   r  c                     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dAd            ZedBd            ZedCd"            ZedDd%            ZedEd(            ZedFd+            ZedGd.            ZedHd1            ZedId4            ZedJd7            ZdKd9Zd:S )L_ImplementationzDescriptor for matching an opaque `Implementation` on a generic class.

    Based on [pyright comment](https://github.com/microsoft/pyright/issues/3071#issuecomment-1043978070)
    r   r  rA  r   r   r   c                    || _         d S r   )r   rC  s      r   rD  z_Implementation.__set_name__  s    !r   r   Narwhals[NativePolars]r   rk   c                    d S r   r   r   s      r   r   z_Implementation.__get__      TWTWr   Narwhals[NativePandas]ri   c                    d S r   r   r   s      r   r   z_Implementation.__get__  r  r   Narwhals[NativeModin]rh   c                    d S r   r   r   s      r   r   z_Implementation.__get__      RURUr   Narwhals[NativeCuDF]ra   c                    d S r   r   r   s      r   r   z_Implementation.__get__      PSPSr   Narwhals[NativePandasLike]rj   c                    d S r   r   r   s      r   r   z_Implementation.__get__   s	     #r   Narwhals[NativeArrow]r`   c                    d S r   r   r   s      r   r   z_Implementation.__get__$  r  r   3Narwhals[NativePolars | NativeArrow | NativePandas]&_PolarsImpl | _PandasImpl | _ArrowImplc                    d S r   r   r   s      r   r   z_Implementation.__get__&  s	     25r   Narwhals[NativeDuckDB]rc   c                    d S r   r   r   s      r   r   z_Implementation.__get__*  r  r   Narwhals[NativeSQLFrame]rn   c                    d S r   r   r   s      r   r   z_Implementation.__get__,  s	     r   Narwhals[NativeDask]rb   c                    d S r   r   r   s      r   r   z_Implementation.__get__0  r  r   Narwhals[NativeIbis]re   c                    d S r   r   r   s      r   r   z_Implementation.__get__2  r  r   .Narwhals[NativePySpark | NativePySparkConnect]"_PySparkImpl | _PySparkConnectImplc                    d S r   r   r   s      r   r   z_Implementation.__get__4  s	     .1Sr   type[Narwhals[Any]]rB   c                    d S r   r   r   s      r   r   z_Implementation.__get__9  s    KN3r   DataFrame[Any] | Series[Any]rd   c                    d S r   r   r   s      r   r   z_Implementation.__get__;  r  r   LazyFrame[Any]rf   c                    d S r   r   r   s      r   r   z_Implementation.__get__?  s    QTQTr   Narwhals[Any] | Nonec                "    || n|j         j        S r   )r  r   r   s      r   r   z_Implementation.__get__A  s    'ttX-@-PPr   N)r   r  rA  r   r   r   )r   r  r   r   r   rk   )r   r  r   r   r   ri   )r   r  r   r   r   rh   )r   r  r   r   r   ra   )r   r  r   r   r   rj   )r   r  r   r   r   r`   )r   r  r   r   r   r  )r   r  r   r   r   rc   )r   r  r   r   r   rn   )r   r  r   r   r   rb   )r   r  r   r   r   re   )r   r  r   r   r   r  )r   r   r   r  r   rB   )r   r  r   r   r   rd   )r   r  r   r   r   rf   )r   r  r   r   r   r   )r   r   r   r   rD  r"   r   r   r   r   r  r    s        
" " " " WWW XWWWW XWUUU XUSSS XS   X UUU XU5 5 5 X5 WWW XW   X SSS XSSSS XS1 1 1 X1 NNN XN      X  TTT XTQ Q Q Q Q Qr   r  tblpa.Table | pa.RecordBatchReaderc                l    dd l }t          | |j                  r|j                            |           S | S rW  )r  r,  RecordBatchReaderTablefrom_batches)r  pas     r   to_pyarrow_tabler  E  s>    #r+,, *x$$S)))Jr   win32sourcerz   c               h    t          | t                    r| nt          t          |                     S r   )r,  r   r   r  s    r   normalize_pathr  O  s)    #FC00Gvvc$v,,6G6GGr   c               D    t          |                                           S r   )r   as_posixr  s    r   r  r  X  s    F||$$&&&r   r  bool | Iterable[bool]n_matchSequence[bool]c                V    t          | t                    r| f|z  nt          |           S )zEnsure the given bool or sequence of bools is the correct length.

    Stolen from https://github.com/pola-rs/polars/blob/b8bfb07a4a37a8d449d6d1841e345817431142df/py-polars/polars/_utils/various.py#L580-L594
    )r,  r5  r~  )r  r  s     r   extend_boolr  \  s+     ",E4!8!8JE8geEllJr   c                      e Zd ZdZddZdS )
_NoDefault
NO_DEFAULTr   r   c                    dS )Nz<no_default>r   r   s    r   r@  z_NoDefault.__repr__l  s    ~r   NrV  )r   r   r   
no_defaultr@  r   r   r   r  r  g  s/         J     r   r  )rX  r   r   r5  )r3  r   r   r>   )rX  r   r   r   )ru  r   r   rv  )r|  r   r   r   )r|  r  r   r5  )r  r  r   r  )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  r  r   r  )r  r  r  r  r   r  )r  r   r  r  r   r  )r  r   r  r   r   r5  )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   r5  )r  r   ru  r5  r  r  r   r   )r  r  r  r   r   r  )r  r#  r   r5  )r3  )r4  r  r   r5  r6  r   r   r   )r?  r   r@  rA  r  r5  r   rB  )rK  rL  r   rM  )r  r   r   rP  )r  r   r   rU  )r  rL  r   r[  )r  r   r   r_  )r  r   r   rc  )r  r   r   rg  )r  r   r   ri  )r  r   r   rl  )r  r   rp  r  r   rq  )rt  ru  r   rv  )r  r   rp  r  r   rM  )r  r   r   r  )r  r  r  r  r  r5  r   r5  )r  r   r  r5  r   r  )r  r  r  r  r   r  )r  r   r  r   r   r   )r@  r  rD  r  r   r  )r   r  r   r   )r  r  r  r  r   r  )
r+  rs   r   ry   r  r  r  r  r   r5  )r?  r   r   r   )r?  r   r  r5  r   r   )r  r   r   r  )r  r   r  r   r   r5  )r  r  r   r  )r  r  r   r  )r  r  r   r  )r  r   r   r  )rq  r   r   r  )rq  r   r   r  )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   r   r   )r/  r   r   r5  )rP  r   rJ  r   r   rQ  )ro  r   r   r   r   rp  )rs  rt  r   ru  )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  rz   r   r   )r  r  r  r  r   r  (-  
__future__r   r  r  syscollections.abcr   r   r   r   r   r	   datetimer
   enumr   r   	functoolsr   r   r   r   importlib.utilr   inspectr   r   	itertoolsr   operatorr   pathlibr   secretsr   typingr   r   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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   narwhals.exceptionsr:   r;   r<   r=   typesr>   r  r  r	  r  r  r  typing_extensionsr?   r@   rA   rB   rC   rD   narwhals._compliantrE   rF   rG   !narwhals._compliant.any_namespacerH   narwhals._compliant.typingrI   rJ   rK   rL   r   rN   narwhals._nativerO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   narwhals._translater[   r\   r]   narwhals._typingr^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   r   rp   rq   r  rs   r   ru   narwhals.typingrv   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  r  rh  r0  r1  rU  r{  r  rz  r  rp  r  r  r  r  r  r  r  r  version_infor  r  r  r"  r2  r:  r9  rJ  rO  rT  rZ  r^  rb  rf  rX  rk  ro  rs  r|  r~  r  r  r  r  r  rG  r  r  r  r  r  r  objectr  r  r  r  r]  rY  rn  r
  r  r  r  r  r  r$  r,  r.  r4  r6  rI  rT  rr  rz  r  r  r  r  r  r  r  r  r  platformr  r  r  r  r  ra  r   r   r   <module>r     s*   " " " " " " " 				 				 



 X X X X X X X X X X X X X X X X               6 6 6 6 6 6 6 6 6 6 6 6 $ $ $ $ $ $ * * * * * * * *                                                  & % % % % % : : : : : : < < < < < < < <                                         * [ Z Z Z Z Z Z Z Z Z j0######                      WVVVVVVVVVCCCCCC            .-----                            ZYYYYYYYYY                                     & 87777777%%%%%%&&&&&&                                       * %(''''WininfSk&Q R  N '%..C
'%..C
'%..C
'%3
4
4
4C	#AA	B	B    8   R R R R Rx R R R0 0 0 0 0 0 0 0
 WT]]W\T222
4888J J J J J|<<<A A A A A< < < < <    HZ(       x.       H   - - - - -X - - -
J J J J JH J J J
    +^X       (*?   	4 	4 	4 	4 	42H 	4 	4 	4I I I I Id I I IXM% M% M% M% M%Z M% M% M%`5 5 5 5 9)EF"F:6Z:     ).M"$9	@      D 2& & & &    <Q Q Q Q   S S S S*% % % %L L L L 
   

 
      
 
 
" " " 
"
 
. . . 
.
 
( ( ( 
(
 
: : : 
:
 
   

      Y Y Y Yx   F ,0S EI	S S S S S Sl, , , ,^  %8T***JJJJJ
7""WS...

	8 	8 	8 	8<8 8 8 8	 	 	 	&* &* &* &*R   *? ? ? ?F :>[ [ [ [ [ :>)& )& )& )& )&X   L L L L9 9 9 9      	 	 	 	" " " "D D D D      J J J J
> > > >   0 0 0 0   & & & & & & &R$ $ $ $0   <   " " " "" " " "*
 
 
 
   M M M M    688	    A A A A: : : :: : : :7 7 7 7? ? ? ?? ? ? ?S S S S   Z Z Z Z

 
 
 
8 8 8 86 6 6 64 4 4 4,# # # #    ,; ; ; ;$R( R( R( R( R( R( R( R(j# # # #R R R R R R R Rj      61 1 1 1 IK + + + + + +\: : : : : : : : 2   
1 1 1 1
    *4hz6J  
7 7 7 7 7x
# 7 7 7:3Q 3Q 3Q 3Q 3Q 3Q 3Q 3Ql    <7H H H H H' ' ' 'K K K K        "
 4::r   