L iDUddlmZddlmZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZddlmZddlmZmZmZddlmZmZmZmZdd lmZm 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,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2dd l3m4Z4m5Z5dd l6m7Z7m8Z8m9Z9dd l:m;Z;mZ>ddl?m@Z@ddlAmBZBe rddlCmDZDmEZEmFZFmGZGddlHmIZIddlJmKZKddlLmMZMddlNZOddlPZQddlRZSddlTmUZUmVZVmWZWmXZXddlYmZZZm[Z[ddl\m]Z]ddlm^Z^ddl_m`Z`ddlmaZambZbmcZcmdZdddlemfZfddlgmhZhmiZiddljmkZkmlZlmmZmmnZnmoZompZpmqZqmrZsmtZumvZvmwZwmxZxmyZymzZzm{Z{eVdZ|e Z}de~d <ed!d"#Zed$d%#Zed&d'#Zed(Zd)Zrde~d*<d+Ztde~d,<Gd-d.e eZGd/d0eeZGd1d2eeZy)3) annotations)abstractmethod)partial)chain) TYPE_CHECKINGAnyCallableClassVarGenericLiteralNoReturnTypeVarget_argsoverload) issue_warning)_parse_into_expr!check_expressions_preserve_lengthis_scalar_like)ArrowPandas_LazyAllowedImpl_LazyFrameCollectImpl)ImplementationVersion_Implementationcan_lazyframe_collectcheck_columns_existflatten generate_repris_compliant_dataframeis_compliant_lazyframeis_eager_allowedis_index_selector is_iteratoris_lazy_allowed is_list_ofis_sequence_like is_slice_none predicates_contains_list_of_boolqualified_type_namesupports_arrow_c_stream zip_strict)is_numpy_array_2dis_pyarrow_table)ColumnNotFoundErrorInvalidOperationErrorPerformanceWarning)_from_dict_no_backend_is_into_schema)SchemaSeries to_native)IterableIteratorMappingSequence)BytesIO)Path) ModuleTypeN) Concatenate ParamSpecSelf TypeAlias)CompliantDataFrameCompliantLazyFrame)CompliantExprAny) ExprMetadata)IntoArrowTable) EagerAllowed IntoBackend LazyAllowedPolars)DType)GroupBy LazyGroupBy)AsofJoinStrategy IntoDataFrameIntoExpr IntoFrame IntoLazyFrame IntoSchema JoinStrategyMultiColSelectorMultiIndexSelectorPivotAggSingleColSelectorSingleIndexSelectorSizeUnitUniqueKeepStrategy_2DArrayPSrC Incomplete_FrameTrS)bound LazyFrameTrT DataFrameTrQRz_MultiColSelector[Series[Any]]rWz _MultiIndexSelector[Series[Any]]rXceZdZUded<ded<eZded< eed(dZd)dZ d(d Z d*d Z d+d Z d,d Z d-d Zed.dZed/dZd/dZ d0dZd1dZed2dZ d3dZ d3dZd4dZd5dZd5dZd6dZ d7dZddd d8dZdd d9dZ d:d Zd;dd#Z!d?d$Z"d?d%Z#d@d&Z$y')A BaseFramer_compliant_frame&Literal['full', 'lazy', 'interchange']_levelrimplementationcyNselfs X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/narwhals/dataframe.py _compliantzBaseFrame._compliants!$c6|jjSrm)rh__native_namespace__ros rqruzBaseFrame.__native_namespace__s$$99;;rsc6|jjSrm)rh__narwhals_namespace__ros rqrwz BaseFrame.__narwhals_namespace__s$$;;==rsc<|j||jS)Nlevel) __class__rj)rpdfs rq_with_compliantzBaseFrame._with_compliants~~b ~44rscjg}|j}tt|jjdt fdt |Dfd|jD}|D]?}|j|}|j||j|jA|S)NF)backend allow_literalc3.K|] }|ywrmrn).0xparses rq z1BaseFrame._flatten_and_extract..s .!U1X .sc3RK|]\}}|j| ywrm)alias)rrexprrs rqrz1BaseFrame._flatten_and_extract..s$ M+%U4[  u % Ms$') rwrrrr_implementationrritems_to_compliant_exprappend_validate_metadata _metadata) rpexprs named_exprs out_exprsns all_exprsrcers @rq_flatten_and_extractzBaseFrame._flatten_and_extracts   ( ( * doo&E&EUZ  .wu~ . M9J9J9L M  2D((,B   R  # #BLL 1 2rsct|t|r |jSdt|dt|}t |)NzExpected `other` to be a , got: ) isinstancetyperhr* TypeErrorrpothermsgs rq_extract_compliant_framez"BaseFrame._extract_compliant_framesG eT$Z ()) ))*=d*C)FgNabgNhMklnrsc0t||jS)N) available)rcolumnsrpsubsets rq_check_columns_existzBaseFrame._check_columns_exists"6T\\BBrscyrmrnrpmetadatas rqrzBaseFrame._validate_metadata rsc\t|jjjSrm)r4rhschemarros rqrzBaseFrame.schemas"d++2288:;;rsc^t|jj}t|Srm)dictrhcollect_schemar4)rp native_schemas rqrzBaseFrame.collect_schemas&T22AACD m$$rsc||g|i|Srmrn)rpfunctionargskwargss rqpipezBaseFrame.pipes .t.v..rsct|tr|gn|}|j|jj |S)Nr)rstrr}rh drop_nullsrs rqrzBaseFrame.drop_nullss9'4&&##D$9$9$D$DF$D$STTrsc.|jjSrm)rhrros rqrzBaseFrame.columnss$$,,,rsc|j|i|}|Dcgc]}t|r|jn|!}}|j|jj |Scc}wrm)rr broadcastr}rh with_columns)rprrcompliant_exprscompliant_exprs rqrzBaseFrame.with_columnss4$33UJkJ #2  n-  $ $ &   ##$FD$9$9$F$F$XYY  s$A%cBtt|}|r=td|Dr+|s) |j|jj |S|j|i|}|r:td|Dr(|j|jj|S|Dcgc]}t|r|jn|!}}|j|jj|S#t $r}|j|x}r||d}~wwxYwcc}w)Nc3<K|]}t|tywrmrrrrs rqrz#BaseFrame.select..sEQjC0Ec32K|]}t|ywrm)rrs rqrz#BaseFrame.select..s"N>!#4"Ns) tuplerallr}rh simple_select Exceptionrr aggregaterrselect)rprr flat_exprseerrorrrs rqrzBaseFrame.selects:75>* #E*EEk ++7D))77D4$33ZO;O s"No"NN''(G(=(=(G(G(YZ Z #2  n-  $ $ &   ##$@D$9$9$@$@/$RSS  55jAA5AQ&   s'C4&$D4 D=DDcV|j|jj|Srm)r}rhrename)rpmappings rqrzBaseFrame.renames$##D$9$9$@$@$IJJrscV|j|jj|Srm)r}rhheadrpns rqrzBaseFrame.head$##D$9$9$>$>q$ABBrscV|j|jj|Srm)r}rhtailrs rqrzBaseFrame.tailrrscZ|j|jj||S)Nstrict)r}rhdrop)rprrs rqrzBaseFrame.drops)##D$9$9$>$>wv$>$VWWrsc ddlm}t|}|j}|j|}t |ddi|j|j Dcgc]\}}|||k(c}}} |jt|| ddi} |j|jj| Scc}}w)Nrcol function_namefilter ignore_nullsF) narwhals.functionsrrrwrrrall_horizontalrr}rhr) rp predicates constraintsrflat_predicatesplxcompliant_predicatesnamevcompliant_constraints predicates rqrzBaseFrame.filters +!*-))+8t88/J)+?XxX 9 9 9,7,=,=,? @qc$i1n @! 'C&& ')> ? NS ##D$9$9$@$@$KLL AsB; F descending nulls_lastctgt|g|}|j|jj|||dS)Nr)rr}rhsort)rpbyrrmore_bys rqrzBaseFrame.sortsL/wt}/w/ 0## &D ! ! & &zj Y  rsreversectt|g}|j|jj|||S)Nrr)rr}rhtop_k)rpkrr flatten_bys rqrzBaseFrame.top_ks=bT] ##  ! ! ' 'j' ' J  rschd}t|tr|gn|}t|tr|gn|}t|tr|gn|}|j}|j|}||vrd|d|d} t | |dk(r*||| d} t | |j ||dd|} n}|P||d|d } t | t|t|k7r d } t | |j |||||} n+||d |d } t | |j |||||} |j| S) N)innerleftfullcrossantisemiz2Only the following join strategies are supported: ; found ''.rz>Can not pass `left_on`, `right_on` or `on` keys for cross join)howleft_onright_onsuffixzGEither (`left_on` and `right_on`) or `on` keys should be specified for .z3`left_on` and `right_on` must have the same length.zBIf `on` is specified, `left_on` and `right_on` should be None for ) rrrhrNotImplementedError ValueErrorjoinlenr}) rpronrrrr_supported_joins compliantrresults rqr zBaseFrame.join#sNC(bTb)'377)W!+Hc!:H:)) --e4 & &FGWFXXabeaffhiC%c* * '>"h&:bnV o%^^3tF$FZ("2_`c_ddef o%7|s8},K o%^^3(6$F"h&:Z[^Z__`a o%^^3R$F##F++rscZ|j|jj||S)Nroffset)r}rh gather_every)rprrs rqrzBaseFrame.gather_everyQs.##  ! ! . .6 . B  rsc Jd} || vrd| d|d} t| ||| d} t| ||| d} t| ||||| d} t| ||| d} t| ||x}}||x}}t|tr|gn|}t|tr|gn|}t|tr4t|tr$t |t |k7r d } t| |j |jj|j||||||| S) N)backwardforwardnearestz-Only the following strategies are supported: rrzCEither (`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.)rrby_leftby_rightstrategyr) rr rrlistr r}rh join_asofr) rprrrr rrrrr_supported_strategiesrs rqrzBaseFrame.join_asofVs!C 0 0ABWAXXabjakkmnC%c* * JW_0@WCS/ ! N!48LRCS/ ! J _!5#(8Z S/ ! N!48LRCS/ ! >!# #Gh >!# #Gh)'377)W!+Hc!:H: w %*Xt*D LCM )GCS/ !##  ! ! + +--e4!!! ,   rsct|tr|gn|}t|tr|gn|}|j|jj ||||S)Nr index variable_name value_name)rrr}rhunpivot)rpr r r!r"s rqr#zBaseFrame.unpivots] C(bTb%eS1u##  ! ! ) )U-J *   rscd}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)rrs rq__neq__zBaseFrame.__neq__ + "#&&rscd}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)r%rs rq__eq__zBaseFrame.__eq__r'rsct|tr|g|ng||}|j|jj |S)Nr)rrr}rhexplode)rpr more_columns to_explodes rqr,zBaseFrame.explodesT'3' $| $*7*\*  ##D$9$9$A$A*$A$UVVrsN)returnr)r/r?)r|rr/rB)rIntoExpr | Iterable[IntoExpr]rrRr/zlist[CompliantExprAny])rz Self | Anyr/r)rz Sequence[str]r/zColumnNotFoundError | NonerrGr/Noner/r4rz"Callable[Concatenate[Self, PS], R]rzPS.argsrz PS.kwargsr/rerstr | list[str] | Noner/rBr/z list[str]rr0rrRr/rBrzdict[str, str]r/rBrintr/rB)rz Iterable[str]rboolr/rBrr0rrr/rB rstr | Iterable[str]rrrbool | Sequence[bool]rr<r/rBrr;rr?rr@r/rB)rr`r r6rrVrr6rr6rrr/rBrrr;rr;r/rB)rr`r str | NonerrDr rDrr6rr6rr6rrPrrr/rB r r6r r6r!rr"rr/rB)robjectr/r rstr | Sequence[str]r-rr/rB)%__name__ __module__ __qualname____annotations__rrkpropertyrrrrurwr}rrrrrrrrrrrrrrrrrrr rrr#r&r)r,rnrsrqrgrgks 22&5&7NO7($$<>53DL ( C  <<% /4// / /U-- Z3 ZDL Z  ZT3TDLT T4KCCXM8MILM M*-2      *      TY  0 ;P  ,,,, #,, ,, ( ,,),,,, ,,\ < <  <  <  < (< )<  #< #< <  < | " &        " ' 'Wrsrgc eZdZUdZej Zded<edmdZ edndZ edodZ dpdZ dqdZ e drd Ze dsd d  dtd Ze ds dud Ze ds dvdZdwdZdxdydZdzdZdsd{dZ dsd d d|dZd}dZd~dZddZedsddZeddZdsddZddZddZeddZddZ dddZ!edd Z"e dd!Z"e dd"Z" dd#Z"dd$Z#ed%d&dd'Z$edd(Z$ed)d& dd*Z$d)d& dd+Z$dd,Z% dfd- Z&dsdfd. Z' dd d/ dd0Z(edfd1 Z)dfd2 Z*edfd3 Z+ed4d5dd6Z,edd7Z,edd8Z,d4d5 dd9Z,dd:Z-ed%d%d; dd<Z.ed%d= dd>Z.ed%d= dd?Z.d4d@d; ddAZ. dfdB Z/ dfdC Z0dfdD Z1ddfdE Z2ddfdF Z3d)dGdfdHZ4 dsdId4d dJ ddKZ5 dfdL Z6ed%dM ddNZ7e ddOZ7d4dM ddPZ7d4d4dQ dfdRZ8d4dS dfdTZ9 dd d dUdV dfdWZ:d d d d d d dXdUdY dfdZZ;dd[Zdd^Z?dxdd_Z@dd`ZAddfda ZBd d d d d4dbdc dddZCddeZD dsd d4d df ddgZE dsd dhdidj dfdkZFdfdl ZGxZHS) 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), ) ``` zClassVar[Version]_versionc|jSrmrhros rqrrzDataFrame._compliant$$$rsctSrmr5ros rq_serieszDataFrame._seriess rsctSrm) LazyFrameros rq _lazyframezDataFrame._lazyframerscyrmrnrs rqrzDataFrame._validate_metadatarrsc||_|t|r|j|_ydt |}t |)NzCExpected an object which implements `__narwhals_dataframe__`, got: )rjr __narwhals_dataframe__rhrAssertionErrorrpr|rzrs rq__init__zDataFrame.__init__sD>C  !" %$&$=$=$?D !WX\]_X`WabC % %rsctt|s%t|sdt|d}t|t j |}t |rV|jjj |j}|jj||}||dS|d|d}t|)uConstruct a DataFrame from an object which supports the PyCapsule Interface. Arguments: native_frame: Object which implements `__arrow_c_stream__`. backend: specifies which eager backend instantiate to. `backend` can be specified in various ways - As `Implementation.` with `BACKEND` being `PANDAS`, `PYARROW`, `POLARS`, `MODIN` or `CUDF`. - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`. - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`. Examples: >>> import pandas as pd >>> import polars as pl >>> import narwhals as nw >>> >>> df_native = pd.DataFrame({"a": [1, 2], "b": [4.2, 5.1]}) >>> nw.DataFrame.from_arrow(df_native, backend="polars") ┌──────────────────┐ |Narwhals DataFrame| |------------------| | shape: (2, 2) | | ┌─────┬─────┐ | | │ a ┆ b │ | | │ --- ┆ --- │ | | │ i64 ┆ f64 │ | | ╞═════╪═════╡ | | │ 1 ┆ 4.2 │ | | │ 2 ┆ 5.1 │ | | └─────┴─────┘ | └──────────────────┘ zGiven object of type z% does not support PyCapsule interface)contextrryz support in Narwhals is lazy-only, but `DataFrame.from_arrow` is an eager-only function. Hint: you may want to use an eager backend and then call `.lazy`, e.g.: nw.DataFrame.from_arrow(df, backend='pyarrow').lazy('')) r+r.rrr from_backendr"rP namespacer _dataframe from_arrowr )cls native_framerrrkrrs rqrfzDataFrame.from_arrowsL( 59I,9W)$|*<)==bcCC. '44W= N +''44^DNNB 00r0JIy/ /HHVGWWY [ orsNrc6|t|\}}tj|}t|rW|jj j|j }|jj|||}||dS|d|d}t|)uInstantiate DataFrame from dictionary. Indexes (if present, for pandas-like backends) are aligned following the [left-hand-rule](../concepts/pandas_index.md/). Notes: For pandas-like dataframes, conversion to schema is applied after dataframe creation. Arguments: data: Dictionary to create DataFrame from. schema: The DataFrame schema as Schema or dict of {name: type}. If not specified, the schema will be inferred by the native library. If any `dtype` is `None`, the data type for that column will be inferred by the native library. backend: specifies which eager backend instantiate to. Only necessary if inputs are not Narwhals Series. `backend` can be specified in various ways - As `Implementation.` with `BACKEND` being `PANDAS`, `PYARROW`, `POLARS`, `MODIN` or `CUDF`. - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`. - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`. Examples: >>> import pandas as pd >>> import narwhals as nw >>> data = {"c": [5, 2], "d": [1, 4]} >>> nw.DataFrame.from_dict(data, backend="pandas") ┌──────────────────┐ |Narwhals DataFrame| |------------------| | c d | | 0 5 1 | | 1 2 4 | └──────────────────┘ rrarryz support in Narwhals is lazy-only, but `DataFrame.from_dict` is an eager-only function. Hint: you may want to use an eager backend and then call `.lazy`, e.g.: nw.DataFrame.from_dict({'a': [1, 2]}, backend='pyarrow').lazy('rb) r2rrcr"rPrdrre from_dictr rgdatarrrkrrrs rqrlzDataFrame.from_dict.s\ ?1$7MD''44W= N +''44^DNNB //VR/PIy/ /TTbScce g orsctj|}t|rW|jjj|j }|j j|||}||dS|d|d}t|)u Instantiate DataFrame from a sequence of dictionaries representing rows. Notes: For pandas-like dataframes, conversion to schema is applied after dataframe creation. Arguments: data: Sequence with dictionaries mapping column name to value. schema: The DataFrame schema as Schema or dict of {name: type}. If not specified, the schema will be inferred by the native library. If any `dtype` is `None`, the data type for that column will be inferred by the native library. backend: Specifies which eager backend instantiate to. `backend` can be specified in various ways - As `Implementation.` with `BACKEND` being `PANDAS`, `PYARROW`, `POLARS`, `MODIN` or `CUDF`. - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`. - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`. Tip: If you expect non-uniform keys in `data`, consider passing `schema` for more consistent results, as **inference varies between backends**: - pandas uses all rows - polars uses the first 100 rows - pyarrow uses only the first row Examples: >>> import polars as pl >>> import narwhals as nw >>> data = [ ... {"item": "apple", "weight": 80, "price": 0.60}, ... {"item": "egg", "weight": 55, "price": 0.40}, ... ] >>> nw.DataFrame.from_dicts(data, backend="polars") ┌──────────────────────────┐ | Narwhals DataFrame | |--------------------------| |shape: (2, 3) | |┌───────┬────────┬───────┐| |│ item ┆ weight ┆ price │| |│ --- ┆ --- ┆ --- │| |│ str ┆ i64 ┆ f64 │| |╞═══════╪════════╪═══════╡| |│ apple ┆ 80 ┆ 0.6 │| |│ egg ┆ 55 ┆ 0.4 │| |└───────┴────────┴───────┘| └──────────────────────────┘ rkrryz support in Narwhals is lazy-only, but `DataFrame.from_dicts` is an eager-only function. Hint: you may want to use an eager backend and then call `.lazy`, e.g.: nw.DataFrame.from_dicts([{'a': 1}, {'a': 2}], backend='pyarrow').lazy('rb) rrcr"rPrdrre from_dictsr rms rqrpzDataFrame.from_dictsksv(44W= N +''44^DNNB 00fb0QIy/ /^^l]mmo q orsctt|s d}t|t|sdt|d}t |t j |}t|rI|jjj |j}||j||dS|d|d}t|)uqConstruct a DataFrame from a NumPy ndarray. Notes: Only row orientation is currently supported. For pandas-like dataframes, conversion to schema is applied after dataframe creation. Arguments: data: Two-dimensional data represented as a NumPy ndarray. schema: The DataFrame schema as Schema, dict of {name: type}, or a sequence of str. backend: specifies which eager backend instantiate to. `backend` can be specified in various ways - As `Implementation.` with `BACKEND` being `PANDAS`, `PYARROW`, `POLARS`, `MODIN` or `CUDF`. - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`. - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`. Examples: >>> import numpy as np >>> import polars as pl >>> import narwhals as nw >>> >>> arr = np.array([[5, 2, 1], [1, 4, 3]]) >>> schema = {"c": nw.Int16(), "d": nw.Float32(), "e": nw.Int8()} >>> nw.DataFrame.from_numpy(arr, schema=schema, backend="polars") ┌───────────────────┐ |Narwhals DataFrame | |-------------------| |shape: (2, 3) | |┌─────┬─────┬─────┐| |│ c ┆ d ┆ e │| |│ --- ┆ --- ┆ --- │| |│ i16 ┆ f32 ┆ i8 │| |╞═════╪═════╪═════╡| |│ 5 ┆ 2.0 ┆ 1 │| |│ 1 ┆ 4.0 ┆ 3 │| |└─────┴─────┴─────┘| └───────────────────┘ z)`from_numpy` only accepts 2D numpy arrayszi`schema` is expected to be one of the following types: Mapping[str, DType] | Schema | Sequence[str]. Got rrryz support in Narwhals is lazy-only, but `DataFrame.from_numpy` is an eager-only function. Hint: you may want to use an eager backend and then call `.lazy`, e.g.: nw.DataFrame.from_numpy(arr, backend='pyarrow').lazy('rb) r-r r3rrrrcr"rPrdr from_numpy)rgrnrrrrkrs rqrrzDataFrame.from_numpysd!&=CS/ !v&F|nA'  C. '44W= N +''44^DNNBr}}T62&A AIIWHXXZ \ orsc6|jjSrm)rh__len__ros rqrtzDataFrame.__len__s$$,,..rsc<|jj||S)Ncopy)rh __array__)rpdtyperws rqrxzDataFrame.__array__s$$..u4.@@rscRtd|jjS)NzNarwhals DataFramerr8__repr__ros rqr|zDataFrame.__repr__ 14>>3C3L3L3NOOrsc~|jj}t|r|j|S tj j }|dkrdt|}t|d|j}|j|S#t$r}dt|}t||d}~wwxYw)ahExport 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. )requested_schemazT'pyarrow>=14.0.0' is required for `DataFrame.__arrow_c_stream__` for object of type N)r) rh _native_framer+__arrow_c_stream__rPYARROW_backend_versionModuleNotFoundErrorrto_arrow)rprrh pa_versionexcrpa_tables rqrzDataFrame.__arrow_c_stream__s,,:: "< 022DT2U U 4'//@@BJ  himnzi{h|}C%c* 4==?**` with `BACKEND` being `DASK`, `DUCKDB`, `IBIS` or `POLARS`. - As a string: `"dask"`, `"duckdb"`, `"ibis"` or `"polars"` - Directly as a module `dask.dataframe`, `duckdb`, `ibis` or `polars`. session: Session to be used if backend is spark-like. Examples: >>> import polars as pl >>> 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 | |-----------------------------| || └─────────────────────────────┘ 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 │ | |└───────┴───────┘ | └──────────────────┘ Nrlazyryz(Not-supported backend. Expected one of z or `None`, got ) rhrrXrrcr%rrr )rprrr lazy_backendrs rqrzDataFrame.lazysT$$)) ???4g#>f?M M%227; < (??4 g#Ff?U U:8DT;U:VVfgsftuorsc.|jjS)aConvert Narwhals DataFrame to native one. 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 )rhrros rqr8zDataFrame.to_nativems$$$222rsc6|jjS)aConvert this DataFrame to 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 )rh to_pandasros rqrzDataFrame.to_pandass $$..00rsc6|jjS)uConvert this DataFrame to 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 │ └─────┴─────┘ )rh to_polarsros rqrzDataFrame.to_polarss&$$..00rscyrmrnrpfiles rq write_csvzDataFrame.write_csvs36rscyrmrnrs rqrzDataFrame.write_csvs=@rsc8|jj|S)aWrite 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. 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() # doctest: +SKIP '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. )rhrrs rqrzDataFrame.write_csvs($$..t44rsc:|jj|y)aWrite dataframe to parquet file. Arguments: file: String, path object or file-like object to which the dataframe will be written. 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)rh write_parquetrs rqrzDataFrame.write_parquets ++D1rsc<|jjddS)aiConvert this DataFrame to a NumPy ndarray. 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. ]]) Nrv)rhto_numpyros rqrzDataFrame.to_numpys $$--d->>rsc.|jjS)aGet the shape of the DataFrame. 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) )rhshaperos rqrzDataFrame.shapes$$***rscn|j|jj||jS)a Get a single column by name. Arguments: name: The column name as a string. 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 ry)rUrh get_columnrj)rprs rqrzDataFrame.get_columns,.||D11<>> 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 )unit)rhestimated_size)rprs rqrzDataFrame.estimated_size s"$$333>>rscyrmrnrpitems rq __getitem__zDataFrame.__getitem__sWZrscyrmrnrs rqrzDataFrame.__getitem__!srscyrmrnrs rqrzDataFrame.__getitem__&srscddlm}dt|d}t|tr[t |dkDr d}t ||rt|drdn|d}t |dkst|drdn|d}|E|C|St|r|}d}n1t|st|ttfrd}|}n t |t|tr t ||j}t|ttfr]t|tr|j||St|tr|n|j|}|j!|} || |S| St||r |j"}t||r |j"}||j%|dd|fS||j%||ddfS|j%|||fS) 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'`. 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 rr5z2Unexpected 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, :]`?N)narwhals.seriesr6rrrr rr(r#r'slicerrhr;rrr_compliant_seriesr}) rprr6r tuple_msgrowsrrcol_nameseriess rqrzDataFrame.__getitem__1sv +Ad MN N  dE "4y1}U **#}T!W'=447D!$i!m}T!W/Ed4PQ7G| t $DG d #z$ 'EDGC. dC C. )) gSz *$$yyw//",Wc":w W@UH__X.F#'#36$< ? ? dF #))D gv &//G <'' !W*(=> > ?'' $'(:; ;##IdGm$<==rsc||jvSrmr+)rpkeys rq __contains__zDataFrame.__contains__sdll""rs. as_seriescyrmrnrprs rqto_dictzDataFrame.to_dictTWrscyrmrnrs rqrzDataFrame.to_dictsMPrsTcyrmrnrs rqrzDataFrame.to_dicts9>> 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']} rry)rhrrrUrj)rprrvalues rqrzDataFrame.to_dicts" #'"7"7"?"?'#@#%' CT\\%t{{\;;  $$,,y,AA s(A8c8|jj|S)akGet 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. 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) (, ) )rhrow)rpr s rqrz DataFrame.rows*$$((//rsc*t||g|i|S)avPipe function call. Arguments: function: Function to apply. args: Positional arguments to pass to function. kwargs: Keyword arguments to pass to function. 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 superrrprrrr{s rqrzDataFrame.pipes4w|H6t6v66rsc$t||S)aDrop rows that contain null values. Arguments: subset: Column name(s) for which null values are considered. If set to None (default), use all 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({"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]] rrrrprr{s rqrzDataFrame.drop_nullss0w!!00rsorder_byct|tr|gn|}|j|jj ||S)avInsert column which enumerates rows. Arguments: name: The name of the column as a string. The default is "index". order_by: Column(s) to order by when computing the row index. 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]] rrrr}rhwith_row_indexrprr order_by_s rqrzDataFrame.with_row_indexsB.#-Xs";XJ ##  ! ! 0 0 0 J  rsct|S)aNGet an ordered mapping of column names to their data type. 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}) )rrrpr{s rqrzDataFrame.schema.sw~rsc t|S)aXGet an ordered mapping of column names to their data type. 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}) rrrs rqrzDataFrame.collect_schema;w%''rsct|S)aGet 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).columns ['foo', 'bar'] rrrs rqrzDataFrame.columnsGwrsFnamedcyrmrnrprs rqrzDataFrame.rowsTsORrscyrmrnrs rqrzDataFrame.rowsWsEHrscyrmrnrs rqrzDataFrame.rowsZrrsc:|jj|S)a6Returns 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. 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)rhrrs rqrzDataFrame.rows]s"$$)))66rsc#K|jjD]!}|j||j#yw)uReturns 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| └─────────────────────────┘ ryN)rh iter_columnsrUrj)rprs rqrzDataFrame.iter_columnsps=8++88: :F,,vT[[,9 9 :sAAr buffer_sizecyrmrnrprrs rq iter_rowszDataFrame.iter_rowss%(rs)rcyrmrnrs rqrzDataFrame.iter_rowss$'rscyrmrnrs rqrzDataFrame.iter_rowss @Crsic<|jj||S)aReturns 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 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)rhrrs rqrzDataFrame.iter_rowss 4$$..U .TTrsc"t||i|S)a8Add 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. 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 )rrrprrr{s rqrzDataFrame.with_columnss@w#U:k::rsc"t||i|S)uXSelect 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. 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]] | └──────────────────┘ )rrrs rqrzDataFrame.selects:w~u4 44rsc"t||S)aRename column names. Arguments: mapping: Key value pairs that map from old name to new name. 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]] rrrprr{s rqrzDataFrame.renames$w~g&&rsc"t||S)aGet 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)`. 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 rrrprr{s rqrzDataFrame.headsw|Arsc"t||S)uGet 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)`. 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 | └──────────────────┘ )rrrs rqrzDataFrame.tail &w|Arsrc4t|t|d|iS)aRemove columns from the dataframe. 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 rrrrrprrr{s rqrzDataFrame.drop5s&w|WW-=f==rsanykeepmaintain_orderrc|dvrddd|}t|t|tr|g}|j|jj ||||S)aJDrop 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. order_by: Column(s) to order by when computing the row index. 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 >rlastnonefirst Expected rrrrrr)r rrr}rhunique)rprrrrrs rqrzDataFrame.uniqueJsrD 7 7<=WTFKCS/ ! fc "XF##  ! ! ( (T.8 )   rscVjfd|D}t|i|S)aFilter 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 boolean list(s). **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 &. 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 c3~K|]4}t|trjjd|n|6yw)riN)r&r<rU from_iterable)rpimplrps rqrz#DataFrame.filter..s@ @J!T?RDLL & &r1d & ;XY Y s:=)rkrr)rprrparsed_predicatesr r{s` @rqrzDataFrame.filterws8f""  w~0@K@@rsdrop_null_keyscyrmrnrpr keyss rqgroup_byzDataFrame.group_byrscyrmrnrs rqrzDataFrame.group_byrrsc ddlm}t|}td|Dr ||||Sddlm}ddlm ddlm t fd|D}|rt|r d }t|t||D cgc]\}} | r|n||} }} |j| } t| d d i||| |Scc} }w) aStart 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. 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)rNc3<K|]}t|tywrmrrrs rqrz%DataFrame.group_by..9z#s#9rr rExprr5c3:K|]}t|fywrmr)rrrr6s rqrz%DataFrame.group_by..s%WjT6N&C%Wsz?drop_null_keys cannot be True when keys contains Expr or SeriesrzDataFrame.group_by)narwhals.group_byrNrrnarwhalsr narwhals.exprrrr6rrrr,rr)rpr rrN flat_keysrkey_is_expr_or_seriesrris_expr_keysexpr_flat_keysrr6s @@rqrzDataFrame.group_bysr .DM 9y9 94>J J &* %%WY%W W c"78SC%c* *)4IJ 7Ac!f $  322E:)  +? t^NKK sB?rc,t||g|||dS)uSort 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. 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 | └──────────────────┘ rrrrprrrrr{s rqrzDataFrame.sorts!Hw|BWWZJWWrsrc(t||||S)u1Return the `k` largest rows. Non-null elements are always preferred over null elements, regardless of the value of reverse. The output is not guaranteed to be in any particular order, sort the outputs afterwards if you wish the output to be sorted. Arguments: k: Number of rows to return. by: Column(s) used to determine the top rows. Accepts expression input. Strings are parsed as column names. reverse: Consider the k smallest elements of the by column(s) (instead of the k largest). This can be specified per column by passing a sequence of booleans. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... {"a": ["a", "b", "a", "b", None, "c"], "b": [2, 1, 1, 3, 2, 1]} ... ) >>> nw.from_native(df_native).top_k(4, by=["b", "a"]) ┌──────────────────┐ |Narwhals DataFrame| |------------------| | a b | | 3 b 3 | | 0 a 2 | | 4 None 2 | | 5 c 1 | └──────────────────┘ rrrrprrrr{s rqrzDataFrame.top_k5s@w}Q2w}77rs_rightrrrc.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. 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 | └──────────────────┘ rrrr rrr rprr rrrrr{s rqr zDataFrame.joinWs)Tw| sGh2f  rsrrrr rrrrrc 4t ||||||||||  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". 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. 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/rr rprrrr rrrrrr{s rqrzDataFrame.join_asofs8Nw !  rsc$|jS)u]Get a mask of all duplicated rows in this DataFrame. 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_uniqueros rq is_duplicatedzDataFrame.is_duplicateds"   rsct|dk(S)a"Check if the dataframe is empty. 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 ros rqis_emptyzDataFrame.is_emptys4yA~rscl|j|jj|jS)uUGet a mask of all unique rows in this DataFrame. 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 | └───────────────┘ ry)rUrhr4rjros rqr4zDataFrame.is_uniques*"||D11;;=T[[|QQrsc|jj}|jj|jj }|j |S)ugCreate a new DataFrame that shows the null counts per column. 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]] | └──────────────────┘ )rhrwrr null_countr})rprrs rqr:zDataFrame.null_count sN.##::<&&--cggi.B.B.DE##F++rsc<|jj||S)aReturn 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). 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 )rcolumn)rhr)rprr<s rqrzDataFrame.item&s $$$))c&)AArscT|j|jjS)z Create a copy of this DataFrame.)r}rhcloneros rqr>zDataFrame.clone:s"##D$9$9$?$?$ABBrsc&t|||S)uTake every nth row in the DataFrame and return as a new DataFrame. Arguments: n: Gather every *n*-th row. offset: Starting index. 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)rr)rprrr{s rqrzDataFrame.gather_every>s*w#a#77rs_)r valuesaggregate_functionr sort_columns separatorc *|| d}t||d}t|tt|tr|gn|}t|tr|gn|}t|tr|gn|}|j |j j||||||S)uCreate 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. 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| └─────────────────────────────────┘ z3At 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.)r r rArBrCrD)r r UserWarningrrr}rhpivot) rpr r rArBrrCrDrs rqrGzDataFrame.pivotUsn >emGCS/ !  %7  #{ +C(bTb'4&&%eS1u##  ! ! ' '#5)# (   rsc6|jjS)aConvert to arrow 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]] )rhrros rqrzDataFrame.to_arrows$$--//rs)fractionwith_replacementseedc^|j|jj||||S)u'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. 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 | └──────────────────┘ )rrIrJrK)r}rhsample)rprrIrJrKs rqrMzDataFrame.samples<B##  ! ! ( (h9IPT )   rsvariablerr r!r"c*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". 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| └────────────────────┘ rrr#rpr r r!r"r{s rqr#zDataFrame.unpivots%^wm   rsc$t||g|S)u?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. 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 │ └─────┴─────┘ rr,rprr-r{s rqr,zDataFrame.explode s8ww666rs)r/z.CompliantDataFrame[Any, Any, DataFrameT, Self])r/ztype[Series[Any]])r/ztype[LazyFrame[Any]]r1r|rrzrir/r2)rhrHrIntoBackend[EagerAllowed]r/DataFrame[Any]rm)rnzMapping[str, Any]r.IntoSchema | Mapping[str, DType | None] | Nonerz IntoBackend[EagerAllowed] | Noner/rX)rnzSequence[Mapping[str, Any]]rrYrrWr/rX)rnr^rz!IntoSchema | Sequence[str] | NonerrWr/rX)r/r;)NN)ryrrw bool | Noner/r^r/r)rz object | Noner/rF)rzIntoBackend[LazyAllowed] | Nonerz Any | Noner/zLazyFrame[Any])r/rd)r/z pd.DataFrame)r/z pl.DataFrame)rr2r/rrzstr | Path | BytesIOr/r2)rzstr | Path | BytesIO | Noner/rD)r/r^)r/ztuple[int, int])rrr/ Series[Any])b)rr\r/z int | float)rz-tuple[SingleIndexSelector, SingleColSelector]r/r)rz2str | tuple[MultiIndexSelector, SingleColSelector]r/r])rzSingleIndexSelector | MultiIndexSelector | MultiColSelector | tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, MultiColSelector]r/rB)ra SingleIndexSelector | SingleColSelector | MultiColSelector | MultiIndexSelector | tuple[SingleIndexSelector, SingleColSelector] | tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, SingleColSelector] | tuple[MultiIndexSelector, MultiColSelector]r/zSeries[Any] | Self | Any)rrr/r<)r Literal[True]r/zdict[str, Series[Any]])rLiteral[False]r/zdict[str, list[Any]])rr<r/z-dict[str, Series[Any]] | dict[str, list[Any]])r r;r/ztuple[Any, ...]r4r5r )rrrstr | Sequence[str] | Noner/rBr3r7)rr`r/zlist[tuple[Any, ...]])rr_r/zlist[dict[str, Any]])rr<r/z,list[tuple[Any, ...]] | list[dict[str, Any]])r/zIterator[Series[Any]])rr`rr;r/zIterator[tuple[Any, ...]])rr_rr;r/zIterator[dict[str, Any]])rr<rr;r/z4Iterator[tuple[Any, ...]] | Iterator[dict[str, Any]]r8r9r:rr?rr<r/rB) rr6rr]rr<rrbr/rB)rz*IntoExpr | Iterable[IntoExpr] | list[bool]rrr/rB)rr0r r`r/ GroupBy[Self])rr?r r_r/rf)rr0r r<r/rfr>rANrrrBr r6rrVrr6rr6rrr/rBrrBrrDrrDr rDrr6rr6rr6rrPrrr/rB)r/r])r/r<r/rB)r int | Noner<zint | str | Noner/rrBrC)r zstr | list[str]r r6rAr6rBzPivotAgg | NonerrZrCr<rDrr/rB)r/zpa.Table) rrkrIz float | NonerJr<rKrkr/rBrErG)IrIrJrK__doc__rMAINrPrLrMrrrUrXrr_ classmethodrfrlrprrrtrxr|rrr8rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr rr5r7r4r:rr>rrGrrMr#r, __classcell__r{s@rqrOrOsh0#*,,H. %% &2)27P2 22hBF: 59 ::?: 2 :  ::xBFE)E?E + E  EEN59DD2D + D  DDL/APN248Q# Q0Q Q  Qf3(1$1*66 @@5,2 ? + +W2?*ZZ F   :    l> :l> "l>\#47WW PP #'< < 6<<$(B B 6B4007477 7 7816" MQ  0J  8   (  .3RR HH WW %77 57&:>),(&(;>( "((:='%'47' !''14CC+.C =CC %UU36U =U8 ;3 ;DL ;  ;D535DL5 5>'("*BF>.*.+ $)$/3 + &+ ! +  + - +  + Z8AE8AVY8A 8AtUX2DR (:G  LQRL2RLDHRL RLp-2 $X $X$X* $X  $X  $XNTY 8 80 8;P 8  8J&*# , +/+/, ,  #,  , ( , ), ,  , d##*.+/%)%/Q Q  Q  Q  Q (Q )Q  #Q #Q Q  Q h!& R&,6B(C86)-)-.2&*"M M & M ' M , M $M M M  M ^0&% "&!& % %  %  %  %  % R&*1 )-'! 1 "1 & 1  1  1  1 f77rsrOc eZdZdZed3dZed4dZd5dZd6dZd7dZ d8dZ d9 d:d Z d;d Z d<fd Z d9d=fd Z d> d?d Zed@fd Zd@fd ZedAfd Z dBfd Z dBfd ZdCfd ZdDdEfd ZdddFfdZ d9ddd dGdZ dHfd ZdIdZedd dJdZe dKd Zd!d dLd"Zd!d!d# dMfd$Zd!d% dNfd&Z dOddd'd( dPfd)Zddddddd*d'd+ dQfd,Z dRd-Z! d9dd.d/d0 dSfd1Z"dTfd2 Z#xZ$S)UrWaNarwhals 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) ``` c|jSrmrRros rqrrzLazyFrame._compliant; rSrsctSrm)rOros rqrezLazyFrame._dataframe? rYrscn|jdkDr d}t||jr d}t|y)NraOrder-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/.a1Length-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()) )n_orderable_opsr0 is_filtration)rprrs rqrzLazyFrame._validate_metadataC sN  # #a 'Z (, ,  ! !E (, , "rsc||_|t|r|j|_ydt |}t |)NzVExpected Polars LazyFrame or an object that implements `__narwhals_lazyframe__`, got: )rjr!__narwhals_lazyframe__rhrr]r^s rqr_zLazyFrame.__init__\ sD  !" %$&$=$=$?D !jkoprksjtuC % %rscRtd|jjS)NzNarwhals LazyFramer{ros rqr|zLazyFrame.__repr__e r}rscd}t|)Nz%Slicing is not supported on LazyFrame)r)rprrs rqrzLazyFrame.__getitem__h s5nrsNc |jj}||j|di|dStj|}t |r|j||fi|dSdt td|d}t|)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.` 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) 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]] | └──────────────────┘ rryz-Unsupported `backend` value. Expected one of z or None, got: rrm) rhcollectrerrcrrrr )rprrr| eager_backendrs rqr|zLazyFrame.collectl sx''// ???7#:6#:&?I I&33G<  /??7=#CF#C6?R R>xH]?^>__no|n}}~orsct|dS)u~Convert Narwhals LazyFrame to native one. 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 │ └───────┴───────┘ F)narwhals_object pass_throughr7ros rqr8zLazyFrame.to_native s"EBBrsc*t||g|i|S)uPipe function call. Arguments: function: Function to apply. args: Positional arguments to pass to function. kwargs: Keyword arguments to pass to function. 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 │ └───────┘ rrs rqrzLazyFrame.pipe s6w|H6t6v66rsc$t||S)uhDrop rows that contain null values. Arguments: subset: Column name(s) for which null values are considered. If set to None (default), use all columns. 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 │ | |└───────┴───────┘ | └──────────────────┘ rrrs rqrzLazyFrame.drop_nulls s6w!!00rsct|tr|gn|}|j|jj ||S)uInsert column which enumerates rows. Arguments: name: The name of the column as a string. The default is "index". order_by: Column(s) to order by when computing the row index. Examples: >>> import duckdb >>> import narwhals as nw >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 5), (2, 4) df(a, b)") >>> nw.from_native(lf_native).with_row_index(order_by="a").sort("a").collect() ┌──────────────────┐ |Narwhals DataFrame| |------------------| | pyarrow.Table | | index: int64 | | a: int32 | | b: int32 | | ---- | | index: [[0,1]] | | a: [[1,2]] | | b: [[5,4]] | └──────────────────┘ >>> nw.from_native(lf_native).with_row_index(order_by="b").sort("a").collect() ┌──────────────────┐ |Narwhals DataFrame| |------------------| | pyarrow.Table | | index: int64 | | a: int32 | | b: int32 | | ---- | | index: [[1,0]] | | a: [[1,2]] | | b: [[5,4]] | └──────────────────┘ rrrs rqrzLazyFrame.with_row_index sCP#-Xs";XJ ##  ! ! 0 0 0 J  rsc|jjtjurd}t |t t |S)aeGet an ordered mapping of column names to their data type. 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 # doctest:+SKIP Schema({'a': Int32, 'b': Decimal}) zResolving the schema of a LazyFrame is a potentially expensive operation. Use `LazyFrame.collect_schema()` to get the schema without this warning.)rhrPrV1rr1rr)rprr{s rqrzLazyFrame.schema, s?  ) ) ;[  #1 2w~rsc t|S)a^Get an ordered mapping of column names to their data type. 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}) rrs rqrzLazyFrame.collect_schema? rrsct|S)aGet 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).columns ['a', 'b'] rrs rqrzLazyFrame.columnsK rrscD|s|s d}t|t||i|S)uAdd 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. 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 rrrprrrr{s rqrzLazyFrame.with_columnsX s/H[TCS/ !w#U:k::rscD|s|s d}t|t||i|S)u1Select 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. 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 rrrs rqrzLazyFrame.select s.D[NCS/ !w~u4 44rsc"t||S)uRename 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. 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 │| |└───────┴──────────────┘| └────────────────────────┘ rrs rqrzLazyFrame.rename s2w~g&&rsc"t||S)uGet `n` rows. Arguments: n: Number of rows to return. 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 | └──────────────────┘ rrs rqrzLazyFrame.head rrsTrc4t|t|d|iS)uRemove 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. 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 │ └───────┘ rrrs rqrzLazyFrame.drop s6w|WW-=f==rsr)rrc|dvrddd|}t||dvr|s d}t|t|tr|g}|j |j j |||S)uDrop 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', 'first', 'last} Which of the duplicate rows to keep. * 'any': Does not give any guarantee of which row is kept. * 'none': Don't keep duplicate rows. * 'first': Keep the first row. Requires `order_by` to be specified. * 'last': Keep the last row. Requires `order_by` to be specified. order_by: Column(s) to order by when computing the row index. Examples: >>> import duckdb >>> import narwhals as nw >>> lf_native = duckdb.sql("SELECT * FROM VALUES (1, 3), (1, 4) df(a, b)") >>> nw.from_native(lf_native).unique("a").sort("a", descending=True) ┌──────────────────┐ |Narwhals LazyFrame| |------------------| |┌───────┬───────┐ | |│ a │ b │ | |│ int32 │ int32 │ | |├───────┼───────┤ | |│ 1 │ 3 │ | |└───────┴───────┘ | └──────────────────┘ >rrrrrrr>rrznarwhals.LazyFrame makes no assumptions about row order, so only 'first' and 'last' are only supported if `order_by` is passed.)rrr)r r0rrr}rhr)rprrrrs rqrzLazyFrame.unique sJ 7 7<=WTFKCS/ ! $ $XQ (, , fc "XF##  ! ! ( (TH ( U  rscvtd|D}t|r d}t|t||i|S)u7 Filter the rows in the LazyFrame based on a predicate expression. The original order of the remaining rows is preserved. Arguments: *predicates: Expression(s) that evaluates to a boolean Series. **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 &. 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 │ └───────┴───────┴─────────┘ 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 │ └───────┴───────┴─────────┘ 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 │ └───────┴───────┴─────────┘ 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 │ └───────┴───────┴─────────┘ c3LK|]}t|r t|n|ywrm)r$r)rrs rqrz#LazyFrame.filter..s sR! AE!HA=Rs"$zX`LazyFrame.filter` is not supported with Python boolean masks - use expressions instead.)rr)rrr)rprr predicates_rr{s rqrzLazyFrame.filter) sATRzRR +K 8lCC. w~{:k::rsc:|jj|y)aWrite LazyFrame to Parquet file. This may allow larger-than-RAM datasets to be written to disk. Arguments: file: String, path object or file-like object to which the dataframe will be written. Examples: >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.LazyFrame({"foo": [1, 2], "bar": [6.0, 7.0]}) >>> df = nw.from_native(df_native) >>> df.sink_parquet("out.parquet") # doctest:+SKIP N)rh sink_parquetrs rqrzLazyFrame.sink_parquetz s **40rs.r cyrmrnrs rqrzLazyFrame.group_by  rscyrmrnrs rqrzLazyFrame.group_by rrsFcz ddlm}t|}td|Dr ||||Sddlm}ddlm t fd|D}|rt|r d}t|t||D cgc]\}} | r|n||} }} |j| } t| d d i||| |Scc} }w) uStart 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. 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 │ └─────────┴────────┘ 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 │ └───────┴────────┘ r)rOc3<K|]}t|tywrmrrs rqrz%LazyFrame.group_by.. rrr rrc36K|]}t|ywrmr)rrrs rqrz%LazyFrame.group_by.. sCAJq$/Csz5drop_null_keys cannot be True when keys contains ExprrzLazyFrame.group_by)rrOrrrrrrrrrr,rr) rpr rrOrr key_is_exprrrr r!r"rs @rqrzLazyFrame.group_by sR 2DM 9y9 9tY~N N &CCC c+.IC%c* *8B)[7Y )3GAc!f $  322E:)  +? 4OO s9B7rc,t||g|||dS)uSort 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. 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 │| |└───────┴──────────────┴─────────┘| └──────────────────────────────────┘ rr$r%s rqrzLazyFrame.sort s!Vw|BWWZJWWrsrc(t||||S)uReturn the `k` largest rows. Non-null elements are always preferred over null elements, regardless of the value of reverse. The output is not guaranteed to be in any particular order, sort the outputs afterwards if you wish the output to be sorted. Arguments: k: Number of rows to return. by: Column(s) used to determine the top rows. Accepts expression input. Strings are parsed as column names. reverse: Consider the k smallest elements of the by column(s) (instead of the k largest). This can be specified per column by passing a sequence of booleans. Examples: >>> import duckdb >>> import narwhals as nw >>> df_native = duckdb.sql( ... "SELECT * FROM VALUES ('a', 2), ('b', 1), ('a', 1), ('b', 3), (NULL, 2), ('c', 1) df(a, b)" ... ) >>> df = nw.from_native(df_native) >>> df.top_k(4, by=["b", "a"]) ┌───────────────────┐ |Narwhals LazyFrame | |-------------------| |┌─────────┬───────┐| |│ a │ b │| |│ varchar │ int32 │| |├─────────┼───────┤| |│ b │ 3 │| |│ a │ 2 │| |│ NULL │ 2 │| |│ c │ 1 │| |└─────────┴───────┘| └───────────────────┘ rr'r(s rqrzLazyFrame.top_k sJw}Q2w}77rsr)r*c.t|||||||S)uAdd 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. 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-r.s rqr zLazyFrame.join, s)fw| sGh2f  rsrr/c 4t ||||||||||  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. 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/r1r2s rqrzLazyFrame.join_asofc s8Tw !  rsc|S)zRestrict available API methods to lazy-only ones. This is a no-op, and exists only for compatibility with `DataFrame.lazy`. rnros rqrzLazyFrame.lazy s  rsrNrrOc*t|||||S)uUnpivot 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". 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 │ └─────────┴──────────┴───────┘ rrQrRs rqr#zLazyFrame.unpivot s%dwm   rsc$t||g|S)uExplode 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. 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 │ └─────────┴───────┘ rTrUs rqr,zLazyFrame.explode s@ww666rs)r/z)CompliantLazyFrame[Any, LazyFrameT, Self])r/ztype[DataFrame[Any]]r1rVr[)rz str | slicer/r rm)rz+IntoBackend[Polars | Pandas | Arrow] | Nonerrr/rX)r/rcr4r5ra)rrrrHr/rBr3r7r8r9rcr:re)rr6rr]rrbr/rBr=r\)rr0r r`r/LazyGroupBy[Self])rr?r r_r/r)rr0r r<r/rr>rArgrhrirjrErG)%rIrJrKrlrMrrrerr_r|rr|r8rrrrrrrrrrrrrrrrrrr rrr#r,rorps@rqrWrW. s %%-2&P FJCBCUXC CJC(7477 7 7:1<"+ + 0C+ + Z$ (  ';3';DL'; ';R%53%5DL%5 %5N'6*BF>>*.2 $)/3 2 &2 ! 2 - 2  2 hO;8O;ILO; O;b1$UX 2 DR    ( :G   LQ@P2@PDH@P @PL-2 +X +X+X* +X  +X  +X\TY%8%80%8;P%8 %8T&*# 5 +/+/5 5  #5  5 ( 5 )5 5  5 v##*.+/%)%/T T  T  T  T (T )T  #T #T T  T l&*4 )-'! 4 "4 & 4  4  4  4 l 7 7rsrW) __future__rabcr functoolsr itertoolsrtypingrrr r r r r rrrnarwhals._exceptionsrnarwhals._expression_parsingrrrnarwhals._typingrrrrnarwhals._utilsrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,narwhals.dependenciesr-r.narwhals.exceptionsr/r0r1rr2r3narwhals.schemar4rr6narwhals.translater8collections.abcr9r:r;r<ior=pathlibr>typesr?pandaspdpolarsplpyarrowpatyping_extensionsr@rArBrCnarwhals._compliantrDrEnarwhals._compliant.typingrFrGnarwhals._translaterHrIrJrKrLnarwhals.dtypesrMrrNrOnarwhals.typingrPrQrRrSrTrUrVrW_MultiColSelectorrX_MultiIndexSelectorrYrZr[r\r]r^r_r`rLrarcrdrergrOrWrnrsrqrs\"   / TS,F F""(EE IIJ;92OO%6$ 4BJ  ); / \ 9 \ 9  CL>)> BIBWW WWt f7 *%f7R;h7 *%h7rs