Skip to content

Commit 4218644

Browse files
NickCrewscpcloud
authored andcommitted
feat(typing): return Self from .fill_null() and similar
1 parent 431488a commit 4218644

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ibis/expr/types/generic.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import polars as pl
2626
import pyarrow as pa
2727
import rich.table
28+
from typing_extensions import Self
2829

2930
import ibis.expr.schema as sch
3031
import ibis.expr.types as ir
@@ -428,7 +429,7 @@ def typeof(self) -> ir.StringValue:
428429
"""
429430
return ops.TypeOf(self).to_expr()
430431

431-
def fill_null(self, fill_value: Scalar, /) -> Value:
432+
def fill_null(self, fill_value: Scalar, /) -> Self:
432433
"""Replace `NULL`s with the given value. Does NOT affect `NaN` and `inf` values.
433434
434435
This only replaces genuine `NULL` values, it does NOT affect
@@ -491,11 +492,11 @@ def fill_null(self, fill_value: Scalar, /) -> Value:
491492
return ops.Coalesce((self, fill_value)).to_expr()
492493

493494
@deprecated(as_of="9.1", instead="use fill_null instead")
494-
def fillna(self, fill_value: Scalar, /) -> Value:
495+
def fillna(self, fill_value: Scalar, /) -> Self:
495496
"""DEPRECATED: use `fill_null` instead, which acts exactly the same."""
496497
return self.fill_null(fill_value)
497498

498-
def nullif(self, null_if_expr: Value, /) -> Value:
499+
def nullif(self, null_if_expr: Value, /) -> Self:
499500
"""Set values to null if they equal the values `null_if_expr`.
500501
501502
Commonly used to avoid divide-by-zero problems by replacing zero with
@@ -758,7 +759,7 @@ def substitute(
758759
value: Value | dict,
759760
replacement: Value | None = None,
760761
else_: Value | None = None,
761-
):
762+
) -> Value:
762763
"""Replace values given in `values` with `replacement`.
763764
764765
This is similar to the pandas `replace` method.
@@ -838,7 +839,7 @@ def over(
838839
range=None,
839840
group_by=None,
840841
order_by=None,
841-
) -> Value:
842+
) -> Self:
842843
"""Construct a window expression.
843844
844845
Parameters
@@ -1261,7 +1262,7 @@ def __le__(self, other: Value) -> ir.BooleanValue:
12611262
def __lt__(self, other: Value) -> ir.BooleanValue:
12621263
return _binop(ops.Less, self, other)
12631264

1264-
def asc(self, *, nulls_first: bool = False) -> ir.Value:
1265+
def asc(self, *, nulls_first: bool = False) -> Self:
12651266
"""Sort an expression in ascending order.
12661267
12671268
Parameters
@@ -1308,7 +1309,7 @@ def asc(self, *, nulls_first: bool = False) -> ir.Value:
13081309
"""
13091310
return ops.SortKey(self, ascending=True, nulls_first=nulls_first).to_expr()
13101311

1311-
def desc(self, *, nulls_first: bool = False) -> ir.Value:
1312+
def desc(self, *, nulls_first: bool = False) -> Self:
13121313
"""Sort an expression in descending order.
13131314
13141315
Parameters

0 commit comments

Comments
 (0)