Ë L iÑšãó¢—ddlmZddlZddlmZmZmZddlmZm Z m Z ddl m Z m Z mZddlmZmZmZmZddlmZddlmZmZdd lmZdd lmZdd lmZdd lm Z dd l!m"Z"ddl#m$Z$ddl%m&Z&erTddlm'Z'm(Z(ddl)m*Z*m+Z+m,Z,ddl-m.Z.m/Z/ddl0m1Z1ddlm2Z2ddl3m4Z4ddl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>m?Z?e+d«Z@e(d«ZAGd„d«ZBdgZCy)é)Ú annotationsN)ÚIterableÚMappingÚSequence)Ú TYPE_CHECKINGÚAnyÚCallable)ÚExprKindÚExprNodeÚevaluate_nodes)Ú_validate_rolling_argumentsÚ ensure_typeÚflattenÚ no_default)Ú_validate_dtype)Ú ComputeErrorÚInvalidOperationError©ÚExprCatNamespace©ÚExprDateTimeNamespace©ÚExprListNamespace©ÚExprNameNamespace©ÚExprStringNamespace©ÚExprStructNamespace)Ú to_native)ÚNoReturnÚTypeVar)Ú ConcatenateÚ ParamSpecÚSelf)Ú CompliantExprÚCompliantNamespace)Ú NoDefault)ÚDType)ÚSeries) ÚClosedIntervalÚFillNullStrategyÚ IntoDTypeÚIntoExprÚModeKeepStrategyÚNonNestedLiteralÚNumericLiteralÚ RankMethodÚRollingInterpolationMethodÚTemporalLiteralÚPSÚRcó —eZdZdwd„Z dxd„Zdyd„Zdyd„Zdzd„Zd{d„Zd|d„Z d}d„Z d~d „Z dd „Z d€d „Z dd „Zdd „Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Zd‚d„Z d‚d„Z!d‚d „Z"d‚d!„Z#d‚d"„Z$d‚d#„Z%d|d$„Z&d|d%„Z'd|d&„Z(d'd'd'd'd(d)d*d+œ dƒd,„Z)d|d-„Z*d|d.„Z+d)d/œd„d0„Z,d)d/œd„d1„Z- d…d*d2œ d†d3„Z.d|d4„Z/d|d5„Z0d|d6„Z1d|d7„Z2d|d8„Z3d|d9„Z4d|d:„Z5d|d;„Z6d|d<„Z7d*d=œd‡d>„Z8d|d?„Z9dˆd@„Z: d…e;d'dAœ d‰dB„Z< dŠ d‹dC„Z=d‚dD„Z>dŒdE„Z?d|dF„Z@d|dG„ZA d dŽdH„ZBddI„ZCd|dJ„ZDd'dKœ ddL„ZEd|dM„ZFd|dN„ZGd|dO„ZHd|dP„ZId|dQ„ZJ d‘dR„ZKd’d“dS„ZLd|dT„ZMd|dU„ZNd|dV„ZO d” d•dW„ZPd|dX„ZQd|dY„ZRdZd[œd–d\„ZSd|d]„ZTd*d=œd‡d^„ZUd*d=œd‡d_„ZVd*d=œd‡d`„ZWd*d=œd‡da„ZXd'd*dbœ d—dc„ZYd'd*dbœ d—dd„ZZd'd*d)deœ d˜df„Z[d'd*d)deœ d˜dg„Z\d™d*dhœdšdi„Z]e^j¾fd›dj„Z`d|dk„Zad|dl„Zbdmdnd*doœ dœdp„Zcedddq„«Zeeddždr„«ZfeddŸds„«Zgedd dt„«Zhedd¡du„«Ziedd¢dv„«Zjy')£ÚExprcó—||_y©N)Ú_nodes)ÚselfÚnodess úS/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/narwhals/expr.pyÚ__init__z Expr.__init__.s €Øˆ ócó.—t|j|«Sr:)r r;)r<Únss r>Ú_to_compliant_exprzExpr._to_compliant_expr1s€ô˜dŸk™k¨2Ó.Ð.r@có>—|jg|j¢|‘­ŽSr:)Ú __class__r;)r<Únodes r>Ú _append_nodezExpr._append_node6s€Øˆt~‰~Ð1˜tŸ{™{Ð1¨DÒ1Ð1r@có4—t|j«}|jj«Dcic]\}}||dk7r|ng“Œ}}}|jd i|¤Ž}t |«}|}|dkDre||dz x} j tjurA|dz}| j||«|dkDr%||dz x} j tjurŒA||k(r |j|«|j|ŽS|jdr(td„|d|D««r|j||«nV|jdr(td„|d|D««r|j||«ntd„|D««r d} t| «‚|j|ŽScc}}w) NÚorder_byréc3ó<K—|]}|j«–—Œy­wr:)Ú is_orderable©Ú.0rFs r>ú z'Expr._with_over_node..Ksèø€Ò*YÀ4¨4×+<Ñ+<×+>Ñ*Yùó‚Ú partition_byc3ó>K—|]}|j« –—Œy­wr:©Úis_elementwiserMs r>rOz'Expr._with_over_node..Ms!èø€ò1 Ø*.×#Ñ#Ó%Ô %ñ1 ùs‚c3ó<K—|]}|j«–—Œy­wr:rSrMs r>rOz'Expr._with_over_node..Qsèø€Ò=¨4×$Ñ$×&Ñ=ùrPz.Cannot apply `over` to elementwise expression.©)Úlistr;ÚkwargsÚitemsÚ _with_kwargsÚlenÚkindr Ú ELEMENTWISEÚ_push_down_over_node_in_placeÚappendrEÚanyÚinsertÚallr) r<rFÚ new_nodesÚkeyÚvalueÚkwargs_no_order_byÚnode_without_order_byÚnÚiÚ_nodeÚmsgs r>Ú_with_over_nodezExpr._with_over_node9sª€ô˜Ÿ™Ó%ˆ ð!%§ ¡ × 1Ñ 1Ó 3÷ áeð ˜# Ò+‘°Ñ 3ð Ðñ ð!2 × 1Ñ 1Ñ GÐ4FÑ GÐÜ  ‹NˆØ ˆØ!Še )¨A°©EÑ"2Ð2˜×8Ñ8¼Hב> 9Ð-Ð -Ø ;‰;zÒ "¤sÑ*YÈ9ÐUWÐVWÈ=Ô*YÔ'YØ × Ñ ˜Q Õ %Ø [‰[˜Ò (¬Sñ1 Ø2;¸B¸Q°-ô1 ô. ð × Ñ ˜QÐ 5Õ 6Ü Ñ=°9Ô=Ô =ØBˆCÜ'¨Ó,Ð ,؈t~‰~˜yÐ)Ð)ùó/ s³FcóF—djd„|jD««S)zCPretty-print the expression by combining all nodes in the metadata.ú.c3ó2K—|]}t|«–—Œy­wr:)ÚreprrMs r>rOz Expr.__repr__..Xsèø€Ò; tœ˜TŸ Ñ;ùs‚)Újoinr;©r<s r>Ú__repr__z Expr.__repr__Vs€àx‰xÑ;¨t¯{©{Ô;Ó;Ð;r@có6—dt|«›d}t|«‚)Nzthe truth value of a– is ambiguous You probably got here by using a Python standard library function instead of the native expressions API. Here are some things you might want to try: - instead of `nw.col('a') and nw.col('b')`, use `nw.col('a') & nw.col('b')` - instead of `nw.col('a') in [y, z]`, use `nw.col('a').is_in([y, z])` - instead of `max(nw.col('a'), nw.col('b'))`, use `nw.max_horizontal(nw.col('a'), nw.col('b'))` )ÚtypeÚ TypeError)r<rks r>Ú__bool__z Expr.__bool__Zs*€à!¤$ t£* ð.pð pð ô˜‹nÐr@có>—|j«j«Sr:)ÚabsÚsumrrs r>Ú _taxicab_normzExpr._taxicab_normgs€ðx‰x‹z~‰~ÓÐr@cóX—|jttjd|¬««S)u”Rename the expression. Arguments: name: The new name. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2], "b": [4, 5]}) >>> df = nw.from_native(df_native) >>> df.select((nw.col("b") + 10).alias("c")) ┌──────────────────┠|Narwhals DataFrame| |------------------| | c | | 0 14 | | 1 15 | └──────────────────┘ Úalias)Úname©rGr r r])r<r~s r>r}z Expr.aliasms$€ð(× Ñ ¤¬(×*>Ñ*>ÀÈdÔ!SÓTÐTr@có—||g|¢­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. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3, 4]}) >>> df = nw.from_native(df_native) >>> df.with_columns(a_piped=nw.col("a").pipe(lambda x: x + 1)) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a a_piped | | 0 1 2 | | 1 2 3 | | 2 3 4 | | 3 4 5 | └──────────────────┘ rV)r<ÚfunctionÚargsrXs r>Úpipez Expr.pipeƒs€ñ:˜Ð.˜tÒ. vÑ.Ð.r@cón—t|«|jttjd|¬««S)u Redefine an object's data type. Arguments: dtype: Data type that the object will be cast into. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"foo": [1, 2, 3], "bar": [6.0, 7.0, 8.0]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("foo").cast(nw.Float32), nw.col("bar").cast(nw.UInt8)) ┌──────────────────┠|Narwhals DataFrame| |------------------| | foo bar | | 0 1.0 6 | | 1 2.0 7 | | 2 3.0 8 | └──────────────────┘ Úcast)Údtype)rrGr r r])r<r†s r>r…z Expr.cast¢s,€ô* ˜ÔØ× Ñ ¤¬(×*>Ñ*>ÀÈeÔ!TÓUÐUr@có^—ttj||d¬«}|j|«S)NT)Ú str_as_lit©r r r]rG)r<ÚattrÚotherrFs r>Ú _with_binaryzExpr._with_binary»s)€Üœ×,Ñ,¨d°EÀdÔKˆØ× Ñ  Ó&Ð&r@có&—|jd|«S)NÚ__eq__©rŒ©r<r‹s r>rŽz Expr.__eq__¿ó€Ø× Ñ  ¨5Ó1Ð1r@có&—|jd|«S)NÚ__ne__rrs r>r“z Expr.__ne__Âr‘r@có&—|jd|«S)NÚ__and__rrs r>r•z Expr.__and__Åó€Ø× Ñ  ¨EÓ2Ð2r@có*—||zjd«S©NÚliteral©r}rs r>Ú__rand__z Expr.__rand__Èó€Øu‘ ×#Ñ# IÓ.Ð.r@có&—|jd|«S)NÚ__or__rrs r>ržz Expr.__or__Ër‘r@có*—||zjd«Sr˜ršrs r>Ú__ror__z Expr.__ror__Îrœr@có&—|jd|«S)NÚ__add__rrs r>r¢z Expr.__add__Ñr–r@có*—||zjd«Sr˜ršrs r>Ú__radd__z Expr.__radd__Ôrœr@có&—|jd|«S)NÚ__sub__rrs r>r¦z Expr.__sub__×r–r@có&—|jd|«S)NÚ__rsub__rrs r>r¨z Expr.__rsub__Úó€Ø× Ñ  ¨UÓ3Ð3r@có&—|jd|«S)NÚ __truediv__rrs r>r«zExpr.__truediv__Ýs€Ø× Ñ  °Ó6Ð6r@có&—|jd|«S)NÚ __rtruediv__rrs r>r­zExpr.__rtruediv__àó€Ø× Ñ  °Ó7Ð7r@có&—|jd|«S)NÚ__mul__rrs r>r°z Expr.__mul__ãr–r@có*—||zjd«Sr˜ršrs r>Ú__rmul__z Expr.__rmul__ærœr@có&—|jd|«S)NÚ__le__rrs r>r´z Expr.__le__ér‘r@có&—|jd|«S)NÚ__lt__rrs r>r¶z Expr.__lt__ìr‘r@có&—|jd|«S)NÚ__gt__rrs r>r¸z Expr.__gt__ïr‘r@có&—|jd|«S)NÚ__ge__rrs r>rºz Expr.__ge__òr‘r@có&—|jd|«S)NÚ__pow__rrs r>r¼z Expr.__pow__õr–r@có&—|jd|«S)NÚ__rpow__rrs r>r¾z Expr.__rpow__ør©r@có&—|jd|«S)NÚ __floordiv__rrs r>rÀzExpr.__floordiv__ûr®r@có&—|jd|«S)NÚ __rfloordiv__rrs r>rÂzExpr.__rfloordiv__þs€Ø× Ñ  °%Ó8Ð8r@có&—|jd|«S)NÚ__mod__rrs r>rÄz Expr.__mod__r–r@có&—|jd|«S)NÚ__rmod__rrs r>rÆz Expr.__rmod__r©r@cóT—|jttjd««S)NÚ __invert__rrrs r>rÈzExpr.__invert__s €Ø× Ñ ¤¬(×*>Ñ*>À Ó!MÓNÐNr@cóT—|jttjd««S)u¬Return whether any of the values in the column are `True`. If there are no non-null elements, the result is `False`. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [True, False], "b": [True, True]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").any()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 True True | └──────────────────┘ r`©rGr r Ú AGGREGATIONrrs r>r`zExpr.any ó"€ð$× Ñ ¤¬(×*>Ñ*>ÀÓ!FÓGÐGr@cóT—|jttjd««S)u¤Return whether all values in the column are `True`. If there are no non-null elements, the result is `True`. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [True, False], "b": [True, True]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").all()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 False True | └──────────────────┘ rbrÊrrs r>rbzExpr.allrÌr@NTrJF©ÚcomÚspanÚ half_lifeÚalphaÚadjustÚ min_samplesÚ ignore_nullsc ód—|jttjd|||||||¬« «S)u Compute exponentially-weighted moving average. Arguments: com: Specify decay in terms of center of mass, $\gamma$, with
$\alpha = \frac{1}{1+\gamma}\forall\gamma\geq0$ span: Specify decay in terms of span, $\theta$, with
$\alpha = \frac{2}{\theta + 1} \forall \theta \geq 1$ half_life: Specify decay in terms of half-life, $\tau$, with
$\alpha = 1 - \exp \left\{ \frac{ -\ln(2) }{ \tau } \right\} \forall \tau > 0$ alpha: Specify smoothing factor alpha directly, $0 < \alpha \leq 1$. adjust: Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings - When `adjust=True` (the default) the EW function is calculated using weights $w_i = (1 - \alpha)^i$ - When `adjust=False` the EW function is calculated recursively by $$ y_0=x_0 $$ $$ y_t = (1 - \alpha)y_{t - 1} + \alpha x_t $$ min_samples: Minimum number of observations in window required to have a value, (otherwise result is null). ignore_nulls: Ignore missing values when calculating weights. - When `ignore_nulls=False` (default), weights are based on absolute positions. For example, the weights of $x_0$ and $x_2$ used in calculating the final weighted average of $[x_0, None, x_2]$ are $(1-\alpha)^2$ and $1$ if `adjust=True`, and $(1-\alpha)^2$ and $\alpha$ if `adjust=False`. - When `ignore_nulls=True`, weights are based on relative positions. For example, the weights of $x_0$ and $x_2$ used in calculating the final weighted average of $[x_0, None, x_2]$ are $1-\alpha$ and $1$ if `adjust=True`, and $1-\alpha$ and $\alpha$ if `adjust=False`. Examples: >>> import pandas as pd >>> import polars as pl >>> import narwhals as nw >>> from narwhals.typing import IntoFrameT >>> >>> data = {"a": [1, 2, 3]} >>> df_pd = pd.DataFrame(data) >>> df_pl = pl.DataFrame(data) We define a library agnostic function: >>> def agnostic_ewm_mean(df_native: IntoFrameT) -> IntoFrameT: ... df = nw.from_native(df_native) ... return df.select( ... nw.col("a").ewm_mean(com=1, ignore_nulls=False) ... ).to_native() We can then pass either pandas or Polars to `agnostic_ewm_mean`: >>> agnostic_ewm_mean(df_pd) a 0 1.000000 1 1.666667 2 2.428571 >>> agnostic_ewm_mean(df_pl) # doctest: +NORMALIZE_WHITESPACE shape: (3, 1) ┌──────────┠│ a │ │ --- │ │ f64 │ ╞â•â•â•â•â•â•â•â•â•â•â•¡ │ 1.0 │ │ 1.666667 │ │ 2.428571 │ └──────────┘ Úewm_meanrΩrGr r ÚORDERABLE_WINDOW)r<rÏrÐrÑrÒrÓrÔrÕs r>r×z Expr.ewm_mean3sA€ðf× Ñ Ü Ü×)Ñ)ØØØØ#ØØØ'Ø)ô ó  ð r@cóT—|jttjd««S)u9Get mean value. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [-1, 0, 1], "b": [2, 4, 6]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").mean()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 0.0 4.0 | └──────────────────┘ ÚmeanrÊrrs r>rÛz Expr.mean”ó"€ð × Ñ ¤¬(×*>Ñ*>ÀÓ!GÓHÐHr@cóT—|jttjd««S)uÒGet median value. Notes: Results might slightly differ across backends due to differences in the underlying algorithms used to compute the median. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").median()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 3.0 4.0 | └──────────────────┘ ÚmedianrÊrrs r>rÞz Expr.median¦s"€ð&× Ñ ¤¬(×*>Ñ*>ÀÓ!IÓJÐJr@©ÚddofcóX—|jttjd|¬««S)u/Get standard deviation. Arguments: ddof: "Delta Degrees of Freedom": the divisor used in the calculation is N - ddof, where N represents the number of elements. By default ddof is 1. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [20, 25, 60], "b": [1.5, 1, -1.4]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").std(ddof=0)) ┌─────────────────────┠| Narwhals DataFrame | |---------------------| | a b| |0 17.79513 1.265789| └─────────────────────┘ ÚstdrßrÊ©r<ràs r>râzExpr.std»ó$€ð(× Ñ ¤¬(×*>Ñ*>ÀÈDÔ!QÓRÐRr@cóX—|jttjd|¬««S)u>Get variance. Arguments: ddof: "Delta Degrees of Freedom": the divisor used in the calculation is N - ddof, where N represents the number of elements. By default ddof is 1. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [20, 25, 60], "b": [1.5, 1, -1.4]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").var(ddof=0)) ┌───────────────────────┠| Narwhals DataFrame | |-----------------------| | a b| |0 316.666667 1.602222| └───────────────────────┘ ÚvarrßrÊrãs r>ræzExpr.varÑrär@)Úreturns_scalarc ó„—|rtjntj}|jt |d|||¬««S)u»Apply a custom python function to a whole Series or sequence of Series. The output of this custom function is presumed to be either a Series, or a NumPy array (in which case it will be automatically converted into a Series). Arguments: function: Function to apply to Series. return_dtype: Dtype of the output Series. If not set, the dtype will be inferred based on the first non-null value that is returned by the function. returns_scalar: If the function returns a scalar, by default it will be wrapped in a list in the output, since the assumption is that the function always returns something Series-like. If you want to keep the result as a scalar, set this argument to True. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("a", "b") ... .map_batches(lambda s: s.to_numpy() + 1, return_dtype=nw.Float64) ... .name.suffix("_mapped") ... ) ┌───────────────────────────┠| Narwhals DataFrame | |---------------------------| | a b a_mapped b_mapped| |0 1 4 2.0 5.0| |1 2 5 3.0 6.0| |2 3 6 4.0 7.0| └───────────────────────────┘ Ú map_batches)rÚ return_dtyperç)r ÚORDERABLE_AGGREGATIONÚORDERABLE_FILTRATIONrGr )r<rrêrçr\s r>rézExpr.map_batchesçsM€ñXô × *Ò *ä×.Ñ.ð ð × Ñ Ü ØØØ!Ø)Ø-ô  ó ð r@cóT—|jttjd««S)ubCalculate the sample skewness of a column. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3, 4, 5], "b": [1, 1, 2, 10, 100]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").skew()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 0.0 1.472427 | └──────────────────┘ ÚskewrÊrrs r>rîz Expr.skew rÜr@cóT—|jttjd««S)uLCompute the kurtosis (Fisher's definition) without bias correction. Kurtosis is the fourth central moment divided by the square of the variance. The Fisher's definition is used where 3.0 is subtracted from the result to give 0.0 for a normal distribution. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3, 4, 5], "b": [1, 1, 2, 10, 100]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").kurtosis()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 -1.3 0.210657 | └──────────────────┘ ÚkurtosisrÊrrs r>rðz Expr.kurtosis2s"€ð&× Ñ ¤¬(×*>Ñ*>À Ó!KÓLÐLr@cóT—|jttjd««S)uReturn the sum value. If there are no non-null elements, the result is zero. Examples: >>> import duckdb >>> import narwhals as nw >>> df_native = duckdb.sql("SELECT * FROM VALUES (5, 50), (10, 100) df(a, b)") >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").sum()) ┌───────────────────┠|Narwhals LazyFrame | |-------------------| |┌────────┬────────â”| |│ a │ b │| |│ int128 │ int128 │| |├────────┼────────┤| |│ 15 │ 150 │| |└────────┴────────┘| └───────────────────┘ rzrÊrrs r>rzzExpr.sumGs"€ð,× Ñ ¤¬(×*>Ñ*>ÀÓ!FÓGÐGr@cóT—|jttjd««S)uJReturns the minimum value(s) from a column(s). Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2], "b": [4, 3]}) >>> df = nw.from_native(df_native) >>> df.select(nw.min("a", "b")) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 1 3 | └──────────────────┘ ÚminrÊrrs r>rózExpr.min_ó"€ð × Ñ ¤¬(×*>Ñ*>ÀÓ!FÓGÐGr@cóT—|jttjd««S)uOReturns the maximum value(s) from a column(s). Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [10, 20], "b": [50, 100]}) >>> df = nw.from_native(df_native) >>> df.select(nw.max("a", "b")) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 20 100 | └──────────────────┘ ÚmaxrÊrrs r>rözExpr.maxqrôr@cóT—|jttjd««S)u[Returns the number of non-null elements in the column. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3], "b": [None, 4, 4]}) >>> df = nw.from_native(df_native) >>> df.select(nw.all().count()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 3 2 | └──────────────────┘ ÚcountrÊrrs r>røz Expr.countƒs"€ð × Ñ ¤¬(×*>Ñ*>ÀÓ!HÓIÐIr@cóT—|jttjd««S)uXReturns count of unique values. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3, 4, 5], "b": [1, 1, 3, 3, 5]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").n_unique()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 5 3 | └──────────────────┘ Ún_uniquerÊrrs r>rúz Expr.n_unique•s"€ð × Ñ ¤¬(×*>Ñ*>À Ó!KÓLÐLr@cóT—|jttjd««S)ueReturn unique values of this expression. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 1, 3, 5, 5], "b": [2, 4, 4, 6, 6]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").unique().sum()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 9 12 | └──────────────────┘ Úunique©rGr r Ú FILTRATIONrrs r>rüz Expr.unique§s"€ð × Ñ ¤¬(×*=Ñ*=¸xÓ!HÓIÐIr@cóT—|jttjd««S)u¦Return absolute value of each element. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, -2], "b": [-3, 4]}) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.col("a", "b").abs().name.suffix("_abs")) ┌─────────────────────┠| Narwhals DataFrame | |---------------------| | a b a_abs b_abs| |0 1 -3 1 3| |1 -2 4 2 4| └─────────────────────┘ ryrrrs r>ryzExpr.abs¹s"€ð"× Ñ ¤¬(×*>Ñ*>ÀÓ!FÓGÐGr@©ÚreversecóX—|jttjd|¬««S)uÙReturn cumulative sum. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: reverse: reverse the operation Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 1, 3, 5, 5], "b": [2, 4, 4, 6, 6]}) >>> df = nw.from_native(df_native) >>> df.with_columns(a_cum_sum=nw.col("a").cum_sum()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b a_cum_sum| |0 1 2 1| |1 1 4 2| |2 3 4 5| |3 5 6 10| |4 5 6 15| └──────────────────┘ Úcum_sumrrØ©r<rs r>rz Expr.cum_sumÌs)€ð6× Ñ Ü ”X×.Ñ.° À7Ô Kó ð r@cóT—|jttjd««S)uªReturns the difference between each element and the previous one. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Notes: pandas may change the dtype here, for example when introducing missing values in an integer column. To ensure, that the dtype doesn't change, you may want to use `fill_null` and `cast`. For example, to calculate the diff and fill missing values with `0` in a Int64 column, you could do: nw.col("a").diff().fill_null(0).cast(nw.Int64) Examples: >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame({"a": [1, 1, 3, 5, 5]}) >>> df = nw.from_native(df_native) >>> df.with_columns(a_diff=nw.col("a").diff()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | shape: (5, 2) | | ┌─────┬────────┠| | │ a ┆ a_diff │ | | │ --- ┆ --- │ | | │ i64 ┆ i64 │ | | ╞â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•¡ | | │ 1 ┆ null │ | | │ 1 ┆ 0 │ | | │ 3 ┆ 2 │ | | │ 5 ┆ 2 │ | | │ 5 ┆ 0 │ | | └─────┴────────┘ | └──────────────────┘ ÚdiffrØrrs r>rz Expr.diffës#€ðN× Ñ ¤¬(×*CÑ*CÀVÓ!LÓMÐMr@có|—t|td¬«|jttj d|¬««S)uÒShift values by `n` positions. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: n: Number of positions to shift values by. Notes: pandas may change the dtype here, for example when introducing missing values in an integer column. To ensure, that the dtype doesn't change, you may want to use `fill_null` and `cast`. For example, to shift and fill missing values with `0` in a Int64 column, you could do: nw.col("a").shift(1).fill_null(0).cast(nw.Int64) Examples: >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame({"a": [1, 1, 3, 5, 5]}) >>> df = nw.from_native(df_native) >>> df.with_columns(a_shift=nw.col("a").shift(n=1)) ┌──────────────────┠|Narwhals DataFrame| |------------------| |shape: (5, 2) | |┌─────┬─────────┠| |│ a ┆ a_shift │ | |│ --- ┆ --- │ | |│ i64 ┆ i64 │ | |╞â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•¡ | |│ 1 ┆ null │ | |│ 1 ┆ 1 │ | |│ 3 ┆ 1 │ | |│ 5 ┆ 3 │ | |│ 5 ┆ 5 │ | |└─────┴─────────┘ | └──────────────────┘ rh)Ú param_nameÚshift)rh)rÚintrGr r rÙ)r<rhs r>r z Expr.shifts2€ôT A”s sÕ+Ø× Ñ ¤¬(×*CÑ*CÀWÐPQÔ!RÓSÐSr@)Údefaultrêc óV—|€Ot|t«s d}t|«‚t|j ««}t|j ««}|t ur ttjd||||¬«}n ttjd||||d¬«}|j|«S)ul Replace all values by different values. Arguments: old: Sequence of values to replace. It also accepts a mapping of values to their replacement as syntactic sugar for `replace_strict(old=list(mapping.keys()), new=list(mapping.values()))`. new: Sequence of values to replace by. Length must match the length of `old`. default: Set values that were not replaced to this value. If no default is specified, (default), an error is raised if any values were not replaced. Accepts expression input. Non-expression inputs are parsed as literals. return_dtype: The data type of the resulting expression. If set to `None` (default), the data type is determined automatically based on the other inputs. Raises: InvalidOperationError: If any non-null values in the original column were not replaced, and no default was specified. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [3, 0, 1, 2]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... b=nw.col("a").replace_strict( ... [0, 1, 2, 3], ... ["zero", "one", "two", "three"], ... return_dtype=nw.String, ... ) ... ) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 3 three | | 1 0 zero | | 2 1 one | | 3 2 two | └──────────────────┘ Replace values and set a default for values not in the mapping: >>> data = {"a": [1, 2, 3, 4], "b": ["beluga", "narwhal", "orca", "vaquita"]} >>> df = nw.from_native(pd.DataFrame(data)) >>> df.with_columns( ... a_replaced=nw.col("a").replace_strict( ... {1: "one", 2: "two"}, ... default=nw.concat_str(nw.lit("default_"), nw.col("b")), ... return_dtype=nw.String, ... ) ... ) ┌──────────────────────────────┠| Narwhals DataFrame | |------------------------------| | a b a_replaced| |0 1 beluga one| |1 2 narwhal two| |2 3 orca default_orca| |3 4 vaquita default_vaquita| └──────────────────────────────┘ zB`new` argument is required if `old` argument is not a Mapping typeÚreplace_strict)r ÚoldÚnewrêT)rrrêrˆ) Ú isinstancerrvrWÚvaluesÚkeysrr r r]rG)r<rrr rêrkrFs r>r zExpr.replace_strictAs§€ðJ ˆ;ܘc¤7Ô+ØZÜ “nÐ$äs—z‘z“|Ó$ˆCÜs—x‘x“zÓ"ˆCà ”jÑ ÜÜ×$Ñ$Ø ØØØØ)ô ‰DôÜ×$Ñ$Ø ØØØØ)ØôˆDð× Ñ  Ó&Ð&r@có`—ttjd|||¬«}|j|«S)uJCheck if this expression is between the given lower and upper bounds. Arguments: lower_bound: Lower bound value. String literals are interpreted as column names. upper_bound: Upper bound value. String literals are interpreted as column names. closed: Define which sides of the interval are closed (inclusive). Options are {"left", "right", "none", "both"}. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3, 4, 5]}) >>> df = nw.from_native(df_native) >>> df.with_columns(b=nw.col("a").is_between(2, 4, "right")) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 1 False | | 1 2 False | | 2 3 True | | 3 4 True | | 4 5 False | └──────────────────┘ Ú is_between)Úclosedr‰)r<Ú lower_boundÚ upper_boundrrFs r>rzExpr.is_between¤s3€ô<Ü × Ñ  ,° ¸[ÐQWô ˆð× Ñ  Ó&Ð&r@c óÔ—t|t«rLt|ttf«s6|j t t jdt|d¬«¬««Sd}t|«‚)uCheck if elements of this expression are present in the other iterable. Arguments: other: iterable Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 9, 10]}) >>> df = nw.from_native(df_native) >>> df.with_columns(b=nw.col("a").is_in([1, 2])) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 1 True | | 1 2 True | | 2 9 False | | 3 10 False | └──────────────────┘ Úis_inT)Ú pass_through)r‹zyNarwhals `is_in` doesn't accept expressions as an argument, as opposed to Polars. You should provide an iterable instead.) rrÚstrÚbytesrGr r r]r ÚNotImplementedError)r<r‹rks r>rz Expr.is_inÇs_€ô, eœXÔ &¬z¸%Ä#ÄuÀÔ/NØ×$Ñ$ÜÜ×(Ñ(ØÜ# E¸Ô=ôóð ðJˆÜ! #Ó&Ð&r@cóV—|jttjdg|¢­Ž«S)u¹Filters elements based on a condition, returning a new expression. Arguments: predicates: Conditions to filter by (which get AND-ed together). Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... {"a": [2, 3, 4, 5, 6, 7], "b": [10, 11, 12, 13, 14, 15]} ... ) >>> df = nw.from_native(df_native) >>> df.select( ... nw.col("a").filter(nw.col("a") > 4), ... nw.col("b").filter(nw.col("b") < 13), ... ) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 3 5 10 | | 4 6 11 | | 5 7 12 | └──────────────────┘ Úfilterrý)r<Ú predicatess r>rz Expr.filterès'€ð4× Ñ ¤¬(×*=Ñ*=¸xÐ!UÈ*Ò!UÓVÐVr@cóT—|jttjd««S)u×Returns a boolean Series indicating which values are null. 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 >>> df_native = duckdb.sql( ... "SELECT * FROM VALUES (null, CAST('NaN' AS DOUBLE)), (2, 2.) df(a, b)" ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_is_null=nw.col("a").is_null(), b_is_null=nw.col("b").is_null() ... ) ┌──────────────────────────────────────────┠| Narwhals LazyFrame | |------------------------------------------| |┌───────┬────────┬───────────┬───────────â”| |│ a │ b │ a_is_null │ b_is_null │| |│ int32 │ double │ boolean │ boolean │| |├───────┼────────┼───────────┼───────────┤| |│ NULL │ nan │ true │ false │| |│ 2 │ 2.0 │ false │ false │| |└───────┴────────┴───────────┴───────────┘| └──────────────────────────────────────────┘ Úis_nullrrrs r>r"z Expr.is_nulls"€ð:× Ñ ¤¬(×*>Ñ*>À Ó!JÓKÐKr@cóT—|jttjd««S)uIndicate which values are NaN. 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 >>> df_native = duckdb.sql( ... "SELECT * FROM VALUES (null, CAST('NaN' AS DOUBLE)), (2, 2.) df(a, b)" ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_is_nan=nw.col("a").is_nan(), b_is_nan=nw.col("b").is_nan() ... ) ┌────────────────────────────────────────┠| Narwhals LazyFrame | |----------------------------------------| |┌───────┬────────┬──────────┬──────────â”| |│ a │ b │ a_is_nan │ b_is_nan │| |│ int32 │ double │ boolean │ boolean │| |├───────┼────────┼──────────┼──────────┤| |│ NULL │ nan │ NULL │ true │| |│ 2 │ 2.0 │ false │ false │| |└───────┴────────┴──────────┴──────────┘| └────────────────────────────────────────┘ Úis_nanrrrs r>r$z Expr.is_nan#s"€ð:× Ñ ¤¬(×*>Ñ*>ÀÓ!IÓJÐJr@có—|| d}t|«‚|€|€ d}t|«‚||dvrd|›}t|«‚|ttjd|||¬«}nttjd|||d¬«}|j |«S) u¸Fill null values with given value. Arguments: value: Value or expression used to fill null values. strategy: Strategy used to fill null values. limit: Number of consecutive null values to fill when using the 'forward' or 'backward' strategy. Notes: - pandas handles null values differently from other libraries. See [null_handling](../concepts/null_handling.md/) for reference. - For pandas Series of `object` dtype, `fill_null` will not automatically change the Series' dtype as pandas used to do. Explicitly call `cast` if you want the dtype to change. Examples: >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame( ... { ... "a": [2, None, None, 3], ... "b": [2.0, float("nan"), float("nan"), 3.0], ... "c": [1, 2, 3, 4], ... } ... ) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("a", "b").fill_null(0).name.suffix("_filled"), ... nw.col("a").fill_null(nw.col("c")).name.suffix("_filled_with_c"), ... ) ┌────────────────────────────────────────────────────────────┠| Narwhals DataFrame | |------------------------------------------------------------| |shape: (4, 6) | |┌──────┬─────┬─────┬──────────┬──────────┬─────────────────â”| |│ a ┆ b ┆ c ┆ a_filled ┆ b_filled ┆ a_filled_with_c │| |│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │| |│ i64 ┆ f64 ┆ i64 ┆ i64 ┆ f64 ┆ i64 │| |╞â•â•â•â•â•â•╪â•â•â•â•â•╪â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡| |│ 2 ┆ 2.0 ┆ 1 ┆ 2 ┆ 2.0 ┆ 2 │| |│ null ┆ NaN ┆ 2 ┆ 0 ┆ NaN ┆ 2 │| |│ null ┆ NaN ┆ 3 ┆ 0 ┆ NaN ┆ 3 │| |│ 3 ┆ 3.0 ┆ 4 ┆ 3 ┆ 3.0 ┆ 3 │| |└──────┴─────┴─────┴──────────┴──────────┴─────────────────┘| └────────────────────────────────────────────────────────────┘ Using a strategy: >>> df.select( ... nw.col("a", "b"), ... nw.col("a", "b") ... .fill_null(strategy="forward", limit=1) ... .name.suffix("_nulls_forward_filled"), ... ) ┌────────────────────────────────────────────────────────────────┠| Narwhals DataFrame | |----------------------------------------------------------------| |shape: (4, 4) | |┌──────┬─────┬────────────────────────┬────────────────────────â”| |│ a ┆ b ┆ a_nulls_forward_filled ┆ b_nulls_forward_filled │| |│ --- ┆ --- ┆ --- ┆ --- │| |│ i64 ┆ f64 ┆ i64 ┆ f64 │| |╞â•â•â•â•â•â•╪â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡| |│ 2 ┆ 2.0 ┆ 2 ┆ 2.0 │| |│ null ┆ NaN ┆ 2 ┆ NaN │| |│ null ┆ NaN ┆ null ┆ NaN │| |│ 3 ┆ 3.0 ┆ 3 ┆ 3.0 │| |└──────┴─────┴────────────────────────┴────────────────────────┘| └────────────────────────────────────────────────────────────────┘ z*cannot specify both `value` and `strategy`z0must specify either a fill `value` or `strategy`>ÚforwardÚbackwardzstrategy not supported: Ú fill_null)reÚstrategyÚlimitT)r)r*rˆ)Ú ValueErrorr r rÙr]rG)r<rer)r*rkrFs r>r(zExpr.fill_nullBs¸€ðV Ð  Ð!5Ø>ˆCܘS“/Ð !Ø ˆ=˜XÐ-ØDˆCܘS“/Ð !Ø Ð  HÐ4KÑ$KØ,¨X¨JÐ7ˆCܘS“/Ð !à Ð ÜÜ×)Ñ)ØØØ!Øô ‰DôÜ×$Ñ$ØØØ!ØØô ˆDð× Ñ  Ó&Ð&r@cóX—|jttjd|¬««S)uâFill floating point NaN values with given value. Arguments: value: Value used to fill NaN values. Notes: This function only fills `'NaN'` values, not null ones, except for pandas which doesn't distinguish between them. See [null_handling](../concepts/null_handling.md/) for reference. Examples: >>> import duckdb >>> import narwhals as nw >>> df_native = duckdb.sql( ... "SELECT * FROM VALUES (5.::DOUBLE, 50.::DOUBLE), ('NaN', null) df(a, b)" ... ) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.col("a", "b").fill_nan(0).name.suffix("_nans_filled")) ┌───────────────────────────────────────────────────┠| Narwhals LazyFrame | |---------------------------------------------------| |┌────────┬────────┬───────────────┬───────────────â”| |│ a │ b │ a_nans_filled │ b_nans_filled │| |│ double │ double │ double │ double │| |├────────┼────────┼───────────────┼───────────────┤| |│ 5.0 │ 50.0 │ 5.0 │ 50.0 │| |│ nan │ NULL │ 0.0 │ NULL │| |└────────┴────────┴───────────────┴───────────────┘| └───────────────────────────────────────────────────┘ Úfill_nan)rer)r<res r>r-z Expr.fill_nanªs%€ð>× Ñ ¤¬(×*>Ñ*>À ÐRWÔ!XÓYÐYr@cóT—|jttjd««S)uˆDrop null values. Notes: pandas handles null values differently from Polars and PyArrow. See [null_handling](../concepts/null_handling.md/) for reference. Examples: >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame({"a": [2.0, 4.0, float("nan"), 3.0, None, 5.0]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a").drop_nulls()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | shape: (5, 1) | | ┌─────┠| | │ a │ | | │ --- │ | | │ f64 │ | | ╞â•â•â•â•â•â•¡ | | │ 2.0 │ | | │ 4.0 │ | | │ NaN │ | | │ 3.0 │ | | │ 5.0 │ | | └─────┘ | └──────────────────┘ Ú drop_nullsrýrrs r>r/zExpr.drop_nullsÌs"€ð<× Ñ ¤¬(×*=Ñ*=¸|Ó!LÓMÐMr@)rIcóÈ—t|«}t|t«r|gn|xsg}|s|s d}t|«‚t t j d||¬«}|j|«S)u›Compute expressions over the given groups (optionally with given order). Arguments: partition_by: Names of columns to compute window expression over. Must be names of columns, as opposed to expressions - so, this is a bit less flexible than Polars' `Expr.over`. order_by: Column(s) to order window functions by. For lazy backends, this argument is required when `over` is applied to order-dependent functions, see [order-dependence](../concepts/order_dependence.md). Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 4], "b": ["x", "x", "y"]}) >>> df = nw.from_native(df_native) >>> df.with_columns(a_min_per_group=nw.col("a").min().over("b")) ┌────────────────────────┠| Narwhals DataFrame | |------------------------| | a b a_min_per_group| |0 1 x 1| |1 2 x 1| |2 4 y 4| └────────────────────────┘ Cumulative operations are also supported, but (currently) only for pandas and Polars: >>> df.with_columns(a_cum_sum_per_group=nw.col("a").cum_sum().over("b")) ┌────────────────────────────┠| Narwhals DataFrame | |----------------------------| | a b a_cum_sum_per_group| |0 1 x 1| |1 2 x 3| |2 4 y 4| └────────────────────────────┘ z?At least one of `partition_by` or `order_by` must be specified.Úover)rQrI)rrrr+r r ÚOVERrl)r<rIrQÚflat_partition_byÚ flat_order_byrkrFs r>r1z Expr.overìsf€ôV$ LÓ1ÐÜ&0°¼3Ô&?˜™ ÀhÂnÐRTˆ Ù ©ØSˆCܘS“/Ð !ÜÜ M‰M˜6Ð0AÈMô ˆð×#Ñ# DÓ)Ð)r@cóT—|jttjd««S)uReturn a boolean mask indicating duplicated values. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3, 1], "b": ["a", "a", "b", "c"]}) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.all().is_duplicated().name.suffix("_is_duplicated")) ┌─────────────────────────────────────────┠| Narwhals DataFrame | |-----------------------------------------| | a b a_is_duplicated b_is_duplicated| |0 1 a True True| |1 2 a False True| |2 3 b False False| |3 1 c True False| └─────────────────────────────────────────┘ Ú is_duplicated©rGr r ÚWINDOWrrs r>r6zExpr.is_duplicated!s €ð&× Ñ ¤¬(¯/©/¸?Ó!KÓLÐLr@cóT—|jttjd««S)u©Return a boolean mask indicating unique values. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3, 1], "b": ["a", "a", "b", "c"]}) >>> df = nw.from_native(df_native) >>> df.with_columns(nw.all().is_unique().name.suffix("_is_unique")) ┌─────────────────────────────────┠| Narwhals DataFrame | |---------------------------------| | a b a_is_unique b_is_unique| |0 1 a False False| |1 2 a True False| |2 3 b True True| |3 1 c False True| └─────────────────────────────────┘ Ú is_uniquer7rrs r>r:zExpr.is_unique6s €ð&× Ñ ¤¬(¯/©/¸;Ó!GÓHÐHr@cóT—|jttjd««S)uCount null values. Notes: pandas handles null values differently from Polars and PyArrow. See [null_handling](../concepts/null_handling.md/) for reference. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... {"a": [1, 2, None, 1], "b": ["a", None, "b", None]} ... ) >>> df = nw.from_native(df_native) >>> df.select(nw.all().null_count()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 1 2 | └──────────────────┘ Ú null_countrÊrrs r>r<zExpr.null_countKs"€ð,× Ñ ¤¬(×*>Ñ*>À Ó!MÓNÐNr@cóT—|jttjd««S)uŠReturn a boolean mask indicating the first occurrence of each distinct value. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3, 1], "b": ["a", "a", "b", "c"]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.all().is_first_distinct().name.suffix("_is_first_distinct") ... ) ┌─────────────────────────────────────────────────┠| Narwhals DataFrame | |-------------------------------------------------| | a b a_is_first_distinct b_is_first_distinct| |0 1 a True True| |1 2 a True False| |2 3 b True True| |3 1 c False True| └─────────────────────────────────────────────────┘ Úis_first_distinctrØrrs r>r>zExpr.is_first_distinctcs#€ð2× Ñ ¤¬(×*CÑ*CÐEXÓ!YÓZÐZr@cóT—|jttjd««S)umReturn a boolean mask indicating the last occurrence of each distinct value. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3, 1], "b": ["a", "a", "b", "c"]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.all().is_last_distinct().name.suffix("_is_last_distinct") ... ) ┌───────────────────────────────────────────────┠| Narwhals DataFrame | |-----------------------------------------------| | a b a_is_last_distinct b_is_last_distinct| |0 1 a False False| |1 2 a True True| |2 3 b True True| |3 1 c True True| └───────────────────────────────────────────────┘ Úis_last_distinctrØrrs r>r@zExpr.is_last_distinct~s#€ð2× Ñ ¤¬(×*CÑ*CÐEWÓ!XÓYÐYr@cóZ—|jttjd||¬««S)uØGet quantile value. Arguments: quantile: Quantile between 0.0 and 1.0. interpolation: Interpolation method. Note: - pandas and Polars may have implementation differences for a given interpolation method. - [dask](https://docs.dask.org/en/stable/generated/dask.dataframe.Series.quantile.html) has its own method to approximate quantile and it doesn't implement 'nearest', 'higher', 'lower', 'midpoint' as interpolation method - use 'linear' which is closest to the native 'dask' - method. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame( ... {"a": list(range(50)), "b": list(range(50, 100))} ... ) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a", "b").quantile(0.5, interpolation="linear")) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 24.5 74.5 | └──────────────────┘ Úquantile)rBÚ interpolationrÊ)r<rBrCs r>rBz Expr.quantile™s1€ð>× Ñ Ü Ü×$Ñ$ØØ!Ø+ô  ó ð r@cóX—|jttjd|¬««S)uÀRound underlying floating point data by `decimals` digits. Arguments: decimals: Number of decimals to round by. Notes: For values exactly halfway between rounded decimal values pandas behaves differently than Polars and Arrow. pandas rounds to the nearest even value (e.g. -0.5 and 0.5 round to 0.0, 1.5 and 2.5 round to 2.0, 3.5 and 4.5 to 4.0, etc..). Polars and Arrow round away from 0 (e.g. -0.5 to -1.0, 0.5 to 1.0, 1.5 to 2.0, 2.5 to 3.0, etc..). Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1.12345, 2.56789, 3.901234]}) >>> df = nw.from_native(df_native) >>> df.with_columns(a_rounded=nw.col("a").round(1)) ┌──────────────────────┠| Narwhals DataFrame | |----------------------| | a a_rounded| |0 1.123450 1.1| |1 2.567890 2.6| |2 3.901234 3.9| └──────────────────────┘ Úround)Údecimalsr)r<rFs r>rEz Expr.roundÁs)€ð<× Ñ Ü ”X×)Ñ)¨7¸XÔ Fó ð r@cóT—|jttjd««S)uCCompute the numerical floor. Examples: >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table({"values": [1.1, 4.3, -1.3]}) >>> df = nw.from_native(df_native) >>> result = df.with_columns(floor=nw.col("values").floor()) >>> result ┌────────────────────────┠| Narwhals DataFrame | |------------------------| |pyarrow.Table | |values: double | |floor: double | |---- | |values: [[1.1,4.3,-1.3]]| |floor: [[1,4,-2]] | └────────────────────────┘ Úfloorrrrs r>rHz Expr.floorãs"€ð*× Ñ ¤¬(×*>Ñ*>ÀÓ!HÓIÐIr@cóT—|jttjd««S)uCCompute the numerical ceiling. Examples: >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table({"values": [1.1, 4.3, -1.3]}) >>> df = nw.from_native(df_native) >>> result = df.with_columns(ceil=nw.col("values").ceil()) >>> result ┌────────────────────────┠| Narwhals DataFrame | |------------------------| |pyarrow.Table | |values: double | |ceil: double | |---- | |values: [[1.1,4.3,-1.3]]| |ceil: [[2,5,-1]] | └────────────────────────┘ Úceilrrrs r>rJz Expr.ceilúó"€ð*× Ñ ¤¬(×*>Ñ*>ÀÓ!GÓHÐHr@cóT—|jttjd««S)uReturn the number of elements in the column. Null values count towards the total. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": ["x", "y", "z"], "b": [1, 2, 1]}) >>> df = nw.from_native(df_native) >>> df.select( ... nw.col("a").filter(nw.col("b") == 1).len().alias("a1"), ... nw.col("a").filter(nw.col("b") == 2).len().alias("a2"), ... ) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a1 a2 | | 0 2 1 | └──────────────────┘ r[rÊrrs r>r[zExpr.lenó"€ð*× Ñ ¤¬(×*>Ñ*>ÀÓ!FÓGÐGr@có—|€*|jttjd|««S|€*|jttjd|««S|jttjd||««S)uKClip values in the Series. Arguments: lower_bound: Lower bound value. String literals are treated as column names. upper_bound: Upper bound value. String literals are treated as column names. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 2, 3]}) >>> df = nw.from_native(df_native) >>> df.with_columns(a_clipped=nw.col("a").clip(-1, 3)) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a a_clipped | | 0 1 1 | | 1 2 2 | | 2 3 3 | └──────────────────┘ Ú clip_lowerÚ clip_upperÚclipr)r<rrs r>rQz Expr.clip(s…€ð4 Ð Ø×$Ñ$Üœ×-Ñ-¨|¸[ÓIóð ð Ð Ø×$Ñ$Üœ×-Ñ-¨|¸[ÓIóð ð× Ñ Ü ”X×)Ñ)¨6°;À Ó Ló ð r@cóT—|jttjd««S)uƒGet the first value. Notes: For lazy backends, this can only be used with `over`. We may introduce `min_by` in the future so it can be used as an aggregation. Examples: >>> import pandas as pd >>> import narwhals as nw >>> data = {"a": [1, 1, 2, 2], "b": ["foo", None, None, "baz"]} >>> df_native = pd.DataFrame(data) >>> df = nw.from_native(df_native) >>> df.select(nw.all().first()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 1 foo | └──────────────────┘ >>> df.group_by("a").agg(nw.col("b").first()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | a b | | 0 1 foo | | 1 2 None | └──────────────────┘ Úfirst©rGr r rërrs r>rSz Expr.firstNs"€ð<× Ñ ¤¬(×*HÑ*HÈ'Ó!RÓSÐSr@cóT—|jttjd««S)udGet the last value. Notes: For lazy backends, this can only be used with `over`. We may introduce `max_by` in the future so it can be used as an aggregation. Examples: >>> import pyarrow as pa >>> import narwhals as nw >>> data = {"a": [1, 1, 2, 2], "b": ["foo", None, None, "baz"]} >>> df_native = pa.table(data) >>> df = nw.from_native(df_native) >>> df.select(nw.all().last()) ┌──────────────────┠|Narwhals DataFrame| |------------------| | pyarrow.Table | | a: int64 | | b: string | | ---- | | a: [[2]] | | b: [["baz"]] | └──────────────────┘ >>> df.group_by("a").agg(nw.col("b").last()) ┌──────────────────┠|Narwhals DataFrame| |------------------| |pyarrow.Table | |a: int64 | |b: string | |---- | |a: [[1,2]] | |b: [[null,"baz"]] | └──────────────────┘ ÚlastrTrrs r>rVz Expr.lastns#€ðJ× Ñ ¤¬(×*HÑ*HÈ&Ó!QÓRÐRr@rb©Úkeepcóº—d}||vrd|›d|›d}t|«‚|dk(rtjntj}|j t |d|¬««S)u%Compute the most occurring value(s). Can return multiple values. Arguments: keep: Whether to keep all modes or any mode found. Remark that `keep='any'` is not deterministic for multimodal values. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 1, 2, 3], "b": [1, 1, 2, 2]}) >>> df = nw.from_native(df_native) >>> df.select(nw.col("a").mode()).sort("a") ┌──────────────────┠|Narwhals DataFrame| |------------------| | a | | 0 1 | └──────────────────┘ )rbr`z`keep` must be one of z , found 'ú'r`ÚmoderW)r+r rËrþrGr )r<rXÚ_supported_keep_valuesrkr\s r>r[z Expr.mode•sg€ð,"0ÐØ Ð-Ñ -Ø*Ð+AÐ*BÀ)ÈDÈ6ÐQRÐSˆCܘS“/Ð !Ø'+¨u¢}Œx×#Ò#¼(×:MÑ:MˆØ× Ñ ¤¨$°¸TÔ!BÓCÐCr@cóT—|jttjd««S)u2Returns boolean values indicating which original values are finite. Warning: pandas handles null values differently from Polars and PyArrow. See [null_handling](../concepts/null_handling.md/) for reference. `is_finite` will return False for NaN and Null's in the Dask and pandas non-nullable backend, while for Polars, PyArrow and pandas nullable backends null values are kept as such. Examples: >>> import polars as pl >>> import narwhals as nw >>> df_native = pl.DataFrame({"a": [float("nan"), float("inf"), 2.0, None]}) >>> df = nw.from_native(df_native) >>> df.with_columns(a_is_finite=nw.col("a").is_finite()) ┌──────────────────────┠| Narwhals DataFrame | |----------------------| |shape: (4, 2) | |┌──────┬─────────────â”| |│ a ┆ a_is_finite │| |│ --- ┆ --- │| |│ f64 ┆ bool │| |╞â•â•â•â•â•â•╪â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡| |│ NaN ┆ false │| |│ inf ┆ false │| |│ 2.0 ┆ true │| |│ null ┆ null │| |└──────┴─────────────┘| └──────────────────────┘ Ú is_finiterrrs r>r^zExpr.is_finite²s#€ð@× Ñ ¤¬(×*>Ñ*>À Ó!LÓMÐMr@cóX—|jttjd|¬««S)uˆReturn the cumulative count of the non-null values in the column. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: reverse: reverse the operation Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": ["x", "k", None, "d"]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("a").cum_count().alias("a_cum_count"), ... nw.col("a").cum_count(reverse=True).alias("a_cum_count_reverse"), ... ) ┌─────────────────────────────────────────┠| Narwhals DataFrame | |-----------------------------------------| | a a_cum_count a_cum_count_reverse| |0 x 1 3| |1 k 2 2| |2 None 2 1| |3 d 3 1| └─────────────────────────────────────────┘ Ú cum_countrrØrs r>r`zExpr.cum_countÔs)€ð:× Ñ Ü ”X×.Ñ.° ÀWÔ Mó ð r@cóX—|jttjd|¬««S)u7Return the cumulative min of the non-null values in the column. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: reverse: reverse the operation Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [3, 1, None, 2]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("a").cum_min().alias("a_cum_min"), ... nw.col("a").cum_min(reverse=True).alias("a_cum_min_reverse"), ... ) ┌────────────────────────────────────┠| Narwhals DataFrame | |------------------------------------| | a a_cum_min a_cum_min_reverse| |0 3.0 3.0 1.0| |1 1.0 1.0 1.0| |2 NaN NaN NaN| |3 2.0 1.0 2.0| └────────────────────────────────────┘ Úcum_minrrØrs r>rbz Expr.cum_minõó)€ð:× Ñ Ü ”X×.Ñ.° À7Ô Kó ð r@cóX—|jttjd|¬««S)u7Return the cumulative max of the non-null values in the column. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: reverse: reverse the operation Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 3, None, 2]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("a").cum_max().alias("a_cum_max"), ... nw.col("a").cum_max(reverse=True).alias("a_cum_max_reverse"), ... ) ┌────────────────────────────────────┠| Narwhals DataFrame | |------------------------------------| | a a_cum_max a_cum_max_reverse| |0 1.0 1.0 3.0| |1 3.0 3.0 3.0| |2 NaN NaN NaN| |3 2.0 3.0 2.0| └────────────────────────────────────┘ Úcum_maxrrØrs r>rez Expr.cum_maxrcr@cóX—|jttjd|¬««S)uYReturn the cumulative product of the non-null values in the column. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: reverse: reverse the operation Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1, 3, None, 2]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... nw.col("a").cum_prod().alias("a_cum_prod"), ... nw.col("a").cum_prod(reverse=True).alias("a_cum_prod_reverse"), ... ) ┌──────────────────────────────────────┠| Narwhals DataFrame | |--------------------------------------| | a a_cum_prod a_cum_prod_reverse| |0 1.0 1.0 6.0| |1 3.0 3.0 6.0| |2 NaN NaN NaN| |3 2.0 6.0 2.0| └──────────────────────────────────────┘ Úcum_prodrrØrs r>rgz Expr.cum_prod7s)€ð:× Ñ Ü ”X×.Ñ.° ÀGÔ Ló ð r@)rÔÚcenterc ó|—t||¬«\}}|jttjd|||¬««S)uApply a rolling sum (moving sum) over the values. A window of length `window_size` will traverse the values. The resulting values will be aggregated to their sum. The window at a given row will include the row itself and the `window_size - 1` elements before it. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: window_size: The length of the window in number of elements. It must be a strictly positive integer. min_samples: The number of values in the window that should be non-null before computing a result. If set to `None` (default), it will be set equal to `window_size`. If provided, it must be a strictly positive integer, and less than or equal to `window_size` center: Set the labels at the center of the window. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1.0, 2.0, None, 4.0]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_rolling_sum=nw.col("a").rolling_sum(window_size=3, min_samples=1) ... ) ┌─────────────────────┠| Narwhals DataFrame | |---------------------| | a a_rolling_sum| |0 1.0 1.0| |1 2.0 3.0| |2 NaN 3.0| |3 4.0 6.0| └─────────────────────┘ ©Ú window_sizerÔÚ rolling_sum©rkrÔrh©r rGr r rÙ©r<rkrÔrhs r>rlzExpr.rolling_sumXsK€ôT$?Ø#°ô$ Ñ ˆ [ð× Ñ Ü Ü×)Ñ)ØØ'Ø'Øô  ó ð r@c ó|—t||¬«\}}|jttjd|||¬««S)uApply a rolling mean (moving mean) over the values. A window of length `window_size` will traverse the values. The resulting values will be aggregated to their mean. The window at a given row will include the row itself and the `window_size - 1` elements before it. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: window_size: The length of the window in number of elements. It must be a strictly positive integer. min_samples: The number of values in the window that should be non-null before computing a result. If set to `None` (default), it will be set equal to `window_size`. If provided, it must be a strictly positive integer, and less than or equal to `window_size` center: Set the labels at the center of the window. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1.0, 2.0, None, 4.0]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_rolling_mean=nw.col("a").rolling_mean(window_size=3, min_samples=1) ... ) ┌──────────────────────┠| Narwhals DataFrame | |----------------------| | a a_rolling_mean| |0 1.0 1.0| |1 2.0 1.5| |2 NaN 1.5| |3 4.0 3.0| └──────────────────────┘ rjÚ rolling_meanrmrnros r>rqzExpr.rolling_meansK€ôT$?Ø#°ô$ Ñ ˆ [ð× Ñ Ü Ü×)Ñ)ØØ'Ø'Øô  ó ð r@)rÔrhràc ó~—t||¬«\}}|jttjd||||¬««S)ukApply a rolling variance (moving variance) over the values. A window of length `window_size` will traverse the values. The resulting values will be aggregated to their variance. The window at a given row will include the row itself and the `window_size - 1` elements before it. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: window_size: The length of the window in number of elements. It must be a strictly positive integer. min_samples: The number of values in the window that should be non-null before computing a result. If set to `None` (default), it will be set equal to `window_size`. If provided, it must be a strictly positive integer, and less than or equal to `window_size`. center: Set the labels at the center of the window. ddof: Delta Degrees of Freedom; the divisor for a length N window is N - ddof. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1.0, 2.0, None, 4.0]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_rolling_var=nw.col("a").rolling_var(window_size=3, min_samples=1) ... ) ┌─────────────────────┠| Narwhals DataFrame | |---------------------| | a a_rolling_var| |0 1.0 NaN| |1 2.0 0.5| |2 NaN 0.5| |3 4.0 2.0| └─────────────────────┘ rjÚ rolling_var©ràrkrÔrhrn©r<rkrÔrhràs r>rszExpr.rolling_varÇóN€ô`$?Ø#°ô$ Ñ ˆ [ð× Ñ Ü Ü×)Ñ)ØØØ'Ø'Øô  ó  ð r@c ó~—t||¬«\}}|jttjd||||¬««S)u‰Apply a rolling standard deviation (moving standard deviation) over the values. A window of length `window_size` will traverse the values. The resulting values will be aggregated to their standard deviation. The window at a given row will include the row itself and the `window_size - 1` elements before it. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: window_size: The length of the window in number of elements. It must be a strictly positive integer. min_samples: The number of values in the window that should be non-null before computing a result. If set to `None` (default), it will be set equal to `window_size`. If provided, it must be a strictly positive integer, and less than or equal to `window_size`. center: Set the labels at the center of the window. ddof: Delta Degrees of Freedom; the divisor for a length N window is N - ddof. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [1.0, 2.0, None, 4.0]}) >>> df = nw.from_native(df_native) >>> df.with_columns( ... a_rolling_std=nw.col("a").rolling_std(window_size=3, min_samples=1) ... ) ┌─────────────────────┠| Narwhals DataFrame | |---------------------| | a a_rolling_std| |0 1.0 NaN| |1 2.0 0.707107| |2 NaN 0.707107| |3 4.0 1.414214| └─────────────────────┘ rjÚ rolling_stdrtrnrus r>rxzExpr.rolling_stdrvr@)Ú descendingcóŒ—hd£}||vrd|›d}t|«‚|jttjd||¬««S)uPAssign ranks to data, dealing with ties appropriately. Notes: The resulting dtype may differ between backends. Info: For lazy backends, this operation must be followed by `Expr.over` with `order_by` specified, see [order-dependence](../concepts/order_dependence.md). Arguments: method: The method used to assign ranks to tied elements. The following methods are available (default is 'average') - *"average"*: The average of the ranks that would have been assigned to all the tied values is assigned to each value. - *"min"*: The minimum of the ranks that would have been assigned to all the tied values is assigned to each value. (This is also referred to as "competition" ranking.) - *"max"*: The maximum of the ranks that would have been assigned to all the tied values is assigned to each value. - *"dense"*: Like "min", but the rank of the next highest element is assigned the rank immediately after those assigned to the tied elements. - *"ordinal"*: All values are given a distinct rank, corresponding to the order that the values occur in the Series. descending: Rank in descending order. Examples: >>> import pandas as pd >>> import narwhals as nw >>> df_native = pd.DataFrame({"a": [3, 6, 1, 1, 6]}) >>> df = nw.from_native(df_native) >>> result = df.with_columns(rank=nw.col("a").rank(method="dense")) >>> result ┌──────────────────┠|Narwhals DataFrame| |------------------| | a rank | | 0 3 2.0 | | 1 6 3.0 | | 2 1 1.0 | | 3 1 1.0 | | 4 6 3.0 | └──────────────────┘ >röróÚdenseÚaverageÚordinalzTRanking method must be one of {'average', 'min', 'max', 'dense', 'ordinal'}. Found 'rZÚrank)Úmethodry)r+rGr r r8)r<rryÚsupported_rank_methodsrks r>r~z Expr.rankCs\€ò\"OÐØ Ð/Ñ /ðØ ˜ ð$ð ô˜S“/Ð !à× Ñ Ü ”X—_‘_ f°VÈ Ô Só ð r@cóX—|jttjd|¬««S)uœCompute the logarithm to a given base. Arguments: base: Given base, defaults to `e` Examples: >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table({"values": [1, 2, 4]}) >>> df = nw.from_native(df_native) >>> result = df.with_columns( ... log=nw.col("values").log(), log_2=nw.col("values").log(base=2) ... ) >>> result ┌────────────────────────────────────────────────┠| Narwhals DataFrame | |------------------------------------------------| |pyarrow.Table | |values: int64 | |log: double | |log_2: double | |---- | |values: [[1,2,4]] | |log: [[0,0.6931471805599453,1.3862943611198906]]| |log_2: [[0,1,2]] | └────────────────────────────────────────────────┘ Úlog)Úbaser)r<rƒs r>r‚zExpr.log}s$€ð8× Ñ ¤¬(×*>Ñ*>ÀÈDÔ!QÓRÐRr@cóT—|jttjd««S)u‚Compute the exponent. Examples: >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table({"values": [-1, 0, 1]}) >>> df = nw.from_native(df_native) >>> result = df.with_columns(exp=nw.col("values").exp()) >>> result ┌────────────────────────────────────────────────┠| Narwhals DataFrame | |------------------------------------------------| |pyarrow.Table | |values: int64 | |exp: double | |---- | |values: [[-1,0,1]] | |exp: [[0.36787944117144233,1,2.718281828459045]]| └────────────────────────────────────────────────┘ Úexprrrs r>r…zExpr.exp›rMr@cóT—|jttjd««S)uâCompute the square root. Examples: >>> import pyarrow as pa >>> import narwhals as nw >>> df_native = pa.table({"values": [1, 4, 9]}) >>> df = nw.from_native(df_native) >>> result = df.with_columns(sqrt=nw.col("values").sqrt()) >>> result ┌──────────────────┠|Narwhals DataFrame| |------------------| |pyarrow.Table | |values: int64 | |sqrt: double | |---- | |values: [[1,4,9]] | |sqrt: [[1,2,3]] | └──────────────────┘ Úsqrtrrrs r>r‡z Expr.sqrt²rKr@gg•Ö&è .>)Úabs_tolÚrel_tolÚ nans_equalcó´—|dkrd|›}t|«‚d|cxkrdksnd|›}t|«‚ddlm}t|tt |f«r,ddlm}m}|j«} ||«} ||«} | } n6|j«|j«} } |j«| z} | } |j«j| d¬«|z} | j|d¬«}|j«}|j«|z}||z j«|k|z| z}|dkD|dkD}}|| z||k(z}|| z}||z|z}|r || z}||z}|S) uB Check if this expression is close, i.e. almost equal, to the other expression. Two values `a` and `b` are considered close if the following condition holds: $$ |a-b| \le max \{ \text{rel\_tol} \cdot max \{ |a|, |b| \}, \text{abs\_tol} \} $$ Arguments: other: Values to compare with. abs_tol: Absolute tolerance. This is the maximum allowed absolute difference between two values. Must be non-negative. rel_tol: Relative tolerance. This is the maximum allowed difference between two values, relative to the larger absolute value. Must be in the range [0, 1). nans_equal: Whether NaN values should be considered equal. Notes: The implementation of this method is symmetric and mirrors the behavior of `math.isclose`. Specifically note that this behavior is different to `numpy.isclose`. Examples: >>> import duckdb >>> import pyarrow as pa >>> import narwhals as nw >>> >>> data = { ... "x": [1.0, float("inf"), 1.41, None, float("nan")], ... "y": [1.2, float("inf"), 1.40, None, float("nan")], ... } >>> _table = pa.table(data) >>> df_native = duckdb.table("_table") >>> df = nw.from_native(df_native) >>> df.with_columns( ... is_close=nw.col("x").is_close( ... nw.col("y"), abs_tol=0.1, nans_equal=True ... ) ... ) ┌──────────────────────────────┠| Narwhals LazyFrame | |------------------------------| |┌────────┬────────┬──────────â”| |│ x │ y │ is_close │| |│ double │ double │ boolean │| |├────────┼────────┼──────────┤| |│ 1.0 │ 1.2 │ false │| |│ inf │ inf │ true │| |│ 1.41 │ 1.4 │ true │| |│ NULL │ NULL │ NULL │| |│ nan │ nan │ true │| |└────────┴────────┴──────────┘| └──────────────────────────────┘ rz'`abs_tol` must be non-negative but got rJz.`rel_tol` must be in the range [0, 1) but got )ÚDecimal)ÚisinfÚisnanN)rr)rÚdecimalrŒrÚfloatr ÚmathrrŽÚ__abs__ryr$r^rQ)r<r‹rˆr‰rŠrkrŒrrŽÚ other_absÚ other_is_nanÚ other_is_infÚother_is_not_infÚ rel_thresholdÚ toleranceÚ self_is_nanÚself_is_not_infÚis_closeÚ self_signÚ other_signÚ is_same_infÚ either_nanÚresultÚboth_nans r>r›z Expr.is_closeÉs”€ð| QŠ;Ø;¸G¸9ÐEˆCܘsÓ#Ð #àWÔ ˜qÔ ØBÀ7À)ÐLˆCܘsÓ#Ð #å#ô eœe¤S¨'Ð2Ô 3ß )🠙 ›ˆIÙ  ›<ˆLÙ  ›<ˆLð $0Ð/Ñ ð',§i¡i£k°5·<±<³>|ˆIØ$Ÿ™Ó0°<Ñ?Ð Ø,Ð,ˆLàŸ™› Ÿ™°IÈ4˜ÓPÐSZÑZˆ Ø!×&Ñ&°7ÈÐ&ÓMˆ à—k‘k“mˆ ØŸ.™.Ó*¨[Ñ8ˆðU‰l× Ñ Ó ! YÑ .°/Ñ AÐDTÑ Tð ð !% q¡¨%°!©):ˆ Ø'Ð'¨<Ñ7¸9È Ñ;RÑSˆ ð ! <Ñ/ˆ ؘ[Ñ(¨Z¨KÑ7ˆá Ø" \Ñ1ˆHؘhÑ&ˆFàˆ r@có—t|«Sr:rrrs r>rzExpr.strC ó €ä" 4Ó(Ð(r@có—t|«Sr:rrrs r>ÚdtzExpr.dtG s €ä$ TÓ*Ð*r@có—t|«Sr:rrrs r>ÚcatzExpr.catK s €ä Ó%Ð%r@có—t|«Sr:rrrs r>r~z Expr.nameO ó €ä  Ó&Ð&r@có—t|«Sr:rrrs r>rWz Expr.listS r©r@có—t|«Sr:rrrs r>Ústructz Expr.structW r£r@)r=r ÚreturnÚNone)rBzCompliantNamespace[Any, Any]r­zCompliantExpr[Any, Any])rFr r­r%)r­r)r­r!)r­r%)r~rr­r%)rz"Callable[Concatenate[Self, PS], R]r‚zPS.argsrXz PS.kwargsr­r6)r†r-r­r%)rŠrr‹ú Self | Anyr­r%)r‹r¯r­r%)r‹rr­r%)rÏú float | NonerÐr°rÑr°rÒr°rÓÚboolrÔr rÕr±r­r%)ràr r­r%r:)rz(Callable[[Any], CompliantExpr[Any, Any]]rêz DType | Nonerçr±r­r%)rr±r­r%)rhr r­r%) rz!Sequence[Any] | Mapping[Any, Any]rzSequence[Any] | Noner zAny | NoDefaultrêzIntoDType | Noner­r%)Úboth)rúAny | IntoExprrr³rr+r­r%)r rr­r%)NNN)rezExpr | NonNestedLiteralr)zFillNullStrategy | Noner*ú int | Noner­r%)rer°r­r%)rQzstr | Sequence[str]rIzstr | Sequence[str] | Noner­r%)rBrrCr3r­r%)r)rFr r­r%)NN)rú2IntoExpr | NumericLiteral | TemporalLiteral | Nonerrµr­r%)rXr/r­r%)rkr rÔr´rhr±r­r%) rkr rÔr´rhr±ràr r­r%)r|)rr2ryr±r­r%)rƒrr­r%) r‹z#Expr | Series[Any] | NumericLiteralrˆrr‰rrŠr±r­r%)r­zExprStringNamespace[Self])r­zExprDateTimeNamespace[Self])r­zExprCatNamespace[Self])r­zExprNameNamespace[Self])r­zExprListNamespace[Self])r­zExprStructNamespace[Self])kÚ__name__Ú __module__Ú __qualname__r?rCrGrlrsrwr{r}rƒr…rŒrŽr“r•r›ržr r¢r¤r¦r¨r«r­r°r²r´r¶r¸rºr¼r¾rÀrÂrÄrÆrÈr`rbr×rÛrÞrârærérîrðrzrórörørúrüryrrr rr rrrr"r$r(r-r/r1r6r:r<r>r@rBrErHrJr[rQrSrVr[r^r`rbrergrlrqrsrxr~r‘Úer‚r…r‡r›Úpropertyrr¥r§r~rWr¬rVr@r>r8r8-sº„óð/Ø.ð/à ó/ó 2ó*ó:<ó ó ó Uð,/à4ð/ðð/ðð /ð ó /ó>Vó2'ó2ó2ó3ó/ó2ó/ó3ó/ó3ó4ó7ó8ó3ó/ó2ó2ó2ó2ó3ó4ó8ó9ó3ó4óOóHó(Hð.!Ø!Ø"&Ø"ØØØ"ñ_ ðð_ ðð _ ð  ð _ ð ð _ ðð_ ðð_ ðð_ ð ó_ óBIó$Kð*"#õSð,"#õSð2&*ð7 ð %ñ 7 à:ð7 ð#ð7 ð ð 7 ð ó 7 órIó$Mó*Hó0Hó$Hó$Jó$Mó$Jó$Hð&*/õ ó>'NóR+Tð`%)ð`'ð $.Ø)-ñ `'à .ð`'ð"ð`'ð !ð `'ð 'ð `'ð ó`'ðN"(ð !'à#ð!'ð$ð!'ðð !'ð ó !'óF'óBWó8Ló>KðB*.Ø,0Ø ð f'à&ðf'ð*ðf'ðð f'ð ó f'óPZóDNðF04ñ3*à*ð3*ð-ð3*ð ó 3*ójMó*Ió*Oó0[ó6Zð6& Øð& Ø.Hð& à ó& ôP  óDJó.Ió.Hð2KOØJNð$ àGð$ ðHð$ ð ó $ óLTó@%SðN05õDó: NðD,1õ ðB*/õ ðB*/õ ðB+0õ ðD>BÐRWñ5 Øð5 Ø0:ð5 ØKOð5 à ó5 ðp>BÐRWñ6 Øð6 Ø0:ð6 ØKOð6 à ó6 ðx#'ØØñ < àð< ð ð < ð ð < ð ð < ð ó< ðD#'ØØñ < àð< ð ð < ð ð < ð ð < ð ó< ð|8 Èõ8 ðt!%§¡ôSó<Hó.Ið6ØØ ñ xà2ðxðð xð ð xð ð xð óxðtò)óð)ðò+óð+ðò&óð&ðò'óð'ðò'óð'ðò)óñ)r@r8)DÚ __future__rr‘Úcollections.abcrrrÚtypingrrr Únarwhals._expression_parsingr r r Únarwhals._utilsr rrrÚnarwhals.dtypesrÚnarwhals.exceptionsrrÚnarwhals.expr_catrÚnarwhals.expr_dtrÚnarwhals.expr_listrÚnarwhals.expr_namerÚnarwhals.expr_strrÚnarwhals.expr_structrÚnarwhals.translater r!r"Útyping_extensionsr#r$r%Únarwhals._compliantr&r'Únarwhals._typingr(r)Únarwhals.seriesr*Únarwhals.typingr+r,r-r.r/r0r1r2r3r4r5r6r8Ú__all__rVr@r>úrÏsðÝ"ã ß7Ñ7ß/Ñ/çKÑKßYÓYÝ+ßCÝ.Ý2Ý0Ý0Ý1Ý4Ý(áß(ç>Ñ>çEÝ*Ý%Ý&÷ ÷ ÷ ñ 4‹€BÙ‹ €A÷l$)ñl$)ð^I ˆ(r@