
    -Pha                      U 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mZmZmZ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$m%Z%m&Z& d dl'm(Z(m)Z) d d	l*m+Z+m,Z,m-Z- d d
l.m/Z/ d dl0m1Z1 d dl2m3Z3 ermd dl4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:Z;d dl<Z=d dl>Z?d dl@mAZAmBZBmCZCmDZD d dlEmFZFmGZG d dlHmIZImJZJ d dlKmLZLmMZM d dlNmOZOmPZPmQZQmRZRmSZSmTZTmUZVmWZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^  eBd          Z_ edd          Z` edd          Za edd          Zb ed          ZcdZUdedd <   d!ZWdedd"<    G d# d$e
e`                   Ze G d% d&eeeb                   Zf G d' d(eeea                   ZgdS ))    )annotations)abstractmethod)chain)TYPE_CHECKINGAnyCallableGenericIterableIteratorLiteralNoReturnSequenceTypeVaroverload)warn)ExprKindall_exprs_are_scalar_like!check_expressions_preserve_lengthis_scalar_like)Implementationfind_stacklevelflattengenerate_repris_compliant_dataframeis_compliant_lazyframeis_index_selector
is_list_ofis_sequence_likeis_slice_noneissue_deprecation_warningparse_versionsupports_arrow_c_stream)
get_polarsis_numpy_array)InvalidIntoExprErrorLengthChangingExprErrorOrderDependentExprError)SchemaSeries	to_native)BytesIO)Path)
ModuleTypeN)Concatenate	ParamSpecSelf	TypeAlias)CompliantDataFrameCompliantLazyFrame)CompliantExprAnyEagerNamespaceAny)GroupByLazyGroupBy)AsofJoinStrategyIntoDataFrameIntoExpr	IntoFrameJoinStrategyLazyUniqueKeepStrategyMultiColSelectorMultiIndexSelectorPivotAggSingleColSelectorSingleIndexSelectorSizeUnitUniqueKeepStrategy_2DArrayPS_FrameTr=   )boundFrameT
DataFrameTr;   Rz_MultiColSelector[Series[Any]]r3   r@   z _MultiIndexSelector[Series[Any]]rA   c            	      T   e Zd ZU ded<   ded<   dddZdedZdfdZdgdZedhd            Z	e
did            ZdidZdjdZdkdld"Zdmd%Ze
dnd'            Zdod(Zdod)Zdpd,Zdqd/Zdqd0Zdrd5Zdsd9Zd:d:d;dtdBZ	 	 dudCdCdEdFdvdNZdwdxdQZdCdCdCdCdCdCdRdEdSdydYZdzd\Zd{d_Zd{d`Zd|dcZdCS )}	BaseFramer   _compliant_frame&Literal['full', 'lazy', 'interchange']_levelreturnr/   c                4    | j                                         S N)rP   __native_namespace__selfs    R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/narwhals/dataframe.pyrV   zBaseFrame.__native_namespace__`   s    $99;;;    c                4    | j                                         S rU   )rP   __narwhals_namespace__rW   s    rY   r\   z BaseFrame.__narwhals_namespace__c   s    $;;===rZ   dfr2   c                :    |                      || j                  S )Nlevel)	__class__rR   )rX   r]   s     rY   _with_compliantzBaseFrame._with_compliantf   s    ~~b~444rZ   exprsIntoExpr | Iterable[IntoExpr]named_exprsr<   -tuple[list[CompliantExprAny], list[ExprKind]]c                   g }g }t          |          D ]U}|                     |          }|                    |           |                    t          j        |d                     V|                                D ]k\  }}|                     |                              |          }|                    |           |                    t          j        |d                     l||fS )zjProcess `args` and `kwargs`, extracting underlying objects as we go, interpreting strings as column names.F)
str_as_lit)r   _extract_compliantappendr   from_into_expritemsalias)rX   rc   re   	out_exprs	out_kindsexprcompliant_exprrm   s           rY   _flatten_and_extractzBaseFrame._flatten_and_extractj   s     		ENN 	N 	ND!44T::N^,,,X4TeLLLMMMM&,,.. 	N 	NKE4!44T::@@GGN^,,,X4TeLLLMMMM)##rZ   argc                    t           rU   NotImplementedError)rX   rs   s     rY   ri   zBaseFrame._extract_compliantz   s    !!rZ   r(   c                X    t          | j        j                                                  S rU   )r(   rP   schemarl   rW   s    rY   rx   zBaseFrame.schema~   s"    d+288::;;;rZ   c                l    t          | j                                                  }t          |          S rU   )dictrP   collect_schemar(   )rX   native_schemas     rY   r{   zBaseFrame.collect_schema   s,    T2AACCDDm$$$rZ   function"Callable[Concatenate[Self, PS], R]argsPS.argskwargs	PS.kwargsrM   c                     || g|R i |S rU    )rX   r}   r   r   s       rY   pipezBaseFrame.pipe   s$     x.t...v...rZ   indexnamestrc                \    |                      | j                            |                    S rU   )rb   rP   with_row_indexrX   r   s     rY   r   zBaseFrame.with_row_index   s'    ##D$9$H$H$N$NOOOrZ   subsetstr | list[str] | Nonec                    t          |t                    r|gn|}|                     | j                            |                    S )Nr   )
isinstancer   rb   rP   
drop_nulls)rX   r   s     rY   r   zBaseFrame.drop_nulls   sD    '44@&&##D$9$D$DF$D$S$STTTrZ   	list[str]c                    | j         j        S rU   )rP   columnsrW   s    rY   r   zBaseFrame.columns   s    $,,rZ   c                     | j         |i |\  }}d t          ||          D             }|                      | j        j        |           S )Nc                `    g | ]+\  }}t          |          r|                    |          n|,S r   r   	broadcast.0rq   kinds      rY   
<listcomp>z*BaseFrame.with_columns.<locals>.<listcomp>   L     
 
 
$ /=T.B.BVN$$T***
 
 
rZ   )rr   ziprb   rP   with_columns)rX   rc   re   compliant_exprskindss        rY   r   zBaseFrame.with_columns   sl     ";!:E!Q[!Q!Q
 
(+OU(C(C
 
 
 ##$FD$9$F$XYYYrZ   c                   t          t          |                    }|rpt          d |D                       rW|sU	 |                      | j        j        |           S # t          $ r%}| j                            |          x}r|| d }~ww xY w | j        |i |\  }}|r.t          |i |r"|                      | j        j
        |           S d t          ||          D             }|                      | j        j        |           S )Nc              3  @   K   | ]}t          |t                    V  d S rU   r   r   )r   xs     rY   	<genexpr>z#BaseFrame.select.<locals>.<genexpr>   s,      EEQjC00EEEEEErZ   c                `    g | ]+\  }}t          |          r|                    |          n|,S r   r   r   s      rY   r   z$BaseFrame.select.<locals>.<listcomp>   r   rZ   )tupler   allrb   rP   simple_select	Exception_check_columns_existrr   r   	aggregater   select)rX   rc   re   
flat_exprseerrorr   r   s           rY   r   zBaseFrame.select   sf    75>>**
 
	#EE*EEEEE 
	k 
	++7D)7D       1FFzRRR5 'Q&	
 ";!:J!V+!V!V 	[8*TTT 	[''(G(=(G(YZZZ
 
(+OU(C(C
 
 
 ##$@D$9$@/$RSSSs   !A 
B' BBmappingdict[str, str]c                \    |                      | j                            |                    S rU   )rb   rP   rename)rX   r   s     rY   r   zBaseFrame.rename   s'    ##D$9$@$@$I$IJJJrZ   nintc                \    |                      | j                            |                    S rU   )rb   rP   headrX   r   s     rY   r   zBaseFrame.head   '    ##D$9$>$>q$A$ABBBrZ   c                \    |                      | j                            |                    S rU   )rb   rP   tailr   s     rY   r   zBaseFrame.tail   r   rZ   r   Iterable[str]strictboolc               `    |                      | j                            ||                    S )Nr   )rb   rP   drop)rX   r   r   s      rY   r   zBaseFrame.drop   s,    ##D$9$>$>wv$>$V$VWWWrZ   
predicates*IntoExpr | Iterable[IntoExpr] | list[bool]constraintsc                  	 t          |          dk    r$t          |d         t                    r	|d         }n{ddlm t          |          }t          |ddi |                                 	 | j        | \  }}	fd|	                                D             } 	j
        t          ||           }|                     | j                            |                    S )N   r   colfunction_namefilterc              3  b   K   | ])\  }} |          |k                                   V  *d S rU   )_to_compliant_expr)r   r   vr   plxs      rY   r   z#BaseFrame.filter.<locals>.<genexpr>   sU       % %D! Ta33C88% % % % % %rZ   )lenr   r   narwhals.functionsr   r   r   r\   rr   rl   all_horizontalr   rb   rP   r   )
rX   r   r   	predicateflat_predicatescompliant_predicates_kindscompliant_constraintsr   r   s
           @@rY   r   zBaseFrame.filter   s    z??aJz!}d$C$C"1II......%j11O-WhWWW--//C+D4+Do+V( &% % % % %*0022% % %! +*+-BCCI ##D$9$@$@$K$KLLLrZ   F
descending
nulls_lastbystr | Iterable[str]more_byr   bool | Sequence[bool]r   c                   t          g t          |g          |          }|                      | j        j        |||d          S )Nr   )r   rb   rP   sort)rX   r   r   r   r   s        rY   r   zBaseFrame.sort   sV     /wt}}/w/00##&D!&zjYYY
 
 	
rZ   Ninner_rightleft_onright_onsuffixotheronhowr>   r   r   r   c          	        t          |t                    r|gn|}t          |t                    r|gn|}t          |t                    r|gn|}|dx}vrd| d| d}t          |          |dk    r|||d}t          |          |dk    r|||d| d}t          |          |dk    r|||d	| d}t          |          ||x}}t          |t                    rFt          |t                    r1t          |          t          |          k    rd
}t          |          |                     | j                            | 	                    |          ||||                    S )N)r   leftfullcrossantisemiz2Only the following join strategies are supported: 	; found ''.r   z>Can not pass `left_on`, `right_on` or `on` keys for cross joinzGEither (`left_on` and `right_on`) or `on` keys should be specified for .zBIf `on` is specified, `left_on` and `right_on` should be None for z3`left_on` and `right_on` must have the same length.)r   r   r   r   )
r   r   rv   
ValueErrorlistr   rb   rP   joinri   )	rX   r   r   r   r   r   r   _supported_joinsmsgs	            rY   r   zBaseFrame.join   s     C((0bTTb)'377D7))W!+Hc!:!:HH:: RR
 
 jGWiibeiiiC%c***'>>8#72>RCS//!'>>rzw(BRb\_bbbCS//!'>>N 3x7K]WZ]]]CS//!>!##Ghw%% 	"*Xt*D*D 	"LLCMM))GCS//!##!&&''..! '  
 
 	
rZ   r   offsetc                `    |                      | j                            ||                    S )Nr   r   )rb   rP   gather_every)rX   r   r   s      rY   r   zBaseFrame.gather_every   s3    ##!..6.BB
 
 	
rZ   backwardr   r   r   by_leftby_rightr   strategyr   
str | Noner   r   r  r:   c                  d}
||
vrd|
 d| d}t          |          |||d}t          |          |||d}t          |          |||||d}t          |          |||d}t          |          ||x}}||x}}t          |t                    r|g}t          |t                    r|g}t          |t                    rFt          |t                    r1t          |          t          |          k    rd	}t          |          |                     | j                            | 	                    |          ||||||	
                    S )N)r   forwardnearestz-Only the following strategies are supported: r   r   zCEither (`left_on` and `right_on`) or `on` keys should be specified.z>If `on` is specified, `left_on` and `right_on` should be None.zGCan not specify only `by_left` or `by_right`, you need to specify both.z>If `by` is specified, `by_left` and `by_right` should be None.z3`by_left` and `by_right` must have the same length.)r   r   r   r   r  r   )
rv   r   r   r   r   r   rb   rP   	join_asofri   )rX   r   r   r   r   r   r   r   r  r   _supported_strategiesr   s               rY   r  zBaseFrame.join_asof%  s    !C000nBWnnbjnnnC%c***JW_0@WCS//!N!48LRCS//!J_!5#(8 Z  S//!N!48LRCS//!>!##Gh>!##Ghgs## 	 iGh$$ 	" zHw%% 	"*Xt*D*D 	"LLCMM))GCS//!##!++''..!!! ,  

 

 
	
rZ   variable_name
value_namec                   t          |t                    r|gn|}t          |t                    r|gn|}|                     | j                            ||||                    S )Nr   r   r  r	  )r   r   rb   rP   unpivot)rX   r   r   r  r	  s        rY   r  zBaseFrame.unpivotd  st      C((0bTTb%eS11<u##!))U-J *  
 
 	
rZ   objectr   c                $    d}t          |          )NzDataFrame.__neq__ and LazyFrame.__neq__ are not implemented, please use expressions instead.

Hint: instead of
    df != 0
you may want to use
    df.select(nw.all() != 0)ru   rX   r   r   s      rY   __neq__zBaseFrame.__neq__u      + 	 "#&&&rZ   c                $    d}t          |          )NzDataFrame.__eq__ and LazyFrame.__eq__ are not implemented, please use expressions instead.

Hint: instead of
    df == 0
you may want to use
    df.select(nw.all() == 0)ru   r  s      rY   __eq__zBaseFrame.__eq__  r  rZ   str | Sequence[str]more_columnsc                    t          |t                    r|g|ng ||}|                     | j                            |                    S )Nr   )r   r   rb   rP   explode)rX   r   r  
to_explodes       rY   r  zBaseFrame.explode  s_     '3''+W$|$$*7*\* 	 ##D$9$A$A*$A$U$UVVVrZ   )rS   r/   )rS   r   )r]   r   rS   r2   )rc   rd   re   r<   rS   rf   rs   r   rS   r   rS   r(   r}   r~   r   r   r   r   rS   rM   r   r   r   rS   r2   r   r   rS   r2   rS   r   rc   rd   re   r<   rS   r2   r   r   rS   r2   r   r   rS   r2   )r   r   r   r   rS   r2   r   r   r   r   rS   r2   
r   r   r   r   r   r   r   r   rS   r2   Nr   r   r2   r   r   r   r>   r   r   r   r   r   r   rS   r2   r   r   r   r   r   rS   r2   r   r2   r   r  r   r  r   r  r   r   r   r   r   r   r  r:   r   r   rS   r2   
r   r   r   r   r  r   r	  r   rS   r2   )r   r  rS   r   r   r  r  r   rS   r2   ) __name__
__module____qualname____annotations__rV   r\   rb   rr   r   ri   propertyrx   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r   rZ   rY   rO   rO   \   s        2222< < < <> > > >5 5 5 5$ $ $ $  " " " ^" < < < X<% % % %
/ / / /P P P P PU U U U - - - X-Z Z Z ZT T T T0K K K KC C C CC C C CX X X XM M M M2 -2 

 

 

 

 

 

 &*#	5
 +/+/5
 5
 5
 5
 5
 5
n
 
 
 
 
 ##*.+/%)%/=
 =
 =
 =
 =
 =
~
 
 
 
"	' 	' 	' 	'	' 	' 	' 	'W W W W W WrZ   rO   c            	      .    e Zd ZdZddZedd            Zedd	            ZddZedd            Z	ddZ
dddZddZdddZ	 ddd"Zdd$Zdd&Zdd(Zeddd*            Zedd,            Zddd/Zdd0Zdd1Zedd3            Zdd6Zddd;Zedd>            Zedd@            ZeddC            ZddFZd dIZedJdKddO            ZeddR            ZeddT            ZdUdKddVZddYZd fdaZdd fddZdd fdeZed	 fdg            Z d	 fdhZ!ed
 fdj            Z"edkdlddo            Z#eddq            Z#edds            Z#dkdlddtZ#ddvZ$edJdwddz            Z%edJdwdd|            Z%edJdwdd~            Z%dkddddZ%d fdZ&d fdZ'd fdZ(dd fdZ)dd fdZ*dUdd fdZ+	 dddkdddZ,d fdZ-edJddd            Z.edd            Z.dkdddZ.dkdkdd fdZ/	 	 dddddd fdZ0dddddddddd fdZ1d dZ2d!dZ3d dZ4d"dZ5dd#dƄZ6d"dǄZ7d$d% fdʄZ8dddddkdd̜d&dӄZ9d'dՄZ:	 dddkdd֜d(dۄZ;	 dddddޜd) fdZ<d* fdZ= xZ>S (+  	DataFramea{  Narwhals DataFrame, backed by a native eager dataframe.

    Warning:
        This class is not meant to be instantiated directly - instead:

        - If the native object is a eager dataframe from one of the supported
            backend (e.g. pandas.DataFrame, polars.DataFrame, pyarrow.Table),
            you can use [`narwhals.from_native`][]:
            ```py
            narwhals.from_native(native_dataframe)
            narwhals.from_native(native_dataframe, eager_only=True)
            ```

        - If the object is a dictionary of column names and generic sequences mapping
            (e.g. `dict[str, list]`), you can create a DataFrame via
            [`narwhals.from_dict`][]:
            ```py
            narwhals.from_dict(
                data={"a": [1, 2, 3]},
                backend=narwhals.get_native_namespace(another_object),
            )
            ```
    rs   r   rS   c                   ddl m} ddlm} |                                 }t          |t                    r|j        S t          ||          r|j        	                                S t          ||          r'|
                    |                                           S t          |t                    r|                    |          S t                      @dt          t          |                    v r"dt          |           d}t          |          t!          |          r.|j                            ||          	                                S t'          j        t          |                    )Nr   Exprr)   polarsExpected Narwhals object, got: [.

Perhaps you:
- Forgot a `nw.from_native` somewhere?
- Used `pl.col` instead of `nw.col`?)context)narwhals.exprr6  narwhals.seriesr*   r\   r   rO   rP   _compliant_series_to_exprr   r   r   r#   type	TypeErrorr$   _series
from_numpyr%   from_invalid_type)rX   rs   r6  r*   r   r   s         rY   ri   zDataFrame._extract_compliant  sl   &&&&&&******!%!<!<!>!>c9%% 	(''c6"" 	4(11333c4   	I))$*E*E*G*GHHHc3 	 773<<<<#CS		NN(B(B7$s)) 7 7 7  C.. # 	G;))#s);;DDFFF"4T#YY???rZ   type[Series[Any]]c                    t           S rU   r)   rW   s    rY   rA  zDataFrame._series  s    rZ   type[LazyFrame[Any]]c                    t           S rU   )	LazyFramerW   s    rY   
_lazyframezDataFrame._lazyframe      rZ   r]   r`   rQ   Nonec                   || _         |  t          |          r|                                | _        d S dt	          |           }t          |          )NzCExpected an object which implements `__narwhals_dataframe__`, got: )rR   r   __narwhals_dataframe__rP   r?  AssertionErrorrX   r]   r`   r   s       rY   __init__zDataFrame.__init__  s^    >CM!"%% 	&$&$=$=$?$?D!!!bX\]_X`X`bbC %%%rZ   r   c                    | j         j        S )a  Return implementation of native frame.

        This can be useful when you need to use special-casing for features outside of
        Narwhals' scope - for example, when dealing with pandas' Period Dtype.

        Returns:
            Implementation.

        Examples:
            >>> import narwhals as nw
            >>> import pandas as pd
            >>> df_native = pd.DataFrame({"a": [1, 2, 3]})
            >>> df = nw.from_native(df_native)
            >>> df.implementation
            <Implementation.PANDAS: 'pandas'>
            >>> df.implementation.is_pandas()
            True
            >>> df.implementation.is_pandas_like()
            True
            >>> df.implementation.is_polars()
            False
        rP   _implementationrW   s    rY   implementationzDataFrame.implementation  s    0 $44rZ   r   c                4    | j                                         S rU   )rP   __len__rW   s    rY   rV  zDataFrame.__len__  s    $,,...rZ   Ndtypecopybool | NonerG   c                :    | j                             ||          S )NrX  )rP   	__array__)rX   rW  rX  s      rY   r\  zDataFrame.__array__  s    $..u4.@@@rZ   r   c                j    t          d|                                                                           S )NzNarwhals DataFramer   r,   __repr__rW   s    rY   r_  zDataFrame.__repr__  )    14>>3C3C3L3L3N3NOOOrZ   requested_schemaobject | Noner  c                   | j         j        }t          |          r|                    |          S 	 ddl}n4# t
          $ r'}dt          |           }t          |          |d}~ww xY wt          |          dk     r"dt          |           }t          |          d|                                 }|                    |          S )ah  Export a DataFrame via the Arrow PyCapsule Interface.

        - if the underlying dataframe implements the interface, it'll return that
        - else, it'll call `to_arrow` and then defer to PyArrow's implementation

        See [PyCapsule Interface](https://arrow.apache.org/docs/dev/format/CDataInterface/PyCapsuleInterface.html)
        for more.
        )ra  r   NzT'pyarrow>=14.0.0' is required for `DataFrame.__arrow_c_stream__` for object of type )   r   )	rP   _native_framer"   __arrow_c_stream__pyarrowModuleNotFoundErrorr?  r!   to_arrow)rX   ra  native_framepaexcr   pa_tables          rY   rf  zDataFrame.__arrow_c_stream__  s     ,:"<00 	V22DT2UUU	4     " 	4 	4 	4}imnzi{i{}}C%c**3	4 w&&}imnzi{i{}}C%c**4==??**<L*MMMs   8 
A)"A$$A)backend(ModuleType | Implementation | str | NoneLazyFrame[Any]c                   |dnt          j        |          }t           j        t           j        t           j        f}|||vrd| d| }t          |          |                     | j                            |          d          S )u
  Restrict available API methods to lazy-only ones.

        If `backend` is specified, then a conversion between different backends
        might be triggered.

        If a library does not support lazy execution and `backend` is not specified,
        then this is will only restrict the API to lazy-only operations. This is useful
        if you want to ensure that you write dataframe-agnostic code which all has
        the possibility of running entirely lazily.

        Arguments:
            backend: Which lazy backend collect to. This will be the underlying
                backend for the resulting Narwhals LazyFrame. If not specified, and the
                given library does not support lazy execution, then this will restrict
                the API to lazy-only operations.

                `backend` can be specified in various ways

                - As `Implementation.<BACKEND>` with `BACKEND` being `DASK`, `DUCKDB`
                    or `POLARS`.
                - As a string: `"dask"`, `"duckdb"` or `"polars"`
                - Directly as a module `dask.dataframe`, `duckdb` or `polars`.

        Returns:
            A new LazyFrame.

        Examples:
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pl.DataFrame({"a": [1, 2], "b": [4, 6]})
            >>> df = nw.from_native(df_native)

            If we call `df.lazy`, we get a `narwhals.LazyFrame` backed by a Polars
            LazyFrame.

            >>> df.lazy()  # doctest: +SKIP
            ┌─────────────────────────────┐
            |     Narwhals LazyFrame      |
            |-----------------------------|
            |<LazyFrame at 0x7F52B9937230>|
            └─────────────────────────────┘

            We can also pass DuckDB as the backend, and then we'll get a
            `narwhals.LazyFrame` backed by a `duckdb.DuckDBPyRelation`.

            >>> df.lazy(backend=nw.Implementation.DUCKDB)
            ┌──────────────────┐
            |Narwhals LazyFrame|
            |------------------|
            |┌───────┬───────┐ |
            |│   a   │   b   │ |
            |│ int64 │ int64 │ |
            |├───────┼───────┤ |
            |│     1 │     4 │ |
            |│     2 │     6 │ |
            |└───────┴───────┘ |
            └──────────────────┘
        Nz(Not-supported backend.

Expected one of z or `None`, got )rn  lazyr_   )	r   from_backendDASKDUCKDBPOLARSr   rI  rP   rr  )rX   rn  lazy_backendsupported_lazy_backendsr   s        rY   rr  zDataFrame.lazy  s    |  'ttN4OPW4X4X!!#

 #<S(S(S_'>_ _P\_ _  S//!!&&|&<<F  
 
 	
rZ   rL   c                    | j         j        S )ac  Convert Narwhals DataFrame to native one.

        Returns:
            Object of class that user started with.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame(
            ...     {"foo": [1, 2, 3], "bar": [6.0, 7.0, 8.0], "ham": ["a", "b", "c"]}
            ... )

            Calling `to_native` on a Narwhals DataFrame returns the native object:

            >>> nw.from_native(df_native).to_native()
               foo  bar ham
            0    1  6.0   a
            1    2  7.0   b
            2    3  8.0   c
        )rP   re  rW   s    rY   r,   zDataFrame.to_nativea  s    * $22rZ   pd.DataFramec                4    | j                                         S )a  Convert this DataFrame to a pandas DataFrame.

        Returns:
            A pandas DataFrame.

        Examples:
            >>> import polars as pl
            >>> import narwhals as nw
            >>> df_native = pl.DataFrame(
            ...     {"foo": [1, 2, 3], "bar": [6.0, 7.0, 8.0], "ham": ["a", "b", "c"]}
            ... )
            >>> df = nw.from_native(df_native)
            >>> df.to_pandas()
               foo  bar ham
            0    1  6.0   a
            1    2  7.0   b
            2    3  8.0   c
        )rP   	to_pandasrW   s    rY   r|  zDataFrame.to_pandasx  s    & $..000rZ   pl.DataFramec                4    | j                                         S )u  Convert this DataFrame to a polars DataFrame.

        Returns:
            A polars DataFrame.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, 2], "bar": [6.0, 7.0]})
            >>> df = nw.from_native(df_native)
            >>> df.to_polars()
            shape: (2, 2)
            ┌─────┬─────┐
            │ foo ┆ bar │
            │ --- ┆ --- │
            │ i64 ┆ f64 │
            ╞═════╪═════╡
            │ 1   ┆ 6.0 │
            │ 2   ┆ 7.0 │
            └─────┴─────┘
        )rP   	to_polarsrW   s    rY   r  zDataFrame.to_polars  s    , $..000rZ   filec                    d S rU   r   rX   r  s     rY   	write_csvzDataFrame.write_csv  s    363rZ   str | Path | BytesIOc                    d S rU   r   r  s     rY   r  zDataFrame.write_csv  s    =@SrZ   str | Path | BytesIO | Noner  c                6    | j                             |          S )a  Write dataframe to comma-separated values (CSV) file.

        Arguments:
            file: String, path object or file-like object to which the dataframe will be
                written. If None, the resulting csv format is returned as a string.

        Returns:
            String or None.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame(
            ...     {"foo": [1, 2, 3], "bar": [6.0, 7.0, 8.0], "ham": ["a", "b", "c"]}
            ... )
            >>> df = nw.from_native(df_native)
            >>> df.write_csv()
            'foo,bar,ham\n1,6.0,a\n2,7.0,b\n3,8.0,c\n'

            If we had passed a file name to `write_csv`, it would have been
            written to that file.
        )rP   r  r  s     rY   r  zDataFrame.write_csv  s    . $..t444rZ   c                :    | j                             |           dS )a  Write dataframe to parquet file.

        Arguments:
            file: String, path object or file-like object to which the dataframe will be
                written.

        Returns:
            None.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, 2], "bar": [6.0, 7.0]})
            >>> df = nw.from_native(df_native)
            >>> df.write_parquet("out.parquet")  # doctest:+SKIP
        N)rP   write_parquetr  s     rY   r  zDataFrame.write_parquet  s!    " 	++D11111rZ   c                :    | j                             dd          S )a  Convert this DataFrame to a NumPy ndarray.

        Returns:
            A NumPy ndarray array.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"foo": [1, 2], "bar": [6.5, 7.0]})
            >>> df = nw.from_native(df_native)
            >>> df.to_numpy()
            array([[1. , 6.5],
                   [2. , 7. ]])
        Nr[  )rP   to_numpyrW   s    rY   r  zDataFrame.to_numpy  s      $--d->>>rZ   tuple[int, int]c                    | j         j        S )a_  Get the shape of the DataFrame.

        Returns:
            The shape of the dataframe as a tuple.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"foo": [1, 2]})
            >>> df = nw.from_native(df_native)
            >>> df.shape
            (2, 1)
        )rP   shaperW   s    rY   r  zDataFrame.shape  s     $**rZ   r   Series[Any]c                j    |                      | j                            |          | j                  S )al  Get a single column by name.

        Arguments:
            name: The column name as a string.

        Returns:
            A Narwhals Series, backed by a native series.

        Notes:
            Although `name` is typed as `str`, pandas does allow non-string column
            names, and they will work when passed to this function if the
            `narwhals.DataFrame` is backed by a pandas dataframe with non-string
            columns. This function can only be used to extract a column by name, so
            there is no risk of ambiguity.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"a": [1, 2]})
            >>> df = nw.from_native(df_native)
            >>> df.get_column("a").to_native()
            0    1
            1    2
            Name: a, dtype: int64
        r_   )rA  rP   
get_columnrR   r   s     rY   r  zDataFrame.get_column  s-    4 ||D1<<TBB$+|VVVrZ   bunitrE   int | floatc                8    | j                             |          S )ak  Return an estimation of the total (heap) allocated size of the `DataFrame`.

        Estimated size is given in the specified unit (bytes by default).

        Arguments:
            unit: 'b', 'kb', 'mb', 'gb', 'tb', 'bytes', 'kilobytes', 'megabytes',
                'gigabytes', or 'terabytes'.

        Returns:
            Integer or Float.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, 2], "bar": [6.0, 7.0]})
            >>> df = nw.from_native(df_native)
            >>> df.estimated_size()
            32
        )r  )rP   estimated_size)rX   r  s     rY   r  zDataFrame.estimated_size  s    ( $333>>>rZ   item-tuple[SingleIndexSelector, SingleColSelector]c                    d S rU   r   rX   r  s     rY   __getitem__zDataFrame.__getitem__-  s    WZWZrZ   2str | tuple[MultiIndexSelector, SingleColSelector]c                    d S rU   r   r  s     rY   r  zDataFrame.__getitem__0  s	     crZ   SingleIndexSelector | MultiIndexSelector | MultiColSelector | tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, MultiColSelector]r2   c                    d S rU   r   r  s     rY   r  zDataFrame.__getitem__5  s	     srZ     SingleIndexSelector | SingleColSelector | MultiColSelector | MultiIndexSelector | tuple[SingleIndexSelector, SingleColSelector] | tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, SingleColSelector] | tuple[MultiIndexSelector, MultiColSelector]Series[Any] | Self | Anyc                   ddl m} dt          |           d}t          |t                    r~t          |          dk    rd}t          |          |rt          |d                   rdn|d         }t          |          dk     st          |d                   rdn|d         }||| S nSt          |          r|}d}n?t          |          st          |t          t          f          rd}|}nt          |          t          |t                    rt          |          | j        }t          |t          t          f          rpt          |t                    r|                     ||          S t          |t                    r|n| j        |         }|                     |          }	||	|         n|	S t          ||          r|j        }t          ||          r|j        }||                     |dd|f                   S ||                     ||ddf                   S |                     |||f                   S )	a	  Extract column or slice of DataFrame.

        Arguments:
            item: How to slice dataframe. What happens depends on what is passed. It's easiest
                to explain by example. Suppose we have a Dataframe `df`

                - `df['a']` extracts column `'a'` and returns a `Series`.
                - `df[0:2]` extracts the first two rows and returns a `DataFrame`.
                - `df[0:2, 'a']` extracts the first two rows from column `'a'` and returns
                    a `Series`.
                - `df[0:2, 0]` extracts the first two rows from the first column and returns
                    a `Series`.
                - `df[[0, 1], [0, 1, 2]]` extracts the first two rows and the first three columns
                    and returns a `DataFrame`
                - `df[:, [0, 1, 2]]` extracts all rows from the first three columns and returns a
                  `DataFrame`.
                - `df[:, ['a', 'c']]` extracts all rows and columns `'a'` and `'c'` and returns a
                  `DataFrame`.
                - `df[['a', 'c']]` extracts all rows and columns `'a'` and `'c'` and returns a
                  `DataFrame`.
                - `df[0: 2, ['a', 'c']]` extracts the first two rows and columns `'a'` and `'c'` and
                    returns a `DataFrame`
                - `df[:, 0: 2]` extracts all rows from the first two columns and returns a `DataFrame`
                - `df[:, 'a': 'c']` extracts all rows and all columns positioned between `'a'` and `'c'`
                    _inclusive_ and returns a `DataFrame`. For example, if the columns are
                    `'a', 'd', 'c', 'b'`, then that would extract columns `'a'`, `'d'`, and `'c'`.

        Returns:
            A Narwhals Series, backed by a native series.

        Notes:
            - Integers are always interpreted as positions
            - Strings are always interpreted as column names.

            In contrast with Polars, pandas allows non-string column names.
            If you don't know whether the column name you're trying to extract
            is definitely a string (e.g. `df[df.columns[0]]`) then you should
            use `DataFrame.get_column` instead.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"a": [1, 2]})
            >>> df = nw.from_native(df_native)
            >>> df["a"].to_native()
            0    1
            1    2
            Name: a, dtype: int64
        r   r)   z2Unexpected type for `DataFrame.__getitem__`, got: z.

Hints:
- use `df.item` to select a single item.
- Use `df[indices, :]` to select rows positionally.
- Use `df.filter(mask)` to filter rows based on a boolean mask.   zzTuples cannot be passed to DataFrame.__getitem__ directly.

Hint: instead of `df[indices]`, did you mean `df[indices, :]`?Nr   )r<  r*   r?  r   r   r   r@  r   r   r   slicer   rP   r   r  r   r  r=  rb   )
rX   r  r*   r   	tuple_msgrowsr   	compliantcol_nameseriess
             rY   r  zDataFrame.__getitem__@  st   | 	+*****Nd N N N 	 dE"" 	!4yy1}}U   	***#J}T!W'='=J4447D!$ii!mm}T!W/E/Emdd4PQ7G|t$$ 	!DGGd## 	!z$'E'E 	!DGGC.. dC   	!C.. )	gSz** 	@$$$ 0yyw///",Wc":":UwwW@UH__X..F#'#36$<<?dF## 	*)Dgv&& 	0/G<''	!!!W*(=>>>?''	$'(:;;;##IdGm$<===rZ   keyr   c                    || j         v S rU   r  )rX   r  s     rY   __contains__zDataFrame.__contains__  s    dl""rZ   .	as_seriesr  Literal[True]dict[str, Series[Any]]c                   d S rU   r   rX   r  s     rY   to_dictzDataFrame.to_dict      TWTWrZ   Literal[False]dict[str, list[Any]]c                   d S rU   r   r  s     rY   r  zDataFrame.to_dict  s    MPSrZ   -dict[str, Series[Any]] | dict[str, list[Any]]c                   d S rU   r   r  s     rY   r  zDataFrame.to_dict  s	     9<rZ   Tc                    |r9 fd j                             |                                          D             S  j                             |          S )av  Convert DataFrame to a dictionary mapping column name to values.

        Arguments:
            as_series: If set to true ``True``, then the values are Narwhals Series,
                    otherwise the values are Any.

        Returns:
            A mapping from column name to values / Series.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"A": [1, 2], "fruits": ["banana", "apple"]})
            >>> df = nw.from_native(df_native)
            >>> df.to_dict(as_series=False)
            {'A': [1, 2], 'fruits': ['banana', 'apple']}
        c                P    i | ]"\  }}|                     |j                   #S )r_   )rA  rR   )r   r  valuerX   s      rY   
<dictcomp>z%DataFrame.to_dict.<locals>.<dictcomp>  sA       C T\\%t{\;;  rZ   r  )rP   r  rl   r  s   ` rY   r  zDataFrame.to_dict  sy    (  	   "&"7"?"?' #@ # #%''	    $,,y,AAArZ   r   tuple[Any, ...]c                6    | j                             |          S )a  Get values at given row.

        Warning:
            You should NEVER use this method to iterate over a DataFrame;
            if you require row-iteration you should strongly prefer use of iter_rows()
            instead.

        Arguments:
            index: Row number.

        Returns:
            A tuple of the values in the selected row.

        Notes:
            cuDF doesn't support this method.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"a": [1, 2], "b": [4, 5]})
            >>> nw.from_native(df_native).row(1)
            (<pyarrow.Int64Scalar: 2>, <pyarrow.Int64Scalar: 5>)
        )rP   row)rX   r   s     rY   r  zDataFrame.row  s    0 $((///rZ   r}   r~   r   r   r   r   rM   c                >     t                      j        |g|R i |S )a  Pipe function call.

        Arguments:
            function: Function to apply.
            args: Positional arguments to pass to function.
            kwargs: Keyword arguments to pass to function.

        Returns:
            The original object with the function applied.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"a": [1, 2], "ba": [4, 5]})
            >>> nw.from_native(df_native).pipe(
            ...     lambda _df: _df.select(
            ...         [x for x in _df.columns if len(x) == 1]
            ...     ).to_native()
            ... )
               a
            0  1
            1  2
        superr   rX   r}   r   r   ra   s       rY   r   zDataFrame.pipe  s+    : uww|H6t666v666rZ   r   r   c                H    t                                          |          S )aP  Drop rows that contain null values.

        Arguments:
            subset: Column name(s) for which null values are considered. If set to None
                (default), use all columns.

        Returns:
            The original object with the rows removed that contained the null values.

        Notes:
            pandas handles null values differently from Polars and PyArrow.
            See [null_handling](../concepts/null_handling.md)
            for reference.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"a": [1.0, None], "ba": [1.0, 2.0]})
            >>> nw.from_native(df_native).drop_nulls().to_native()
            pyarrow.Table
            a: double
            ba: double
            ----
            a: [[1]]
            ba: [[1]]
        r   r  r   rX   r   ra   s     rY   r   zDataFrame.drop_nulls  s     6 ww!!!000rZ   c                F    t                                          |          S )au  Insert column which enumerates rows.

        Arguments:
            name: The name of the column as a string. The default is "index".

        Returns:
            The original object with the column added.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"a": [1, 2], "b": [4, 5]})
            >>> nw.from_native(df_native).with_row_index().to_native()
            pyarrow.Table
            index: int64
            a: int64
            b: int64
            ----
            index: [[0,1]]
            a: [[1,2]]
            b: [[4,5]]
        r  r   rX   r   ra   s     rY   r   zDataFrame.with_row_index0  s    . ww%%d+++rZ   r(   c                *    t                      j        S )a  Get an ordered mapping of column names to their data type.

        Returns:
            A Narwhals Schema object that displays the mapping of column names.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, 2], "bar": [6.0, 7.0]})
            >>> nw.from_native(df_native).schema
            Schema({'foo': Int64, 'bar': Float64})
        r  rx   rX   ra   s    rY   rx   zDataFrame.schemaI       ww~rZ   c                D    t                                                      S )a  Get an ordered mapping of column names to their data type.

        Returns:
            A Narwhals Schema object that displays the mapping of column names.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, 2], "bar": [6.0, 7.0]})
            >>> nw.from_native(df_native).collect_schema()
            Schema({'foo': Int64, 'bar': Float64})
        r  r{   r  s    rY   r{   zDataFrame.collect_schemaY       ww%%'''rZ   r   c                *    t                      j        S )aO  Get column names.

        Returns:
            The column names stored in a list.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, 2], "bar": [6.0, 7.0]})
            >>> nw.from_native(df_native).columns
            ['foo', 'bar']
        r  r   r  s    rY   r   zDataFrame.columnsh       wwrZ   Fnamedr  list[tuple[Any, ...]]c                   d S rU   r   rX   r  s     rY   r  zDataFrame.rowsx  s    ORsrZ   list[dict[str, Any]]c                   d S rU   r   r  s     rY   r  zDataFrame.rows{  s    EHSrZ   ,list[tuple[Any, ...]] | list[dict[str, Any]]c                   d S rU   r   r  s     rY   r  zDataFrame.rows~  r  rZ   c               8    | j                             |          S )ap  Returns all data in the DataFrame as a list of rows of python-native values.

        Arguments:
            named: By default, each row is returned as a tuple of values given
                in the same order as the frame columns. Setting named=True will
                return rows of dictionaries instead.

        Returns:
            The data as a list of rows.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, 2], "bar": [6.0, 7.0]})
            >>> nw.from_native(df_native).rows()
            [(1, 6.0), (2, 7.0)]
        r  )rP   r  r  s     rY   r  zDataFrame.rows  s    ( $)))666rZ   Iterator[Series[Any]]c              #  ~   K   | j                                         D ] }|                     || j                  V  !dS )u  Returns an iterator over the columns of this DataFrame.

        Yields:
            A Narwhals Series, backed by a native series.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"foo": [1, 2], "bar": [6.0, 7.0]})
            >>> iter_columns = nw.from_native(df_native).iter_columns()
            >>> next(iter_columns)
            ┌───────────────────────┐
            |    Narwhals Series    |
            |-----------------------|
            |0    1                 |
            |1    2                 |
            |Name: foo, dtype: int64|
            └───────────────────────┘
            >>> next(iter_columns)
            ┌─────────────────────────┐
            |     Narwhals Series     |
            |-------------------------|
            |0    6.0                 |
            |1    7.0                 |
            |Name: bar, dtype: float64|
            └─────────────────────────┘
        r_   N)rP   iter_columnsrA  rR   )rX   r  s     rY   r  zDataFrame.iter_columns  sQ      8 +88:: 	: 	:F,,vT[,999999	: 	:rZ   )buffer_sizer  Iterator[tuple[Any, ...]]c                   d S rU   r   rX   r  r  s      rY   	iter_rowszDataFrame.iter_rows  s	     %(CrZ   Iterator[dict[str, Any]]c                   d S rU   r   r  s      rY   r  zDataFrame.iter_rows  s	     $'3rZ   4Iterator[tuple[Any, ...]] | Iterator[dict[str, Any]]c                   d S rU   r   r  s      rY   r  zDataFrame.iter_rows  s     @CsrZ   i   r  r  c               :    | j                             ||          S )a  Returns an iterator over the DataFrame of rows of python-native values.

        Arguments:
            named: By default, each row is returned as a tuple of values given
                in the same order as the frame columns. Setting named=True will
                return rows of dictionaries instead.
            buffer_size: Determines the number of rows that are buffered
                internally while iterating over the data.
                See https://docs.pola.rs/api/python/stable/reference/dataframe/api/polars.DataFrame.iter_rows.html

        Returns:
            An iterator over the DataFrame of rows.

        Notes:
            cuDF doesn't support this method.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, 2], "bar": [6.0, 7.0]})
            >>> iter_rows = nw.from_native(df_native).iter_rows()
            >>> next(iter_rows)
            (1, 6.0)
            >>> next(iter_rows)
            (2, 7.0)
        r  )rP   r  r  s      rY   r  zDataFrame.iter_rows  s     : $..U.TTTrZ   rc   rd   re   r<   c                6     t                      j        |i |S )a  Add columns to this DataFrame.

        Added columns will replace existing columns with the same name.

        Arguments:
            *exprs: Column(s) to add, specified as positional arguments.
                     Accepts expression input. Strings are parsed as column names, other
                     non-expression inputs are parsed as literals.

            **named_exprs: Additional columns to add, specified as keyword arguments.
                            The columns will be renamed to the keyword used.

        Returns:
            DataFrame: A new DataFrame with the columns added.

        Note:
            Creating a new DataFrame using this method does not create a new copy of
            existing data.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"a": [1, 2], "b": [0.5, 4.0]})
            >>> (
            ...     nw.from_native(df_native)
            ...     .with_columns((nw.col("a") * 2).alias("a*2"))
            ...     .to_native()
            ... )
               a    b  a*2
            0  1  0.5    2
            1  2  4.0    4
        )r  r   rX   rc   re   ra   s      rY   r   zDataFrame.with_columns  s"    F $uww#U:k:::rZ   c                6     t                      j        |i |S )u  Select columns from this DataFrame.

        Arguments:
            *exprs: Column(s) to select, specified as positional arguments.
                     Accepts expression input. Strings are parsed as column names,
                     other non-expression inputs are parsed as literals.

            **named_exprs: Additional columns to select, specified as keyword arguments.
                            The columns will be renamed to the keyword used.

        Returns:
            The dataframe containing only the selected columns.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"a": [1, 2], "b": [3, 4]})
            >>> nw.from_native(df_native).select("a", a_plus_1=nw.col("a") + 1)
            ┌──────────────────┐
            |Narwhals DataFrame|
            |------------------|
            |pyarrow.Table     |
            |a: int64          |
            |a_plus_1: int64   |
            |----              |
            |a: [[1,2]]        |
            |a_plus_1: [[2,3]] |
            └──────────────────┘
        )r  r   r  s      rY   r   zDataFrame.select	  s!    @ uww~u4444rZ   r   r   c                F    t                                          |          S )aK  Rename column names.

        Arguments:
            mapping: Key value pairs that map from old name to new name.

        Returns:
            The dataframe with the specified columns renamed.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, 2], "bar": [6, 7]})
            >>> nw.from_native(df_native).rename({"foo": "apple"}).to_native()
            pyarrow.Table
            apple: int64
            bar: int64
            ----
            apple: [[1,2]]
            bar: [[6,7]]
        r  r   rX   r   ra   s     rY   r   zDataFrame.rename+  s    * ww~~g&&&rZ      r   c                F    t                                          |          S )a  Get the first `n` rows.

        Arguments:
            n: Number of rows to return. If a negative value is passed, return all rows
                except the last `abs(n)`.

        Returns:
            A subset of the dataframe of shape (n, n_columns).

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"a": [1, 2], "b": [0.5, 4.0]})
            >>> nw.from_native(df_native).head(1).to_native()
               a    b
            0  1  0.5
        r  r   rX   r   ra   s     rY   r   zDataFrame.headB  s    $ ww||ArZ   c                F    t                                          |          S )u  Get the last `n` rows.

        Arguments:
            n: Number of rows to return. If a negative value is passed, return all rows
                except the first `abs(n)`.

        Returns:
            A subset of the dataframe of shape (n, n_columns).

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"a": [1, 2], "b": [0.5, 4.0]})
            >>> nw.from_native(df_native).tail(1)
            ┌──────────────────┐
            |Narwhals DataFrame|
            |------------------|
            |       a    b     |
            |    1  2  4.0     |
            └──────────────────┘
        r  r   r  s     rY   r   zDataFrame.tailV      , ww||ArZ   r   r   r   r   c               P     t                      j        t          |          d|iS )a  Remove columns from the dataframe.

        Returns:
            The dataframe with the specified columns removed.

        Arguments:
            *columns: Names of the columns that should be removed from the dataframe.
            strict: Validate that all column names exist in the schema and throw an
                exception if a column name does not exist in the schema.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame(
            ...     {"foo": [1, 2], "bar": [6.0, 7.0], "ham": ["a", "b"]}
            ... )
            >>> nw.from_native(df_native).drop("ham").to_native()
               foo  bar
            0    1  6.0
            1    2  7.0
        r   r  r   r   rX   r   r   ra   s      rY   r   zDataFrame.dropn  s(    , uww|WW--=f===rZ   anykeepmaintain_orderr  rF   r   c                   |dvrdd d| }t          |          t          |t                    r|g}|                     | j                            |||                    S )aM  Drop duplicate rows from this dataframe.

        Arguments:
            subset: Column name(s) to consider when identifying duplicate rows.
            keep: {'first', 'last', 'any', 'none'}
                Which of the duplicate rows to keep.

                * 'any': Does not give any guarantee of which row is kept.
                        This allows more optimizations.
                * 'none': Don't keep duplicate rows.
                * 'first': Keep first unique row.
                * 'last': Keep last unique row.
            maintain_order: Keep the same order as the original DataFrame. This may be more
                expensive to compute.

        Returns:
            The dataframe with the duplicate rows removed.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame(
            ...     {"foo": [1, 2], "bar": ["a", "a"], "ham": ["b", "b"]}
            ... )
            >>> nw.from_native(df_native).unique(["bar", "ham"]).to_native()
               foo bar ham
            0    1   a   b
        >   r  lastnonefirstz	Expected )r  r  r  r  z, got: r  r   r   r   rb   rP   unique)rX   r   r  r   r   s        rY   r  zDataFrame.unique  s    F 777K=KKTKKCS//!fc"" 	XF##!((d>(ZZ
 
 	
rZ   r   r   r   c                6     t                      j        |i |S )a  Filter the rows in the DataFrame based on one or more predicate expressions.

        The original order of the remaining rows is preserved.

        Arguments:
            *predicates: Expression(s) that evaluates to a boolean Series. Can
                also be a (single!) boolean list.
            **constraints: Column filters; use `name = value` to filter columns by the supplied value.
                Each constraint will behave the same as `nw.col(name).eq(value)`, and will be implicitly
                joined with the other filter conditions using &.

        Returns:
            The filtered dataframe.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame(
            ...     {"foo": [1, 2, 3], "bar": [6, 7, 8], "ham": ["a", "b", "c"]}
            ... )

            Filter on one condition

            >>> nw.from_native(df_native).filter(nw.col("foo") > 1).to_native()
               foo  bar ham
            1    2    7   b
            2    3    8   c

            Filter on multiple conditions with implicit `&`

            >>> nw.from_native(df_native).filter(
            ...     nw.col("foo") < 3, nw.col("ham") == "a"
            ... ).to_native()
               foo  bar ham
            0    1    6   a

            Filter on multiple conditions with `|`

            >>> nw.from_native(df_native).filter(
            ...     (nw.col("foo") == 1) | (nw.col("ham") == "c")
            ... ).to_native()
               foo  bar ham
            0    1    6   a
            2    3    8   c

            Filter using `**kwargs` syntax

            >>> nw.from_native(df_native).filter(foo=2, ham="b").to_native()
               foo  bar ham
            1    2    7   b
        )r  r   )rX   r   r   ra   s      rY   r   zDataFrame.filter  s!    l uww~z9[999rZ   drop_null_keyskeysr	  GroupBy[Self]c                   d S rU   r   rX   r	  r
  s      rY   group_byzDataFrame.group_by  	     rZ   c                   d S rU   r   r  s      rY   r  zDataFrame.group_by  r  rZ   c                  ddl m} t          |          }t          d |D                       r || ||          S ddlm ddlm ddlm	 t          fd|D                       }|r t          |          rd	}t          |          fd
t          ||          D             } | j        | \  }}	t          d |	D                       sddlm}
 d} |
|           || ||          S )a  Start a group by operation.

        Arguments:
            *keys: Column(s) to group by. Accepts expression input. Strings are parsed as
                column names.
            drop_null_keys: if True, then groups where any key is null won't be included
                in the result.

        Returns:
            GroupBy: Object which can be used to perform aggregations.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame(
            ...     {
            ...         "a": ["a", "b", "a", "b", "c"],
            ...         "b": [1, 2, 1, 3, 3],
            ...         "c": [5, 4, 3, 2, 1],
            ...     }
            ... )

            Group by one column and compute the sum of another column

            >>> nw.from_native(df_native, eager_only=True).group_by("a").agg(
            ...     nw.col("b").sum()
            ... ).sort("a").to_native()
               a  b
            0  a  2
            1  b  5
            2  c  3

            Group by multiple columns and compute the max of another column

            >>> (
            ...     nw.from_native(df_native, eager_only=True)
            ...     .group_by(["a", "b"])
            ...     .agg(nw.max("c"))
            ...     .sort("a", "b")
            ...     .to_native()
            ... )
               a  b  c
            0  a  1  5
            1  b  2  4
            2  b  3  2
            3  c  3  1

            Expressions are also accepted.

            >>> nw.from_native(df_native, eager_only=True).group_by(
            ...     "a", nw.col("b") // 2
            ... ).agg(nw.col("c").mean()).to_native()
               a  b    c
            0  a  0  4.0
            1  b  1  3.0
            2  c  1  1.0
        r   )r8   c              3  @   K   | ]}t          |t                    V  d S rU   r   r   r  s     rY   r   z%DataFrame.group_by.<locals>.<genexpr>4  ,      99z#s##999999rZ   r  r   r5  r)   c              3  <   K   | ]}t          |f          V  d S rU   r   )r   kr6  r*   s     rY   r   z%DataFrame.group_by.<locals>.<genexpr>;  s1      %W%WjT6N&C&C%W%W%W%W%W%WrZ   z?drop_null_keys cannot be True when keys contains Expr or Seriesc                4    g | ]\  }}|r|n
 |          S r   r   r   r  is_exprr   s      rY   r   z&DataFrame.group_by.<locals>.<listcomp>A  s>     
 
 
7 $AAcc!ff
 
 
rZ   c              3  2   K   | ]}|t           j        u V  d S rU   r   ELEMENTWISEr   r   s     rY   r   z%DataFrame.group_by.<locals>.<genexpr>G  *      BBD48//BBBBBBrZ   ComputeErrorHGroup by is not supported with keys that are not elementwise expressions)narwhals.group_byr8   r   r   narwhalsr   r;  r6  r<  r*   r   r  rv   r   rr   narwhals.exceptionsr!  )rX   r	  r
  r8   	flat_keyskey_is_expr_or_seriesr   _keysexpr_flat_keysr   r!  r6  r*   r   s              @@@rY   r  zDataFrame.group_by  s   x 	.-----DMM	99y99999 	K74>JJJJ      &&&&&&****** %%W%W%W%W%WY%W%W%W W W 	+c"788 	+SC%c***
 
 
 
!)-BCC
 
 
 !: 95 ABBEBBBBB 	$888888 [  ,s###wt^NKKKKrZ   r   r   r   r   r   r   c               @     t                      j        |g|R ||dS )u  Sort the dataframe by the given columns.

        Arguments:
            by: Column(s) names to sort by.
            *more_by: Additional columns to sort by, specified as positional arguments.
            descending: Sort in descending order. When sorting by multiple columns, can be
                specified per column by passing a sequence of booleans.
            nulls_last: Place null values last.

        Returns:
            The sorted dataframe.

        Note:
            Unlike Polars, it is not possible to specify a sequence of booleans for
            `nulls_last` in order to control per-column behaviour. Instead a single
            boolean is applied for all `by` columns.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame(
            ...     {"foo": [2, 1], "bar": [6.0, 7.0], "ham": ["a", "b"]}
            ... )
            >>> nw.from_native(df_native).sort("foo")
            ┌──────────────────┐
            |Narwhals DataFrame|
            |------------------|
            |    foo  bar ham  |
            | 1    1  7.0   b  |
            | 0    2  6.0   a  |
            └──────────────────┘
        r   r  r   rX   r   r   r   r   ra   s        rY   r   zDataFrame.sortQ  s.    N uww|BWWWZJWWWWrZ   r   r   r   r   r   r   r>   r   r   r   c               R    t                                          ||||||          S )u  Join in SQL-like fashion.

        Arguments:
            other: DataFrame to join with.
            on: Name(s) of the join columns in both DataFrames. If set, `left_on` and
                `right_on` should be None.
            how: Join strategy.

                  * *inner*: Returns rows that have matching values in both tables.
                  * *left*: Returns all rows from the left table, and the matched rows from the right table.
                  * *full*: Returns all rows in both dataframes, with the suffix appended to the right join keys.
                  * *cross*: Returns the Cartesian product of rows from both tables.
                  * *semi*: Filter rows that have a match in the right table.
                  * *anti*: Filter rows that do not have a match in the right table.
            left_on: Join column of the left DataFrame.
            right_on: Join column of the right DataFrame.
            suffix: Suffix to append to columns with a duplicate name.

        Returns:
            A new joined DataFrame

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_1_native = pd.DataFrame({"id": ["a", "b"], "price": [6.0, 7.0]})
            >>> df_2_native = pd.DataFrame({"id": ["a", "b", "c"], "qty": [1, 2, 3]})
            >>> nw.from_native(df_1_native).join(nw.from_native(df_2_native), on="id")
            ┌──────────────────┐
            |Narwhals DataFrame|
            |------------------|
            |   id  price  qty |
            | 0  a    6.0    1 |
            | 1  b    7.0    2 |
            └──────────────────┘
        r   r   r   r   r   r  r   rX   r   r   r   r   r   r   ra   s          rY   r   zDataFrame.joinz  s2    Z ww||sGh2f  
 
 	
rZ   r   r   r   r   r  r:   c               X    t                                          |||||||||		  	        S )up  Perform an asof join.

        This is similar to a left-join except that we match on nearest key rather than equal keys.

        For Polars, both DataFrames must be sorted by the `on` key (within each `by` group
        if specified).

        Arguments:
            other: DataFrame to join with.
            left_on: Name(s) of the left join column(s).
            right_on: Name(s) of the right join column(s).
            on: Join column of both DataFrames. If set, left_on and right_on should be None.
            by_left: join on these columns before doing asof join.
            by_right: join on these columns before doing asof join.
            by: join on these columns before doing asof join.
            strategy: Join strategy. The default is "backward".
            suffix: Suffix to append to columns with a duplicate name.

                  * *backward*: selects the last row in the right DataFrame whose "on" key is less than or equal to the left's key.
                  * *forward*: selects the first row in the right DataFrame whose "on" key is greater than or equal to the left's key.
                  * *nearest*: search selects the last row in the right DataFrame whose value is nearest to the left's key.

        Returns:
            A new joined DataFrame

        Examples:
            >>> from datetime import datetime
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> data_gdp = {
            ...     "datetime": [
            ...         datetime(2016, 1, 1),
            ...         datetime(2017, 1, 1),
            ...         datetime(2018, 1, 1),
            ...         datetime(2019, 1, 1),
            ...         datetime(2020, 1, 1),
            ...     ],
            ...     "gdp": [4164, 4411, 4566, 4696, 4827],
            ... }
            >>> data_population = {
            ...     "datetime": [
            ...         datetime(2016, 3, 1),
            ...         datetime(2018, 8, 1),
            ...         datetime(2019, 1, 1),
            ...     ],
            ...     "population": [82.19, 82.66, 83.12],
            ... }
            >>> gdp_native = pd.DataFrame(data_gdp)
            >>> population_native = pd.DataFrame(data_population)
            >>> gdp = nw.from_native(gdp_native)
            >>> population = nw.from_native(population_native)
            >>> population.join_asof(gdp, on="datetime", strategy="backward")
            ┌──────────────────────────────┐
            |      Narwhals DataFrame      |
            |------------------------------|
            |    datetime  population   gdp|
            |0 2016-03-01       82.19  4164|
            |1 2018-08-01       82.66  4566|
            |2 2019-01-01       83.12  4696|
            └──────────────────────────────┘
        r   r  r  rX   r   r   r   r   r   r   r   r  r   ra   s             rY   r  zDataFrame.join_asof  sB    T ww   ! 

 

 
	
rZ   c                ,    |                                   S )u  Get a mask of all duplicated rows in this DataFrame.

        Returns:
            A new Series.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"foo": [2, 2, 2], "bar": [6.0, 6.0, 7.0]})
            >>> nw.from_native(df_native).is_duplicated()
            ┌───────────────┐
            |Narwhals Series|
            |---------------|
            |  0     True   |
            |  1     True   |
            |  2    False   |
            |  dtype: bool  |
            └───────────────┘
        )	is_uniquerW   s    rY   is_duplicatedzDataFrame.is_duplicated  s    (     rZ   c                (    t          |           dk    S )a  Check if the dataframe is empty.

        Returns:
            A boolean indicating whether the dataframe is empty (True) or not (False).

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"foo": [2, 2, 2], "bar": [6.0, 6.0, 7.0]})
            >>> nw.from_native(df_native).is_empty()
            False
        r   )r   rW   s    rY   is_emptyzDataFrame.is_empty  s     4yyA~rZ   c                h    |                      | j                                        | j                  S )u  Get a mask of all unique rows in this DataFrame.

        Returns:
            A new Series.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"foo": [2, 2, 2], "bar": [6.0, 6.0, 7.0]})
            >>> nw.from_native(df_native).is_unique()
            ┌───────────────┐
            |Narwhals Series|
            |---------------|
            |  0    False   |
            |  1    False   |
            |  2     True   |
            |  dtype: bool  |
            └───────────────┘
        r_   )rA  rP   r5  rR   rW   s    rY   r5  zDataFrame.is_unique'  s+    ( ||D1;;==T[|QQQrZ   c                    | j                                         }| j                             |                                                                          }|                     |          S )u  Create a new DataFrame that shows the null counts per column.

        Returns:
            A dataframe of shape (1, n_columns).

        Notes:
            pandas handles null values differently from Polars and PyArrow.
            See [null_handling](../concepts/null_handling.md/)
            for reference.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, None], "bar": [2, 3]})
            >>> nw.from_native(df_native).null_count()
            ┌──────────────────┐
            |Narwhals DataFrame|
            |------------------|
            |  pyarrow.Table   |
            |  foo: int64      |
            |  bar: int64      |
            |  ----            |
            |  foo: [[1]]      |
            |  bar: [[0]]      |
            └──────────────────┘
        )rP   r\   r   r   
null_countrb   )rX   r   results      rY   r;  zDataFrame.null_count=  sV    6 #::<<&--cggii.B.B.D.DEE##F+++rZ   r  
int | Nonecolumnint | str | Nonec                :    | j                             ||          S )a  Return the DataFrame as a scalar, or return the element at the given row/column.

        Arguments:
            row: The *n*-th row.
            column: The column selected via an integer or a string (column name).

        Returns:
            A scalar or the specified element in the dataframe.

        Notes:
            If row/col not provided, this is equivalent to df[0,0], with a check that the shape is (1,1).
            With row/col, this is equivalent to df[row,col].

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, None], "bar": [2, 3]})
            >>> nw.from_native(df_native).item(0, 1)
            2
        )r  r>  )rP   r  )rX   r  r>  s      rY   r  zDataFrame.item\  s     * $))c&)AAArZ   c                Z    |                      | j                                                  S )ztCreate a copy of this DataFrame.

        Returns:
            An identical copy of the original dataframe.
        )rb   rP   clonerW   s    rY   rB  zDataFrame.clones  s'     ##D$9$?$?$A$ABBBrZ   r   r   c                J    t                                          ||          S )u)  Take every nth row in the DataFrame and return as a new DataFrame.

        Arguments:
            n: Gather every *n*-th row.
            offset: Starting index.

        Returns:
            The dataframe containing only the selected rows.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"foo": [1, None, 2, 3]})
            >>> nw.from_native(df_native).gather_every(2)
            ┌──────────────────┐
            |Narwhals DataFrame|
            |------------------|
            |  pyarrow.Table   |
            |  foo: int64      |
            |  ----            |
            |  foo: [[1,2]]    |
            └──────────────────┘
        r   )r  r   )rX   r   r   ra   s      rY   r   zDataFrame.gather_every{  s"    0 ww##a#777rZ   _)r   valuesaggregate_functionr   sort_columns	separatorstr | list[str]rE  rF  PivotAgg | NonerG  rH  c          
     |   ||d}t          |          |%d}t          |t          t                                 t	          |t
                    r|gn|}t	          |t
                    r|gn|}t	          |t
                    r|gn|}|                     | j                            ||||||                    S )u	  Create a spreadsheet-style pivot table as a DataFrame.

        Arguments:
            on: Name of the column(s) whose values will be used as the header of the
                output DataFrame.
            index: One or multiple keys to group by. If None, all remaining columns not
                specified on `on` and `values` will be used. At least one of `index` and
                `values` must be specified.
            values: One or multiple keys to group by. If None, all remaining columns not
                specified on `on` and `index` will be used. At least one of `index` and
                `values` must be specified.
            aggregate_function: Choose from

                - None: no aggregation takes place, will raise error if multiple values
                    are in group.
                - A predefined aggregate function string, one of
                    {'min', 'max', 'first', 'last', 'sum', 'mean', 'median', 'len'}
            maintain_order: Has no effect and is kept around only for backwards-compatibility.
            sort_columns: Sort the transposed columns by name. Default is by order of
                discovery.
            separator: Used as separator/delimiter in generated column names in case of
                multiple `values` columns.

        Returns:
            A new dataframe.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> data = {
            ...     "ix": [1, 1, 2, 2, 1, 2],
            ...     "col": ["a", "a", "a", "a", "b", "b"],
            ...     "foo": [0, 1, 2, 2, 7, 1],
            ...     "bar": [0, 2, 0, 0, 9, 4],
            ... }
            >>> df_native = pd.DataFrame(data)
            >>> nw.from_native(df_native).pivot(
            ...     "col", index="ix", aggregate_function="sum"
            ... )
            ┌─────────────────────────────────┐
            |       Narwhals DataFrame        |
            |---------------------------------|
            |   ix  foo_a  foo_b  bar_a  bar_b|
            |0   1      1      7      2      9|
            |1   2      4      1      0      4|
            └─────────────────────────────────┘
        Nz3At least one of `values` and `index` must be passedzx`maintain_order` has no effect and is only kept around for backwards-compatibility. You can safely remove this argument.)messagecategory
stacklevel)r   r   rE  rF  rG  rH  )	r   r   UserWarningr   r   r   rb   rP   pivot)	rX   r   r   rE  rF  r   rG  rH  r   s	            rY   rP  zDataFrame.pivot  s    t >emGCS//!%7  {?P?PQQQQC((0bTTb'44@&&%eS11<u##!''#5)# (  	
 	
 		
rZ   pa.Tablec                4    | j                                         S )a  Convert to arrow table.

        Returns:
            A new PyArrow table.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"foo": [1, None], "bar": [2, 3]})
            >>> nw.from_native(df_native).to_arrow()
            pyarrow.Table
            foo: double
            bar: int64
            ----
            foo: [[1,null]]
            bar: [[2,3]]
        )rP   ri  rW   s    rY   ri  zDataFrame.to_arrow  s    $ $--///rZ   )fractionwith_replacementseedrS  float | NonerT  rU  c               d    |                      | j                            ||||                    S )uV  Sample from this DataFrame.

        Arguments:
            n: Number of items to return. Cannot be used with fraction.
            fraction: Fraction of items to return. Cannot be used with n.
            with_replacement: Allow values to be sampled more than once.
            seed: Seed for the random number generator. If set to None (default), a random
                seed is generated for each sample operation.

        Returns:
            A new dataframe.

        Notes:
            The results may not be consistent across libraries.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> df_native = pd.DataFrame({"foo": [1, 2, 3], "bar": [19, 32, 4]})
            >>> nw.from_native(df_native).sample(n=2)  # doctest:+SKIP
            ┌──────────────────┐
            |Narwhals DataFrame|
            |------------------|
            |      foo  bar    |
            |   2    3    4    |
            |   1    2   32    |
            └──────────────────┘
        )r   rS  rT  rU  )rb   rP   sample)rX   r   rS  rT  rU  s        rY   rX  zDataFrame.sample  sC    H ##!((h9IPT )  
 
 	
rZ   variabler  r   r  r	  r  r	  c               N    t                                          ||||          S )u[  Unpivot a DataFrame from wide to long format.

        Optionally leaves identifiers set.

        This function is useful to massage a DataFrame into a format where one or more
        columns are identifier variables (index) while all other columns, considered
        measured variables (on), are "unpivoted" to the row axis leaving just
        two non-identifier columns, 'variable' and 'value'.

        Arguments:
            on: Column(s) to use as values variables; if `on` is empty all columns that
                are not in `index` will be used.
            index: Column(s) to use as identifier variables.
            variable_name: Name to give to the `variable` column. Defaults to "variable".
            value_name: Name to give to the `value` column. Defaults to "value".

        Returns:
            The unpivoted dataframe.

        Notes:
            If you're coming from pandas, this is similar to `pandas.DataFrame.melt`,
            but with `index` replacing `id_vars` and `on` replacing `value_vars`.
            In other frameworks, you might know this operation as `pivot_longer`.

        Examples:
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> data = {"a": ["x", "y", "z"], "b": [1, 3, 5], "c": [2, 4, 6]}
            >>> df_native = pd.DataFrame(data)
            >>> nw.from_native(df_native).unpivot(["b", "c"], index="a")
            ┌────────────────────┐
            | Narwhals DataFrame |
            |--------------------|
            |   a variable  value|
            |0  x        b      1|
            |1  y        b      3|
            |2  z        b      5|
            |3  x        c      2|
            |4  y        c      4|
            |5  z        c      6|
            └────────────────────┘
        r  r  r  rX   r   r   r  r	  ra   s        rY   r  zDataFrame.unpivot%  s.    d wwm
  
 
 	
rZ   r  r  c                8     t                      j        |g|R  S )uk  Explode the dataframe to long format by exploding the given columns.

        Notes:
            It is possible to explode multiple columns only if these columns must have
            matching element counts.

        Arguments:
            columns: Column names. The underlying columns being exploded must be of the `List` data type.
            *more_columns: Additional names of columns to explode, specified as positional arguments.

        Returns:
            New DataFrame

        Examples:
            >>> import polars as pl
            >>> import narwhals as nw
            >>> data = {"a": ["x", "y"], "b": [[1, 2], [3]]}
            >>> df_native = pl.DataFrame(data)
            >>> nw.from_native(df_native).explode("b").to_native()
            shape: (3, 2)
            ┌─────┬─────┐
            │ a   ┆ b   │
            │ --- ┆ --- │
            │ str ┆ i64 │
            ╞═════╪═════╡
            │ x   ┆ 1   │
            │ x   ┆ 2   │
            │ y   ┆ 3   │
            └─────┴─────┘
        r  r  rX   r   r  ra   s      rY   r  zDataFrame.explode[  s#    > uwww66666rZ   r  )rS   rD  )rS   rF  r]   r   r`   rQ   rS   rK  rS   r   )rS   r   )NN)rW  r   rX  rY  rS   rG   rS   r   rU   )ra  rb  rS   r  )rn  ro  rS   rp  )rS   rL   )rS   rz  )rS   r}  )r  rK  rS   r   )r  r  rS   rK  )r  r  rS   r  )rS   rG   )rS   r  )r   r   rS   r  )r  )r  rE   rS   r  )r  r  rS   r   )r  r  rS   r  )r  r  rS   r2   )r  r  rS   r  )r  r   rS   r   )r  r  rS   r  )r  r  rS   r  )r  r   rS   r  )r   r   rS   r  r  r  r  r  r  r   )r  r  rS   r  )r  r  rS   r  )r  r   rS   r  )rS   r  )r  r  r  r   rS   r  )r  r  r  r   rS   r  )r  r   r  r   rS   r  r!  r"  r  r#  r   r   r   r   rS   r2   )r   r   r  rF   r   r   rS   r2   r$  )r
  rd   r	  r  rS   r  )r
  r   r	  r  rS   r  )r
  rd   r	  r   rS   r  r%  r&  r'  r*  )rS   r  )rS   r   rS   r2   )r  r=  r>  r?  rS   r   r(  r)  )r   rI  r   r   rE  r   rF  rJ  r   rY  rG  r   rH  r   rS   r2   )rS   rQ  )
r   r=  rS  rV  rT  r   rU  r=  rS   r2   r+  r,  )?r-  r.  r/  __doc__ri   r1  rA  rI  rP  rT  rV  r\  r_  rf  rr  r,   r|  r  r   r  r  r  r  r  r  r  r  r  r  r   r   r   rx   r{   r   r  r  r  r   r   r   r   r   r   r  r   r  r   r   r  r6  r8  r5  r;  r  rB  r   rP  ri  rX  r  r  __classcell__ra   s   @rY   r3  r3    sX	        0@ @ @ @2    X    X& & & & 5 5 5 X52/ / / /A A A A AP P P PN N N N N0 CGL
 L
 L
 L
 L
\3 3 3 3.1 1 1 1*1 1 1 10 6666 X6@@@ X@5 5 5 5 522 2 2 2&? ? ? ?" + + + X+ W W W W8? ? ? ? ?0 ZZZ XZ   X 	 	 	 X	o> o> o> o>b# # # # 47WWWWW XWPPP XP< < < X< $(B B B B B B:0 0 0 067 7 7 7 7 7>1 1 1 1 1 1 1:, , , , , , ,2      X( ( ( ( ( (      X .3RRRRR XRHHH XHWWW XW  %7 7 7 7 7 7,: : : :> ;>( ( ( ( ( X( :=' ' ' ' ' X' 14C C C C C XC
  %U U U U U U>#; #; #; #; #; #;J 5  5  5  5  5  5D' ' ' ' ' '.      (      0 BF > > > > > > > >4 *.*
 $)$*
 *
 *
 *
 *
 *
X6: 6: 6: 6: 6: 6:p UX     X    X
 LQ[L [L [L [L [L [LB -2 'X 'X 'X 'X 'X 'X 'X 'XX &*#	/
 +/+//
 /
 /
 /
 /
 /
 /
 /
j ##*.+/%)%/T
 T
 T
 T
 T
 T
 T
 T
n! ! ! !,   R R R R,, , , ,>B B B B B.C C C C8 8 8 8 8 8 8< )-)-.2&*"P
 P
 P
 P
 P
 P
d0 0 0 0, (
 "&!&(
 (
 (
 (
 (
 (
X &*4
 )-'!4
 4
 4
 4
 4
 4
 4
 4
l7 7 7 7 7 7 7 7 7 7rZ   r3  c            	      (    e Zd ZdZddZedd            ZddZddZedd            Z	ddZ
	 dddZddZd fd#Zdd fd'Zdd fd*Zed fd,            Zd fd-Zed fd/            Zd fd4Zd fd5Zd fd8Zdd fd<Zdd fd=Zd>d?d fdDZ	 ddEdFddIZd fdMZedNdOddT            ZeddV            ZdWdOddXZdWdWdYd fd_Z	 	 ddddadbd fdjZdddddddkdadld fdrZddsZ dd fdvZ!	 dddwdxdyd fd|Z"d fdZ# xZ$S )rH  a  Narwhals LazyFrame, backed by a native lazyframe.

    Warning:
        This class is not meant to be instantiated directly - instead use
        [`narwhals.from_native`][] with a native
        object that is a lazy dataframe from one of the supported
        backend (e.g. polars.LazyFrame, dask_expr._collection.DataFrame):
        ```py
        narwhals.from_native(native_lazyframe)
        ```
    rs   r   rS   c                   ddl m} ddlm} t	          |t
                    r|j        S t	          ||          rd}t          |          t	          |t                    r)| 	                                }|
                    |          S t	          ||          ra|j        j        rd}t          |          |j        j        rd}t          |          |                    | 	                                          S t#                      @dt          t%          |                    v r"dt%          |           d	}t          |          t'          j        t%          |                    )
Nr   r5  r)   zABinary operations between Series and LazyFrame are not supported.a  Order-dependent expressions are not supported for use in LazyFrame.

Hint: To make the expression valid, use `.over` with `order_by` specified.

For example, if you wrote `nw.col('price').cum_sum()` and you have a column
`'date'` which orders your data, then replace:

   nw.col('price').cum_sum()

 with:

   nw.col('price').cum_sum().over(order_by='date')
                            ^^^^^^^^^^^^^^^^^^^^^^

See https://narwhals-dev.github.io/narwhals/concepts/order_dependence/.a1  Length-changing expressions are not supported for use in LazyFrame, unless
followed by an aggregation.

Hints:
- Instead of `lf.select(nw.col('a').head())`, use `lf.select('a').head()
- Instead of `lf.select(nw.col('a').drop_nulls()).select(nw.sum('a'))`,
  use `lf.select(nw.col('a').drop_nulls().sum())
r7  r8  r9  )r;  r6  r<  r*   r   rO   rP   r@  r   r\   r   	_metadatan_orderable_opsr'   is_filtrationr&   r   r#   r?  r%   rC  )rX   rs   r6  r*   r   r   s         rY   ri   zLazyFrame._extract_compliant  s   &&&&&&******c9%% 	(''c6"" 	!UCC.. c3 	 --//C773<<c4   	I}, 3^  .c222}* 	3I  .c222))$*E*E*G*GHHH<<#CS		NN(B(B7$s)) 7 7 7  C.. "4T#YY???rZ   type[DataFrame[Any]]c                    t           S rU   )r3  rW   s    rY   
_dataframezLazyFrame._dataframe  rJ  rZ   r]   r`   rQ   rK  c                   || _         |  t          |          r|                                | _        d S dt	          |           }t          |          )NzVExpected Polars LazyFrame or an object that implements `__narwhals_lazyframe__`, got: )rR   r   __narwhals_lazyframe__rP   r?  rN  rO  s       rY   rP  zLazyFrame.__init__  s^    D!"%% 	&$&$=$=$?$?D!!!ukoprksksuuC %%%rZ   r   c                j    t          d|                                                                           S )NzNarwhals LazyFramer^  rW   s    rY   r_  zLazyFrame.__repr__  r`  rZ   r   c                    | j         j        S )a  Return implementation of native frame.

        This can be useful when you need to use special-casing for features outside of
        Narwhals' scope - for example, when dealing with pandas' Period Dtype.

        Returns:
            Implementation.

        Examples:
            >>> import narwhals as nw
            >>> import dask.dataframe as dd
            >>> lf_native = dd.from_dict({"a": [1, 2]}, npartitions=1)
            >>> nw.from_native(lf_native).implementation
            <Implementation.DASK: 'dask'>
        rR  rW   s    rY   rT  zLazyFrame.implementation  s    " $44rZ   r  str | slicer   c                $    d}t          |          )Nz%Slicing is not supported on LazyFrame)r@  )rX   r  r   s      rY   r  zLazyFrame.__getitem__  s    5nnrZ   Nrn  ro  r   DataFrame[Any]c                   |dnt          j        |          }t           j        t           j        t           j        f}|||vrd| d| d}t          |          |                      | j        j        dd|i|d          S )	u
  Materialize this LazyFrame into a DataFrame.

        As each underlying lazyframe has different arguments to set when materializing
        the lazyframe into a dataframe, we allow to pass them as kwargs (see examples
        below for how to generalize the specification).

        Arguments:
            backend: specifies which eager backend collect to. This will be the underlying
                backend for the resulting Narwhals DataFrame. If None, then the following
                default conversions will be applied

                - `polars.LazyFrame` -> `polars.DataFrame`
                - `dask.DataFrame` -> `pandas.DataFrame`
                - `duckdb.PyRelation` -> `pyarrow.Table`
                - `pyspark.DataFrame` -> `pyarrow.Table`

                `backend` can be specified in various ways

                - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`
                    or `POLARS`.
                - As a string: `"pandas"`, `"pyarrow"` or `"polars"`
                - Directly as a module `pandas`, `pyarrow` or `polars`.
            kwargs: backend specific kwargs to pass along. To know more please check the
                backend specific documentation

                - [polars.LazyFrame.collect](https://docs.pola.rs/api/python/dev/reference/lazyframe/api/polars.LazyFrame.collect.html)
                - [dask.dataframe.DataFrame.compute](https://docs.dask.org/en/stable/generated/dask.dataframe.DataFrame.compute.html)

        Returns:
            DataFrame

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 2), (3, 4) df(a, b)")
            >>> lf = nw.from_native(lf_native)
            >>> lf
            ┌──────────────────┐
            |Narwhals LazyFrame|
            |------------------|
            |┌───────┬───────┐ |
            |│   a   │   b   │ |
            |│ int32 │ int32 │ |
            |├───────┼───────┤ |
            |│     1 │     2 │ |
            |│     3 │     4 │ |
            |└───────┴───────┘ |
            └──────────────────┘
            >>> lf.collect()
            ┌──────────────────┐
            |Narwhals DataFrame|
            |------------------|
            |  pyarrow.Table   |
            |  a: int32        |
            |  b: int32        |
            |  ----            |
            |  a: [[1,3]]      |
            |  b: [[2,4]]      |
            └──────────────────┘
        Nz-Unsupported `backend` value.
Expected one of z or None, got: r   rn  r   r_   r   )	r   rs  rv  PANDASPYARROWr   rq  rP   collect)rX   rn  r   eager_backendsupported_eager_backendsr   s         rY   r|  zLazyFrame.collect  s    ~ !(^5PQX5Y5Y!!"$
 
 $>V)V)V|C[||ly|||CS//!)D!)JJ-J6JJRX  
 
 	
rZ   rK   c                $    t          | d          S )u  Convert Narwhals LazyFrame to native one.

        Returns:
            Object of class that user started with.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 2), (3, 4) df(a, b)")
            >>> nw.from_native(lf_native).to_native()
            ┌───────┬───────┐
            │   a   │   b   │
            │ int32 │ int32 │
            ├───────┼───────┤
            │     1 │     2 │
            │     3 │     4 │
            └───────┴───────┘
            <BLANKLINE>
        F)narwhals_objectpass_throughr+   rW   s    rY   r,   zLazyFrame.to_native,	  s    ( EBBBBrZ   r}   r~   r   r   r   rM   c                >     t                      j        |g|R i |S )u  Pipe function call.

        Arguments:
            function: Function to apply.
            args: Positional arguments to pass to function.
            kwargs: Keyword arguments to pass to function.

        Returns:
            The original object with the function applied.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 2), (3, 4) df(a, b)")
            >>> nw.from_native(lf_native).pipe(lambda x: x.select("a")).to_native()
            ┌───────┐
            │   a   │
            │ int32 │
            ├───────┤
            │     1 │
            │     3 │
            └───────┘
            <BLANKLINE>
        r  r  s       rY   r   zLazyFrame.pipeC	  s+    < uww|H6t666v666rZ   r   r   r2   c                H    t                                          |          S )u  Drop rows that contain null values.

        Arguments:
            subset: Column name(s) for which null values are considered. If set to None
                (default), use all columns.

        Returns:
            The original object with the rows removed that contained the null values.

        Notes:
            pandas handles null values differently from Polars and PyArrow.
            See [null_handling](../concepts/null_handling.md/)
            for reference.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, NULL), (3, 4) df(a, b)")
            >>> nw.from_native(lf_native).drop_nulls()
            ┌──────────────────┐
            |Narwhals LazyFrame|
            |------------------|
            |┌───────┬───────┐ |
            |│   a   │   b   │ |
            |│ int32 │ int32 │ |
            |├───────┼───────┤ |
            |│     3 │     4 │ |
            |└───────┴───────┘ |
            └──────────────────┘
        r   r  r  s     rY   r   zLazyFrame.drop_nullsc	  s     > ww!!!000rZ   r   r   c                F    t                                          |          S )u  Insert column which enumerates rows.

        Arguments:
            name: The name of the column as a string. The default is "index".

        Returns:
            The original object with the column added.

        Examples:
            >>> import dask.dataframe as dd
            >>> import narwhals as nw
            >>> lf_native = dd.from_dict({"a": [1, 2], "b": [4, 5]}, npartitions=1)
            >>> nw.from_native(lf_native).with_row_index().collect()
            ┌──────────────────┐
            |Narwhals DataFrame|
            |------------------|
            |     index  a  b  |
            |  0      0  1  4  |
            |  1      1  2  5  |
            └──────────────────┘
        r  r  s     rY   r   zLazyFrame.with_row_index	  s    , ww%%d+++rZ   r(   c                *    t                      j        S )a  Get an ordered mapping of column names to their data type.

        Returns:
            A Narwhals Schema object that displays the mapping of column names.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 4.5), (3, 2.) df(a, b)")
            >>> nw.from_native(lf_native).schema
            Schema({'a': Int32, 'b': Decimal})
        r  r  s    rY   rx   zLazyFrame.schema	  r  rZ   c                D    t                                                      S )a  Get an ordered mapping of column names to their data type.

        Returns:
            A Narwhals Schema object that displays the mapping of column names.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 4.5), (3, 2.) df(a, b)")
            >>> nw.from_native(lf_native).collect_schema()
            Schema({'a': Int32, 'b': Decimal})
        r  r  s    rY   r{   zLazyFrame.collect_schema	  r  rZ   r   c                *    t                      j        S )aU  Get column names.

        Returns:
            The column names stored in a list.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 4.5), (3, 2.) df(a, b)")
            >>> nw.from_native(lf_native).columns
            ['a', 'b']
        r  r  s    rY   r   zLazyFrame.columns	  r  rZ   rc   rd   re   r<   c                `    |s|sd}t          |           t                      j        |i |S )uE  Add columns to this LazyFrame.

        Added columns will replace existing columns with the same name.

        Arguments:
            *exprs: Column(s) to add, specified as positional arguments.
                     Accepts expression input. Strings are parsed as column names, other
                     non-expression inputs are parsed as literals.

            **named_exprs: Additional columns to add, specified as keyword arguments.
                            The columns will be renamed to the keyword used.

        Returns:
            LazyFrame: A new LazyFrame with the columns added.

        Note:
            Creating a new LazyFrame using this method does not create a new copy of
            existing data.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 4.5), (3, 2.) df(a, b)")
            >>> nw.from_native(lf_native).with_columns(c=nw.col("a") + 1)
            ┌────────────────────────────────┐
            |       Narwhals LazyFrame       |
            |--------------------------------|
            |┌───────┬──────────────┬───────┐|
            |│   a   │      b       │   c   │|
            |│ int32 │ decimal(2,1) │ int32 │|
            |├───────┼──────────────┼───────┤|
            |│     1 │          4.5 │     2 │|
            |│     3 │          2.0 │     4 │|
            |└───────┴──────────────┴───────┘|
            └────────────────────────────────┘
        z@At least one expression must be passed to LazyFrame.with_columns)r   r  r   rX   rc   re   r   ra   s       rY   r   zLazyFrame.with_columns	  sB    N  	"[ 	"TCS//!#uww#U:k:::rZ   c                `    |s|sd}t          |           t                      j        |i |S )u  Select columns from this LazyFrame.

        Arguments:
            *exprs: Column(s) to select, specified as positional arguments.
                Accepts expression input. Strings are parsed as column names.
            **named_exprs: Additional columns to select, specified as keyword arguments.
                The columns will be renamed to the keyword used.

        Returns:
            The LazyFrame containing only the selected columns.

        Notes:
            If you'd like to select a column whose name isn't a string (for example,
            if you're working with pandas) then you should explicitly use `nw.col` instead
            of just passing the column name. For example, to select a column named
            `0` use `df.select(nw.col(0))`, not `df.select(0)`.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 4.5), (3, 2.) df(a, b)")
            >>> nw.from_native(lf_native).select("a", a_plus_1=nw.col("a") + 1)
            ┌────────────────────┐
            | Narwhals LazyFrame |
            |--------------------|
            |┌───────┬──────────┐|
            |│   a   │ a_plus_1 │|
            |│ int32 │  int32   │|
            |├───────┼──────────┤|
            |│     1 │        2 │|
            |│     3 │        4 │|
            |└───────┴──────────┘|
            └────────────────────┘
        z:At least one expression must be passed to LazyFrame.select)r   r  r   r  s       rY   r   zLazyFrame.select	  sA    J  	"[ 	"NCS//!uww~u4444rZ   r   r   c                F    t                                          |          S )u  Rename column names.

        Arguments:
            mapping: Key value pairs that map from old name to new name, or a
                      function that takes the old name as input and returns the
                      new name.

        Returns:
            The LazyFrame with the specified columns renamed.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 4.5), (3, 2.) df(a, b)")
            >>> nw.from_native(lf_native).rename({"a": "c"})
            ┌────────────────────────┐
            |   Narwhals LazyFrame   |
            |------------------------|
            |┌───────┬──────────────┐|
            |│   c   │      b       │|
            |│ int32 │ decimal(2,1) │|
            |├───────┼──────────────┤|
            |│     1 │          4.5 │|
            |│     3 │          2.0 │|
            |└───────┴──────────────┘|
            └────────────────────────┘
        r  r  s     rY   r   zLazyFrame.rename!
  s    8 ww~~g&&&rZ   r  r   r   c                F    t                                          |          S )u  Get `n` rows.

        Arguments:
            n: Number of rows to return.

        Returns:
            A subset of the LazyFrame of shape (n, n_columns).

        Examples:
            >>> import dask.dataframe as dd
            >>> import narwhals as nw
            >>> lf_native = dd.from_dict({"a": [1, 2, 3], "b": [4, 5, 6]}, npartitions=1)
            >>> nw.from_native(lf_native).head(2).collect()
            ┌──────────────────┐
            |Narwhals DataFrame|
            |------------------|
            |        a  b      |
            |     0  1  4      |
            |     1  2  5      |
            └──────────────────┘
        r  r  s     rY   r   zLazyFrame.head?
  r  rZ   c                F    t                                          |          S )a  Get the last `n` rows.

        Warning:
            `LazyFrame.tail` is deprecated and will be removed in a future version.
            Note: this will remain available in `narwhals.stable.v1`.
            See [stable api](../backcompat.md/) for more information.

        Arguments:
            n: Number of rows to return.

        Returns:
            A subset of the LazyFrame of shape (n, n_columns).
        r  r  s     rY   r   zLazyFrame.tailW
  s     ww||ArZ   Tr   r   r   r   r   c               P     t                      j        t          |          d|iS )u  Remove columns from the LazyFrame.

        Arguments:
            *columns: Names of the columns that should be removed from the dataframe.
            strict: Validate that all column names exist in the schema and throw an
                exception if a column name does not exist in the schema.

        Returns:
            The LazyFrame with the specified columns removed.

        Warning:
            `strict` argument is ignored for `polars<1.0.0`.

            Please consider upgrading to a newer version or pass to eager mode.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 2), (3, 4) df(a, b)")
            >>> nw.from_native(lf_native).drop("a").to_native()
            ┌───────┐
            │   b   │
            │ int32 │
            ├───────┤
            │     2 │
            │     4 │
            └───────┘
            <BLANKLINE>
        r   r  r  s      rY   r   zLazyFrame.dropg
  s(    < uww|WW--=f===rZ   r  )r  r  r?   c                   |dvrd| d}t          |          t          |t                    r|g}|                     | j                            ||                    S )u  Drop duplicate rows from this LazyFrame.

        Arguments:
            subset: Column name(s) to consider when identifying duplicate rows.
                     If set to `None`, use all columns.
            keep: {'any', 'none'}
                Which of the duplicate rows to keep.

                * 'any': Does not give any guarantee of which row is kept.
                * 'none': Don't keep duplicate rows.

        Returns:
            The LazyFrame with unique rows.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 1), (3, 4) df(a, b)")
            >>> nw.from_native(lf_native).unique("a").sort("a", descending=True)
            ┌──────────────────┐
            |Narwhals LazyFrame|
            |------------------|
            |┌───────┬───────┐ |
            |│   a   │   b   │ |
            |│ int32 │ int32 │ |
            |├───────┼───────┤ |
            |│     3 │     4 │ |
            |│     1 │     1 │ |
            |└───────┴───────┘ |
            └──────────────────┘
        >   r  r  z}narwhals.LazyFrame makes no assumptions about row order, so only 'any' and 'none' are supported for `keep` in `unique`. Got: r   )r   r  r  )rX   r   r  r   s       rY   r  zLazyFrame.unique
  s    J &&WOSW W W  S//!fc"" 	XF##!((T(BB
 
 	
rZ   r   r   r   c                    t          |          dk    r.t          |d         t                    r|sd}t          |           t	                      j        |i |S )u  Filter the rows in the LazyFrame based on a predicate expression.

        The original order of the remaining rows is preserved.

        Arguments:
            *predicates: Expression that evaluates to a boolean Series. Can
                also be a (single!) boolean list.
            **constraints: Column filters; use `name = value` to filter columns by the supplied value.
                Each constraint will behave the same as `nw.col(name).eq(value)`, and will be implicitly
                joined with the other filter conditions using &.

        Returns:
            The filtered LazyFrame.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> df_native = duckdb.sql('''
            ...     SELECT * FROM VALUES
            ...         (1, 6, 'a'),
            ...         (2, 7, 'b'),
            ...         (3, 8, 'c')
            ...     df(foo, bar, ham)
            ... ''')

            Filter on one condition

            >>> nw.from_native(df_native).filter(nw.col("foo") > 1).to_native()
            ┌───────┬───────┬─────────┐
            │  foo  │  bar  │   ham   │
            │ int32 │ int32 │ varchar │
            ├───────┼───────┼─────────┤
            │     2 │     7 │ b       │
            │     3 │     8 │ c       │
            └───────┴───────┴─────────┘
            <BLANKLINE>

            Filter on multiple conditions with implicit `&`

            >>> nw.from_native(df_native).filter(
            ...     nw.col("foo") < 3, nw.col("ham") == "a"
            ... ).to_native()
            ┌───────┬───────┬─────────┐
            │  foo  │  bar  │   ham   │
            │ int32 │ int32 │ varchar │
            ├───────┼───────┼─────────┤
            │     1 │     6 │ a       │
            └───────┴───────┴─────────┘
            <BLANKLINE>

            Filter on multiple conditions with `|`

            >>> nw.from_native(df_native).filter(
            ...     (nw.col("foo") == 1) | (nw.col("ham") == "c")
            ... ).to_native()
            ┌───────┬───────┬─────────┐
            │  foo  │  bar  │   ham   │
            │ int32 │ int32 │ varchar │
            ├───────┼───────┼─────────┤
            │     1 │     6 │ a       │
            │     3 │     8 │ c       │
            └───────┴───────┴─────────┘
            <BLANKLINE>

            Filter using `**kwargs` syntax

            >>> nw.from_native(df_native).filter(foo=2, ham="b").to_native()
            ┌───────┬───────┬─────────┐
            │  foo  │  bar  │   ham   │
            │ int32 │ int32 │ varchar │
            ├───────┼───────┼─────────┤
            │     2 │     7 │ b       │
            └───────┴───────┴─────────┘
            <BLANKLINE>
        r   r   zX`LazyFrame.filter` is not supported with Python boolean masks - use expressions instead.)r   r   r   r@  r  r   )rX   r   r   r   ra   s       rY   r   zLazyFrame.filter
  s[    ^ 
OOq  Z
1t%D%D [ lCC.. uww~z9[999rZ   .r  r
  r	  r  LazyGroupBy[Self]c                   d S rU   r   r  s      rY   r  zLazyFrame.group_by  	      CrZ   r  c                   d S rU   r   r  s      rY   r  zLazyFrame.group_by  r  rZ   Fc                  ddl m} t          |          }t          d |D                       r || ||          S ddlm ddlm t          fd|D                       }|r t          |          rd}t          |          fd	t          ||          D             } | j        | \  }}	t          d
 |	D                       sddlm}
 d} |
|           || ||          S )ue  Start a group by operation.

        Arguments:
            *keys: Column(s) to group by. Accepts expression input. Strings are parsed as
                column names.
            drop_null_keys: if True, then groups where any key is null won't be
                included in the result.

        Returns:
            Object which can be used to perform aggregations.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> df_native = duckdb.sql(
            ...     "SELECT * FROM VALUES (1, 'a'), (2, 'b'), (3, 'a') df(a, b)"
            ... )
            >>> df = nw.from_native(df_native)
            >>> df.group_by("b").agg(nw.col("a").sum()).sort("b").to_native()
            ┌─────────┬────────┐
            │    b    │   a    │
            │ varchar │ int128 │
            ├─────────┼────────┤
            │ a       │      4 │
            │ b       │      2 │
            └─────────┴────────┘
            <BLANKLINE>

            Expressions are also accepted.

            >>> df.group_by(nw.col("b").str.len_chars()).agg(
            ...     nw.col("a").sum()
            ... ).to_native()
            ┌───────┬────────┐
            │   b   │   a    │
            │ int64 │ int128 │
            ├───────┼────────┤
            │     1 │      6 │
            └───────┴────────┘
            <BLANKLINE>
        r   )r9   c              3  @   K   | ]}t          |t                    V  d S rU   r   r  s     rY   r   z%LazyFrame.group_by.<locals>.<genexpr>H  r  rZ   r  r   r5  c              3  8   K   | ]}t          |          V  d S rU   r  )r   r  r6  s     rY   r   z%LazyFrame.group_by.<locals>.<genexpr>N  s-      CCAJq$//CCCCCCrZ   z5drop_null_keys cannot be True when keys contains Exprc                4    g | ]\  }}|r|n
 |          S r   r   r  s      rY   r   z&LazyFrame.group_by.<locals>.<listcomp>T  s.    XXXjag)33q66XXXrZ   c              3  2   K   | ]}|t           j        u V  d S rU   r  r  s     rY   r   z%LazyFrame.group_by.<locals>.<genexpr>W  r  rZ   r   r"  )r#  r9   r   r   r$  r   r;  r6  r   r  rv   r   rr   r%  r!  )rX   r	  r
  r9   r&  key_is_exprr   r(  r)  r   r!  r6  r   s              @@rY   r  zLazyFrame.group_by  sg   X 	211111DMM	99y99999 	O;tY~NNNN      &&&&&&CCCCCCCCC 	+c+.. 	+IC%c***XXXXC	;<W<WXXX 9 95 ABBEBBBBB 	$888888 [  ,s###{4OOOOrZ   r   r   r   r   r   r   c               @     t                      j        |g|R ||dS )uI  Sort the LazyFrame by the given columns.

        Arguments:
            by: Column(s) names to sort by.
            *more_by: Additional columns to sort by, specified as positional arguments.
            descending: Sort in descending order. When sorting by multiple columns, can be
                specified per column by passing a sequence of booleans.
            nulls_last: Place null values last; can specify a single boolean applying to
                all columns or a sequence of booleans for per-column control.

        Returns:
            The sorted LazyFrame.

        Warning:
            Unlike Polars, it is not possible to specify a sequence of booleans for
            `nulls_last` in order to control per-column behaviour. Instead a single
            boolean is applied for all `by` columns.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> df_native = duckdb.sql(
            ...     "SELECT * FROM VALUES (1, 6.0, 'a'), (2, 5.0, 'c'), (NULL, 4.0, 'b') df(a, b, c)"
            ... )
            >>> df = nw.from_native(df_native)
            >>> df.sort("a")
            ┌──────────────────────────────────┐
            |        Narwhals LazyFrame        |
            |----------------------------------|
            |┌───────┬──────────────┬─────────┐|
            |│   a   │      b       │    c    │|
            |│ int32 │ decimal(2,1) │ varchar │|
            |├───────┼──────────────┼─────────┤|
            |│  NULL │          4.0 │ b       │|
            |│     1 │          6.0 │ a       │|
            |│     2 │          5.0 │ c       │|
            |└───────┴──────────────┴─────────┘|
            └──────────────────────────────────┘
        r   r+  r,  s        rY   r   zLazyFrame.sorta  s.    \ uww|BWWWZJWWWWrZ   r   r   r   r   r   r   r>   r   r   r   c               R    t                                          ||||||          S )u	  Add a join operation to the Logical Plan.

        Arguments:
            other: Lazy DataFrame to join with.
            on: Name(s) of the join columns in both DataFrames. If set, `left_on` and
                `right_on` should be None.
            how: Join strategy.

                  * *inner*: Returns rows that have matching values in both tables.
                  * *left*: Returns all rows from the left table, and the matched rows from the right table.
                  * *full*: Returns all rows in both dataframes, with the suffix appended to the right join keys.
                  * *cross*: Returns the Cartesian product of rows from both tables.
                  * *semi*: Filter rows that have a match in the right table.
                  * *anti*: Filter rows that do not have a match in the right table.
            left_on: Join column of the left DataFrame.
            right_on: Join column of the right DataFrame.
            suffix: Suffix to append to columns with a duplicate name.

        Returns:
            A new joined LazyFrame.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> df_native1 = duckdb.sql(
            ...     "SELECT * FROM VALUES (1, 'a'), (2, 'b') df(a, b)"
            ... )
            >>> df_native2 = duckdb.sql(
            ...     "SELECT * FROM VALUES (1, 'x'), (3, 'y') df(a, c)"
            ... )
            >>> df1 = nw.from_native(df_native1)
            >>> df2 = nw.from_native(df_native2)
            >>> df1.join(df2, on="a")
            ┌─────────────────────────────┐
            |     Narwhals LazyFrame      |
            |-----------------------------|
            |┌───────┬─────────┬─────────┐|
            |│   a   │    b    │    c    │|
            |│ int32 │ varchar │ varchar │|
            |├───────┼─────────┼─────────┤|
            |│     1 │ a       │ x       │|
            |└───────┴─────────┴─────────┘|
            └─────────────────────────────┘
        r.  r/  r0  s          rY   r   zLazyFrame.join  s2    l ww||sGh2f  
 
 	
rZ   r   r   r  r   r   r  r:   c               X    t                                          |||||||||		  	        S )u  Perform an asof join.

        This is similar to a left-join except that we match on nearest key rather than equal keys.

        For Polars, both DataFrames must be sorted by the `on` key (within each `by` group
        if specified).

        Arguments:
            other: DataFrame to join with.
            left_on: Name(s) of the left join column(s).
            right_on: Name(s) of the right join column(s).
            on: Join column of both DataFrames. If set, left_on and right_on should be None.
            by_left: join on these columns before doing asof join
            by_right: join on these columns before doing asof join
            by: join on these columns before doing asof join
            strategy: Join strategy. The default is "backward".

                  * *backward*: selects the last row in the right DataFrame whose "on" key is less than or equal to the left's key.
                  * *forward*: selects the first row in the right DataFrame whose "on" key is greater than or equal to the left's key.
                  * *nearest*: search selects the last row in the right DataFrame whose value is nearest to the left's key.

            suffix: Suffix to append to columns with a duplicate name.

        Returns:
            A new joined LazyFrame.

        Examples:
            >>> from datetime import datetime
            >>> import polars as pl
            >>> import narwhals as nw
            >>> data_gdp = {
            ...     "datetime": [
            ...         datetime(2016, 1, 1),
            ...         datetime(2017, 1, 1),
            ...         datetime(2018, 1, 1),
            ...         datetime(2019, 1, 1),
            ...         datetime(2020, 1, 1),
            ...     ],
            ...     "gdp": [4164, 4411, 4566, 4696, 4827],
            ... }
            >>> data_population = {
            ...     "datetime": [
            ...         datetime(2016, 3, 1),
            ...         datetime(2018, 8, 1),
            ...         datetime(2019, 1, 1),
            ...     ],
            ...     "population": [82.19, 82.66, 83.12],
            ... }
            >>> gdp_native = pl.DataFrame(data_gdp)
            >>> population_native = pl.DataFrame(data_population)
            >>> gdp = nw.from_native(gdp_native)
            >>> population = nw.from_native(population_native)
            >>> population.join_asof(gdp, on="datetime", strategy="backward").to_native()
            shape: (3, 3)
            ┌─────────────────────┬────────────┬──────┐
            │ datetime            ┆ population ┆ gdp  │
            │ ---                 ┆ ---        ┆ ---  │
            │ datetime[μs]        ┆ f64        ┆ i64  │
            ╞═════════════════════╪════════════╪══════╡
            │ 2016-03-01 00:00:00 ┆ 82.19      ┆ 4164 │
            │ 2018-08-01 00:00:00 ┆ 82.66      ┆ 4566 │
            │ 2019-01-01 00:00:00 ┆ 83.12      ┆ 4696 │
            └─────────────────────┴────────────┴──────┘
        r   r2  r3  s             rY   r  zLazyFrame.join_asof  sB    Z ww   ! 

 

 
	
rZ   c                    | S )zRestrict available API methods to lazy-only ones.

        This is a no-op, and exists only for compatibility with `DataFrame.lazy`.

        Returns:
            A LazyFrame.
        r   rW   s    rY   rr  zLazyFrame.lazy$  s	     rZ   r   r   c                p    d}t          |d           t                                          ||          S )a  Take every nth row in the DataFrame and return as a new DataFrame.

        Warning:
            `LazyFrame.gather_every` is deprecated and will be removed in a future version.
            Note: this will remain available in `narwhals.stable.v1`.
            See [stable api](../backcompat.md/) for more information.

        Arguments:
            n: Gather every *n*-th row.
            offset: Starting index.

        Returns:
            The LazyFrame containing only the selected rows.
        z`LazyFrame.gather_every` is deprecated and will be removed in a future version.

Note: this will remain available in `narwhals.stable.v1`.
See https://narwhals-dev.github.io/narwhals/backcompat/ for more information.
z1.29.0)_versionr   )r    r  r   )rX   r   r   r   ra   s       rY   r   zLazyFrame.gather_every.  s@     ^ 	
 	"#9999ww##a#777rZ   rY  r  rZ  r  r	  c               N    t                                          ||||          S )u  Unpivot a DataFrame from wide to long format.

        Optionally leaves identifiers set.

        This function is useful to massage a DataFrame into a format where one or more
        columns are identifier variables (index) while all other columns, considered
        measured variables (on), are "unpivoted" to the row axis leaving just
        two non-identifier columns, 'variable' and 'value'.

        Arguments:
            on: Column(s) to use as values variables; if `on` is empty all columns that
                are not in `index` will be used.
            index: Column(s) to use as identifier variables.
            variable_name: Name to give to the `variable` column. Defaults to "variable".
            value_name: Name to give to the `value` column. Defaults to "value".

        Returns:
            The unpivoted LazyFrame.

        Notes:
            If you're coming from pandas, this is similar to `pandas.DataFrame.melt`,
            but with `index` replacing `id_vars` and `on` replacing `value_vars`.
            In other frameworks, you might know this operation as `pivot_longer`.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> df_native = duckdb.sql(
            ...     "SELECT * FROM VALUES ('x', 1, 2), ('y', 3, 4), ('z', 5, 6) df(a, b, c)"
            ... )
            >>> df = nw.from_native(df_native)
            >>> df.unpivot(on=["b", "c"], index="a").sort("a", "variable").to_native()
            ┌─────────┬──────────┬───────┐
            │    a    │ variable │ value │
            │ varchar │ varchar  │ int32 │
            ├─────────┼──────────┼───────┤
            │ x       │ b        │     1 │
            │ x       │ c        │     2 │
            │ y       │ b        │     3 │
            │ y       │ c        │     4 │
            │ z       │ b        │     5 │
            │ z       │ c        │     6 │
            └─────────┴──────────┴───────┘
            <BLANKLINE>
        r  r\  r]  s        rY   r  zLazyFrame.unpivotF  s.    j wwm
  
 
 	
rZ   r  r  c                8     t                      j        |g|R  S )uJ  Explode the dataframe to long format by exploding the given columns.

        Notes:
            It is possible to explode multiple columns only if these columns have
            matching element counts.

        Arguments:
            columns: Column names. The underlying columns being exploded must be of the `List` data type.
            *more_columns: Additional names of columns to explode, specified as positional arguments.

        Returns:
            New LazyFrame

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> df_native = duckdb.sql(
            ...     "SELECT * FROM VALUES ('x', [1, 2]), ('y', [3, 4]), ('z', [5, 6]) df(a, b)"
            ... )
            >>> df = nw.from_native(df_native)
            >>> df.explode("b").to_native()
            ┌─────────┬───────┐
            │    a    │   b   │
            │ varchar │ int32 │
            ├─────────┼───────┤
            │ x       │     1 │
            │ x       │     2 │
            │ y       │     3 │
            │ y       │     4 │
            │ z       │     5 │
            │ z       │     6 │
            └─────────┴───────┘
            <BLANKLINE>
        r_  r`  s      rY   r  zLazyFrame.explode  s$    F uwww66666rZ   r  )rS   ro  ra  rc  rb  )r  rv  rS   r   rU   )rn  ro  r   r   rS   rx  )rS   rK   r  r  r  r  r  r   r!  r"  rd  r#  re  )r   r   r  r?   rS   r2   r$  )r
  rd   r	  r  rS   r  )r
  r   r	  r  rS   r  )r
  rd   r	  r   rS   r  r%  r&  r'  r*  rf  r(  r)  r+  r,  )%r-  r.  r/  rg  ri   r1  rq  rP  r_  rT  r  r|  r,   r   r   r   rx   r{   r   r   r   r   r   r   r   r  r   r   r  r   r   r  rr  r   r  r  rh  ri  s   @rY   rH  rH  }  s       
 
-@ -@ -@ -@^    X& & & &P P P P 5 5 5 X5$   
 CGJ
 J
 J
 J
 J
XC C C C.7 7 7 7 7 7@1 1 1 1 1 1 1B, , , , , , ,0      X( ( ( ( ( (      X*; *; *; *; *; *;X(5 (5 (5 (5 (5 (5T' ' ' ' ' '<      0        BF > > > > > > > >D *./
 (-	/
 /
 /
 /
 /
 /
bT: T: T: T: T: T:l UX          X        X 
 LQGP GP GP GP GP GPZ -2 .X .X .X .X .X .X .X .Xf &*#	8
 +/+/8
 8
 8
 8
 8
 8
 8
 8
| ##*.+/%)%/W
 W
 W
 W
 W
 W
 W
 W
r   8 8 8 8 8 8 84 &*7
 )-'!7
 7
 7
 7
 7
 7
 7
 7
r#7 #7 #7 #7 #7 #7 #7 #7 #7 #7rZ   rH  )h
__future__r   abcr   	itertoolsr   typingr   r   r   r	   r
   r   r   r   r   r   r   warningsr   narwhals._expression_parsingr   r   r   r   narwhals._utilsr   r   r   r   r   r   r   r   r   r   r    r!   r"   narwhals.dependenciesr#   r$   r%  r%   r&   r'   narwhals.schemar(   r<  r*   narwhals.translater,   ior-   pathlibr.   typesr/   pandaspdr7  plrg  rk  typing_extensionsr0   r1   r2   r3   narwhals._compliantr4   r5   narwhals._compliant.typingr6   r7   r#  r8   r9   narwhals.typingr:   r;   r<   r=   r>   r?   r@   _MultiColSelectorrA   _MultiIndexSelectorrB   rC   rD   rE   rF   rG   rH   rI   rK   rL   rM   r0  rO   r3  rH  r   rZ   rY   <module>r     s   " " " " " " "                                                                                    = < < < < < < <         
 # " " " " " " " " " " " ( ( ( ( ( (       IIIIIIIIIIIIJJJJJJJJNNNNNNNN66666666                               " 
4B
');
/
/
/		-	-	-W\999
GCLL>  > > > > B  B B B BvW vW vW vW vW  vW vW vWr	e7 e7 e7 e7 e7	*% e7 e7 e7P7e7 e7 e7 e7 e7	&! e7 e7 e7 e7 e7rZ   