From 046a7ff5641074386edd7e1975f6df4b34c9526d Mon Sep 17 00:00:00 2001 From: Jim Crist-Harif Date: Mon, 22 Jul 2024 10:44:14 -0500 Subject: [PATCH] feat(api): support deferred or string column names in `cov`/`corr` methods --- ibis/expr/tests/test_reductions.py | 7 +++++++ ibis/expr/types/numeric.py | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ibis/expr/tests/test_reductions.py b/ibis/expr/tests/test_reductions.py index ccca6298838a..5f27f25c4a7b 100644 --- a/ibis/expr/tests/test_reductions.py +++ b/ibis/expr/tests/test_reductions.py @@ -106,3 +106,10 @@ 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)) + + +@pytest.mark.parametrize("func_name", ["cov", "corr"]) +def test_cov_corr_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/numeric.py b/ibis/expr/types/numeric.py index 36da3740a944..c99c357c7470 100644 --- a/ibis/expr/types/numeric.py +++ b/ibis/expr/types/numeric.py @@ -836,7 +836,10 @@ def corr( The correlation of `left` and `right` """ return ops.Correlation( - self, right, how=how, where=self._bind_to_parent_table(where) + self, + self._bind_to_parent_table(right), + how=how, + where=self._bind_to_parent_table(where), ).to_expr() def cov( @@ -862,7 +865,10 @@ def cov( The covariance of `self` and `right` """ return ops.Covariance( - self, right, how=how, where=self._bind_to_parent_table(where) + self, + self._bind_to_parent_table(right), + how=how, + where=self._bind_to_parent_table(where), ).to_expr() def mean(