Skip to content

Commit

Permalink
feat(api): support deferred or string column names in cov/corr me…
Browse files Browse the repository at this point in the history
…thods (#9657)
  • Loading branch information
jcrist authored Jul 22, 2024
1 parent 2e3fd9a commit 4d135b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ibis/expr/tests/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
10 changes: 8 additions & 2 deletions ibis/expr/types/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 4d135b3

Please sign in to comment.