
    hh                   (   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"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/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZE d dlFmGZGmHZHmIZI e"rd dlmJZJ d dlKmLZL d dlMZNd dlOZPd dlQZRd dlSmTZTmUZUmVZVmWZWmXZXmYZY d dlZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z` d dlambZb d dlcmdZdmeZemfZfmgZg d dlhmiZi d dljmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZv d dlwmxZxmyZymzZz d dl{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZ 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'd(#          Z eVd)          Z e)d*          Z e)d+          Z e)d,          Z G d- d.e(          Z G d/ d0e(          Z G d1 d2e(          Z e)d3          Z e)d4d56          Z e)d7d56          Zd8Zd ed9<    e)d:e#          Zd;Zd ed<<   d=Zd ed><    G d? d@e(e                   Z G dA dBe(e                   Z G dC dDe(          Z G dE dFe(          Z G dG dHe(          Z G dI dJeee(          Z G dK dLeee(          Z G dM dNee(          Z G dO dPe          Z G dQ dRe.          Zej        dSej        dTej        dUej        dVej        dWej        dWej        dXej        dYej        dZej        d[ej        d\iZd]ed^<   ej        d_ej        d`ej        daej        dbiZdcedd<   	  edef          dpdk            Zedqdn            ZӐdrdrZԐdsdtZՐdtdwZ֐dud{Zאdvd~Ze,dwd            Ze,dxd            Ze,dyd            Ze,dzd            Ze,d{d            Ze,d|d            Ze,d}d            Zِd~dZِddZڐddZېddZ	 dddddZݐddZe"r eed5          Zn"d dlZej        dk    r eed5          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ZdddddZddZddZddZdd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d-Zdd/Zdd1Zdd6Zdd;Zdd=Zdd?Z G d@ dA          ZddEZ G dF dG          ZddKZddOZddQZddRddVZ G dW dXe&e                   Z edYf          dd\            Zdd^Z G d_ d`ee         ee(e                   Z G da dbe(e                   Z G dc dd          ZddgZddjZ ddo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)	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_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)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SingleIndexSelectorSizedMultiIndexSelectorSizeUnitSupportsNativeNamespaceTimeUnit_1DArray_SliceIndex
_SliceName
_SliceNoner@   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__     F/var/www/histauto/venv/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.series8  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__c  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-   PYARROWr/   PYSPARKr,   POLARSr'   DASKr(   DUCKDBr)   IBISr0   SQLFRAMEr.   PYSPARK_CONNECTgetUNKNOWN)r  r  mappings      r   from_native_namespacez$Implementation.from_native_namespacef  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  r6  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  rD  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  r?  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+  r6  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_ibis8  r?  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_sqlframeE  s     ~...r   r   c                     t          |           S )zReturns backend version.backend_versionr   s    r   r   zImplementation._backend_versionR  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   r3  r   )$r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r   r  classmethodr"  r&  r+  r2  r5  r8  r:  r<  r>  rA  rC  rF  rH  rJ  rL  rN  rP  r   r   r   r   r   r   G  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   )   rV     )r         )   
   )   )rW     )r         )i  rX  )rV  rV  )   )rW     r   z(Mapping[Implementation, tuple[int, ...]]MIN_VERSIONSzdask.dataframezmodin.pandaszpyspark.sqlzpyspark.sql.connectzMapping[Implementation, str]r.     )maxsizer1  r   r   r;   c                $    ddl m}  ||           S )Nr   )import_module)	importlibrf  )r1  rf  s     r   r/  r/  n  s$    ''''''=%%%r   implementationr   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   r.  r  r  r/  rP  sqlframe._versionr   rC  rF  r  rJ  r  parse_versionrb  r%  )rh  implr1  r  r  into_versionr  r  versionmin_versionr0  s              r   rS  rS  x  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 )NrV  r   )listlen_is_iterable)rp  s    r   flattenrv    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*  rs  tuple)rw  s    r   tupleifyrz    s$    cD%=)) vJr   Any | Iterable[Any]r3  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)rw  ru   pdplr0  s        r   ru  ru    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   rn  #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  ry  split)rn  version_strs     r   rk  rk    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  r0  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  r0  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  rt  r%  )r  r  r  r  r  lhs_anyrhs_anyr0  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_nativer5   r6   r  )r  obj_any
native_objs      r   maybe_get_indexr  c  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 Series)rh  )narwhals.translater  r    r%  ru  r5   r  r  r  r  r6   narwhals._pandas_like.utilsr  r   )	r  r  r  df_anyr  r0  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  r5   __native_namespace___has_default_indexr  r  r  reset_indexr6   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)rW  r[  	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 )NrY  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)r0  r   r  rests     r   zip_tailzzip_strict.<locals>.zip_tail!  sU      $ *@C$S//),T22  AAC$S//) r   )r   r   )rt  zipiterr   nextrs  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  1  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   rV  )r  r  startstoprt  step)r  r  r  s      r   r  r  5  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   )rh  r8  r  
_compliantr  r  convert_dtypesr    )r  rp  r  results       r   maybe_convert_dtypesr  A  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  r0  s      r   scale_bytesr  j  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 = 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)rV      zpl.Categoricalphysical)is_dictionary)narwhals._interchange.seriesr   r  r   r   r*  dtypeCategoricalr   describe_categoricalr   r  rh  r<  r   r    orderingr8  r3  catorderedrH  narwhals._arrow.utilsr$  r  )r   r   r   r   r  r   rl  r$  s           r   is_ordered_categoricalr-    sq   N ?>>>>>%.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   )r/  r   r1  )r#   generate_temporary_column_name)r/  r   r1  r0  s       r   generate_unique_tokenr5    s7    	?  cH5555)'7SYZZZZr   c                    d}	 | t          | dz
             }||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   TrV  d   zMInternal Error: Narwhals was not able to generate a column name with n_bytes=z and not in )r   r-  )r/  r   r1  countertokenr0  s         r   r4  r4    s    < G&39Wq[1133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)rs  setr   intersectioncheck_columns_exist)r:  r;  r  to_droperrors        r   parse_columns_to_droprE    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   )rF  s    r   is_sequence_but_not_strrJ    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_nonerO    s"    c5!!8cU4[[&88r   CTypeIs[SizedMultiIndexSelector[Series[Any] | CompliantSeries[Any]]]c                    t          |           o@t          |           dk    rt          | d         t                    pt          |           dk    p,t	          |           pt          |           pt          |           S Nr   )rJ  rt  r*  r  r4   r2   is_compliant_series_intrN  s    r   is_sized_multi_index_selectorrT    s    
 $C(( Pc((Q,::c!fc#:#:NCA	( !%%		(
 "#&&	( #3''r   -TypeIs[Sequence[_T] | Series[Any] | _1DArray]c                z    t          |           p,t          |           pt          |           pt          |           S r   )rJ  r3   r1   is_compliant_seriesrN  s    r   is_sequence_likerX    sF     	 $$ 	$S!!	$c""	$ s##	r   TypeIs[_SliceIndex]c                    t          | t                    o_t          | j        t                    pEt          | j        t                    p+t          | j        t                    o| j        d u o| j        d u S r   )r*  rM  r  r  r  r  rN  s    r   is_slice_indexr[  )  sj    c5!! 39c"" 	Rch$$	Rsx%%P#)t*;PD@Pr   TypeIs[range]c                ,    t          | t                    S r   )r*  rangerN  s    r   is_ranger_  1  s    c5!!!r   TypeIs[SingleIndexSelector]c                r    t          t          | t                    ot          | t                                S r   )r3  r*  r  rN  s    r   is_single_index_selectorrb  5  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   )rb  rT  r[  rN  s    r   is_index_selectorre  9  s4     	!%% 	(--	#r   tpTypeIs[list[_T]]c                v    t          t          | t                    o| ot          | d         |                    S rR  )r3  r*  rs  )r  rf  s     r   
is_list_ofri  C  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   )ri  r3  )r  preds     r   r  z3predicates_contains_list_of_bool.<locals>.<genexpr>K  s,      ==$z$%%======r   any)rj  s    r    predicates_contains_list_of_boolrr  H  s!     ==*======r   c                    t          t          |           o.t          t          |           d           x}ot	          ||                    S r   )r3  rJ  r  r  r*  )r  rf  r  s      r   is_sequence_ofrt  N  sN    $$ 	"499d+++U	"ub!!  r   bool | Noner  pass_through_defaultc               P    | ||}n| ||  }n| |nd}t          |          |S )Nz,Cannot pass both `strict` and `pass_through`r  )r  r  rv  r0  s       r   validate_strict_and_pass_thoughrx  W  sM     ~,.+		 4!z	L4<oor   r  F)warn_versionrequiredry  rz  *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 )	Nrp  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.
r3  z0Can't pass both `native_namespace` and `backend`z `backend` must be specified in `z`.)popr#   r%  r   )rp  r  r'  r  r0  r}  rz  ry  s        r   wrapperz=deprecate_native_namespace.<locals>.decorate.<locals>.wrapperw  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   )rp  r  r  r  r   r   )r   )r}  r  rz  ry  s   ` r   decoratez,deprecate_native_namespace.<locals>.decoratev  sC    	r	% 	% 	% 	% 	% 	% 	% 
	%* r   )r}  r~  r   r~  r   )ry  rz  r  s   `` r   deprecate_native_namespacer  i  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  rV  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%  r9   )r  r  r0  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   )rt  )r  lines     r   r  z generate_repr.<locals>.<genexpr>  s(      >>3t99>>>>>>r   rY  u   ┌u   ─u   ┐
| z|
-u   └u   ┘'   uu   ───────────────────────────────────────u   ┐
|u/   |
| Use `.to_native` to see native output |
└)
osget_terminal_sizer   OSErrorr  getenv
expandtabs
splitlinesmaxrt  )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]r?  ColumnNotFoundError | Nonec              x    t          |                               |          x}rt          j        ||          S d S r   )r@  
differencer7   'from_missing_and_available_column_names)r;  r?  missings      r   rB  rB    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 )rV  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:)rt  r@  collectionsr  r  joinr8   )r   r  r8  
duplicatesr0  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   r@  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  rN  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  rN  s    r   is_compliant_lazyframer     s     3 8999r   'CompliantSeries[NativeSeriesT_co] | Any)TypeIs[CompliantSeries[NativeSeriesT_co]]c                "    t          | d          S )N__narwhals_series__r  rN  s    r   rW  rW  &  s     3 5666r   c                R    t          |           o| j                                        S r   )rW  r&  
is_integerrN  s    r   rS  rS  ,  s%     s##>	(<(<(>(>>r   ECompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co] | AnyGTypeIs[CompliantExpr[CompliantFrameT, CompliantSeriesOrNativeExprT_co]]c                "    t          | d          S )N__narwhals_expr__)hasattrrN  s    r   is_compliant_exprr  2  s     3+,,,r   'TypeIs[NamespaceAccessor[_FullContext]]c                B    t          | d          ot          | d          S )Nr   	_accessorr  rN  s    r   _is_namespace_accessorr  8  s#     3,,Rk1R1RRr   rl  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  rl  s    r   is_eager_allowedr  B  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  M  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	  R  s>    &  r   TypeIs[SupportsNativeNamespace]c                "    t          | d          S )Nr  r  rN  s    r   has_native_namespacer  _  s    3 6777r   TypeIs[ArrowStreamExportable]c                "    t          | d          S )N__arrow_c_stream__r  rN  s    r   supports_arrow_c_streamr  c  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>w  sL        8;C7NN3     r   )dictr  )r  r  r  right_keys_suffixeds   ` ` r   _remap_full_join_keysr  g  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  r0  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:
        >>> 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   )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Zrp  )r%  s   `r   _is_naive_formatr*    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:
        >>> 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
    Nalias
str | Noner   r   c                   || _         d S r   )_alias)r   r-  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   r4  r0  r5  r   r   r7  s      r   __set_name__znot_implemented.__set_name__  s     %+-


r   r   _T | Literal['raise'] | Nonetype[_T] | Noner   c               d    || S t          |d| j                  }t          | j        |           d S )Nr   )r  r4  _raise_not_implemented_errorr5  )r   r   r   whos       r   r   znot_implemented.__get__  s?      K h 143CDD$TZ555tr   rp  r  c                ,    |                      d          S )Nraise)r   )r   rp  r  s      r   __call__znot_implemented.__call__  s     ||G$$$r   messager=   r?   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  rC  r  s      r   r%   znot_implemented.deprecated  s'     cee"z'""3'''r   r   )r-  r.  r   r   rT  )r   r  r7  r   r   r   )r   r;  r   r<  r   r   )rp  r   r  r   r   r   )rC  r=   r   r?   )r   r   r   r   r1  r6  r:  r   rB  rU  r%   r   r   r   r,  r,    s        " "H( ( ( ( (
K K K K. . . . PT    % % % %
 	( 	( 	( [	( 	( 	(r   r,  whatr?  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)rF  )rE  r?  r0  s      r   r>  r>    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:
        >>> 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   _hint_wrapped_namer  hintminimumr   r?   c               L    |                      |           }||_        ||_        |S )zMethod decorator for raising below a minimum `_backend_version`.

        Arguments:
            minimum: Minimum backend version.
            hint: Optional suggested alternative.
        )__new__rJ  rK  )r  rN  rM  r  s       r   rS  zrequires.backend_version0  s)     kk#"	
r   rS  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$      8811888888r   )r  rR  s    r   _unparse_versionzrequires._unparse_version=  s#    xx88888888r   r1  rI   r   c               >    d| j         vr| d| j          | _         d S d S Nr  )rL  )r   r1  s     r   _qualify_accessor_namezrequires._qualify_accessor_nameA  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  rW  r  r   r   r   r   )r   r   r   s      r   _unwrap_contextzrequires._unwrap_contextF  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  
)rZ  rJ  rT  rL  rK  rF  )r   r   rn  r'  rN  foundr0  s          r   _ensure_versionzrequires._ensure_versionN  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   rp  r  r  r  r   r   c                F                         |             | g|R i |S r   )r_  )r   rp  r  r}  r   s      r   r  z"requires.__call__.<locals>.wrapper^  s7      ***2h.......r   )r   r   rp  r  r  r  r   r   )r   rL  r   )r   r}  r  s   `` r   rB  zrequires.__call__Y  sJ      [	r	/ 	/ 	/ 	/ 	/ 	/ 
	/
 r   N)r  )rM  r   rN  r   r   r?   )rS  r   r   r   )r1  rI   r   r   )r   r   r   rX  )r   r   r   r   )r}  r`  r   r`  )r   r   r   r   r   rU  rS  staticmethodrT  rW  rZ  r_  rB  r   r   r   rI  rI    s          , "!!!JJJ
 
 
 
 
 [
 9 9 9 \9B B B B
J J J J	' 	' 	' 	'     r   rI  	str_slicer   "tuple[int | None, int | None, Any]c                    | j         |                    | j                   nd }| j        |                    | j                  dz   nd }| j        }|||fS )NrV  )r  r  r  r  )rd  r   r  r  r  s        r   convert_str_slice_to_int_slicerg  g  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          |          )Nr1  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  )rl  r0  rh  s     r   r  zinherit_doc.<locals>.decorate}  s    *,,DOOT1R1R,!'	!2!2J%% % %!.% % % % 	
 nnr   )rl  rm  r   rm  r   )rh  r  s   ` r   ro  ro  p  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  rf  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:
        >>> 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  4   K   | ]}t          |          V  d S r   )r~  )r  rf  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  ^r]  N)r*  r  r~  reprrt  r  )	r  r  ru  tp_namesr0  left_padr  assign	underlines	            r   r  r    s    B 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   r1  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*  ry  )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   r1  r  r  r   r   r   r  r    sZ        VV@ @ @ @% % % %: : : : : :r   r  @   nestedattrgetter[Any]c                Z    |rd                     | g|R           n| }t          |          S rV  )r  r   )r  r  r7  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   rv  r7  r   r   r   c                    || _         d S r   )r   r9  s      r   r:  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__  r  r   Narwhals[NativeIbis]re   c                    d S r   r   r   s      r   r   z_Implementation.__get__  r  r   .Narwhals[NativePySpark | NativePySparkConnect]"_PySparkImpl | _PySparkConnectImplc                    d S r   r   r   s      r   r   z_Implementation.__get__!  s	     .1Sr   type[Narwhals[Any]]r?   c                    d S r   r   r   s      r   r   z_Implementation.__get__&  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__.  s    'ttX-@-PPr   N)r   rv  r7  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   r?   )r   r  r   r   r   rd   )r   r  r   r   r   rf   )r   r  r   r   r   r   )r   r   r   r   r:  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 rR  )r  r*  RecordBatchReaderTablefrom_batches)r  pas     r   to_pyarrow_tabler  2  s>    #r+,, *x$$S)))Jr   sourcerz   c               l    t          | t                    r| S ddlm} t           ||                     S )Nr   )Path)r*  r   pathlibr  )r  r  s     r   normalize_pathr  :  sA    &# ttF||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*  r3  ry  )r  r  s     r   extend_boolr  B  s+     ",E4!8!8JE8geEllJr   )r1  r   r   r;   )rh  r   r   r   )rp  r   r   rq  )rw  r   r   r   )rw  r{  r   r3  )r  r  r   r  )rn  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   r3  )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   r3  )r  r   rp  r3  r  r	  r   r   )r  r  r  r   r   r  )r   r  r   r3  )r.  )r/  r  r   r0  r1  r   r   r   )r:  r   r;  r<  r  r3  r   r=  )rF  rG  r   rH  )r  r   r   rK  )r  r   r   rP  )r  rG  r   rU  )r  r   r   rY  )r  r   r   r\  )r  r   r   r`  )r  r   r   rc  )r  r   rf  r  r   rg  )rj  rk  r   rl  )r  r   rf  r  r   rH  )r  ru  r  ru  rv  r3  r   r3  )ry  r   rz  r3  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&  rs   r   ry   r  r  r  r  r   r3  )r:  r   r   r   )r:  r   r  r0  r   r   )r  r   r   r  )r  r   r  r   r   r3  )r  r  r   r  )r  r  r   r  )r  r  r   r  )r  r  r   r  )r  r   r   r  )rl  r   r   r   )rl  r   r   r  )rl  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   r3  )rE  r   r?  r   r   rF  )rd  r   r   r   r   re  )rh  ri  r   rj  )r  rp  r   r   )r  r   ru  rv  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   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.   r/   r0   r1   r2   r3   r4   r5   r6   narwhals.exceptionsr7   r8   r9   r:   typesr;   r  r  r  r  r  r  typing_extensionsr<   r=   r>   r?   r@   rA   narwhals._compliantrB   rC   rD   rE   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  rb  r.  r/  rS  rv  rz  ru  r  rk  r  r  r  r  r  r  r  r  version_infor  r  r  r  r-  r5  r4  rE  rJ  rO  rT  rX  r[  r_  rb  re  ri  rr  rt  rx  r  r  r  rB  r  r  r  r  r  r  objectr  r  r  r  rW  rS  r  r  r  r  r	  r  r  r  r"  r$  r*  r,  r>  rI  rg  ro  r~  r  r  r  r  r  r  r  r  r  r  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 o0######                                     D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%b 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   *C C C CN :>[ [ [ [ [ :>*& *& *& *& *&Z   L L L L9 9 9 9         " " " "D D D D   J J J J
> > > >      & & & & & & &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,# # # #    .; ; ; ;$O( O( O( O( O( O( O( O(d# # # #S S S S S S S Sl      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      K K K K K Kr   