diff --git a/ibis/expr/tests/test_reductions.py b/ibis/expr/tests/test_reductions.py index 0427aea40d24..ccca6298838a 100644 --- a/ibis/expr/tests/test_reductions.py +++ b/ibis/expr/tests/test_reductions.py @@ -99,3 +99,10 @@ def test_reduction_methods(fn, operation, cond): assert node.where == resolved else: assert node.where == where.op() + + +@pytest.mark.parametrize("func_name", ["argmin", "argmax"]) +def test_argminmax_deferred(func_name): + t = ibis.table({"a": "int", "b": "int"}, name="t") + func = getattr(t.a, func_name) + assert func(_.b).equals(func(t.b)) diff --git a/ibis/expr/types/generic.py b/ibis/expr/types/generic.py index 72ece2321697..0aade5f88686 100644 --- a/ibis/expr/types/generic.py +++ b/ibis/expr/types/generic.py @@ -1539,10 +1539,7 @@ def _bind_to_parent_table(self, value) -> Value | None: def __deferred_repr__(self): return f"" - def approx_nunique( - self, - where: ir.BooleanValue | None = None, - ) -> ir.IntegerScalar: + def approx_nunique(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar: """Return the approximate number of distinct elements in `self`. ::: {.callout-note} @@ -1584,10 +1581,7 @@ def approx_nunique( self, where=self._bind_to_parent_table(where) ).to_expr() - def approx_median( - self, - where: ir.BooleanValue | None = None, - ) -> Scalar: + def approx_median(self, where: ir.BooleanValue | None = None) -> Scalar: """Return an approximate of the median of `self`. ::: {.callout-note} @@ -1744,7 +1738,9 @@ def argmax(self, key: ir.Value, where: ir.BooleanValue | None = None) -> Scalar: └─────────────┘ """ return ops.ArgMax( - self, key=key, where=self._bind_to_parent_table(where) + self, + key=self._bind_to_parent_table(key), + where=self._bind_to_parent_table(where), ).to_expr() def argmin(self, key: ir.Value, where: ir.BooleanValue | None = None) -> Scalar: @@ -1778,7 +1774,9 @@ def argmin(self, key: ir.Value, where: ir.BooleanValue | None = None) -> Scalar: └──────────┘ """ return ops.ArgMin( - self, key=key, where=self._bind_to_parent_table(where) + self, + key=self._bind_to_parent_table(key), + where=self._bind_to_parent_table(where), ).to_expr() def median(self, where: ir.BooleanValue | None = None) -> Scalar: @@ -1941,11 +1939,7 @@ def nunique(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar: self, where=self._bind_to_parent_table(where) ).to_expr() - def topk( - self, - k: int, - by: ir.Value | None = None, - ) -> ir.Table: + def topk(self, k: int, by: ir.Value | None = None) -> ir.Table: """Return a "top k" expression. Parameters