Skip to content

Commit 5b29be3

Browse files
committed
refactor(api)!: where argument of aggregate functions is now required-keyword
1 parent fd5e7e3 commit 5b29be3

File tree

4 files changed

+38
-30
lines changed

4 files changed

+38
-30
lines changed

ibis/expr/types/generic.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ def cases(
10281028

10291029
def collect(
10301030
self,
1031+
*,
10311032
where: ir.BooleanValue | None = None,
10321033
order_by: Any = None,
10331034
include_null: bool = False,
@@ -1698,7 +1699,9 @@ def _bind_to_parent_table(self, value) -> Value | None:
16981699
def __deferred_repr__(self) -> str:
16991700
return f"<column[{self.type()}]>"
17001701

1701-
def approx_nunique(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
1702+
def approx_nunique(
1703+
self, *, where: ir.BooleanValue | None = None
1704+
) -> ir.IntegerScalar:
17021705
"""Return the approximate number of distinct elements in `self`.
17031706
17041707
::: {.callout-note}
@@ -1740,7 +1743,7 @@ def approx_nunique(self, where: ir.BooleanValue | None = None) -> ir.IntegerScal
17401743
self, where=self._bind_to_parent_table(where)
17411744
).to_expr()
17421745

1743-
def approx_median(self, where: ir.BooleanValue | None = None) -> Scalar:
1746+
def approx_median(self, *, where: ir.BooleanValue | None = None) -> Scalar:
17441747
"""Return an approximate of the median of `self`.
17451748
17461749
::: {.callout-note}
@@ -1780,7 +1783,7 @@ def approx_median(self, where: ir.BooleanValue | None = None) -> Scalar:
17801783
"""
17811784
return ops.ApproxMedian(self, where=self._bind_to_parent_table(where)).to_expr()
17821785

1783-
def mode(self, where: ir.BooleanValue | None = None) -> Scalar:
1786+
def mode(self, *, where: ir.BooleanValue | None = None) -> Scalar:
17841787
"""Return the mode of a column.
17851788
17861789
Parameters
@@ -1809,7 +1812,7 @@ def mode(self, where: ir.BooleanValue | None = None) -> Scalar:
18091812
"""
18101813
return ops.Mode(self, where=self._bind_to_parent_table(where)).to_expr()
18111814

1812-
def max(self, where: ir.BooleanValue | None = None) -> Scalar:
1815+
def max(self, *, where: ir.BooleanValue | None = None) -> Scalar:
18131816
"""Return the maximum of a column.
18141817
18151818
Parameters
@@ -1838,7 +1841,7 @@ def max(self, where: ir.BooleanValue | None = None) -> Scalar:
18381841
"""
18391842
return ops.Max(self, where=self._bind_to_parent_table(where)).to_expr()
18401843

1841-
def min(self, where: ir.BooleanValue | None = None) -> Scalar:
1844+
def min(self, *, where: ir.BooleanValue | None = None) -> Scalar:
18421845
"""Return the minimum of a column.
18431846
18441847
Parameters
@@ -1867,7 +1870,7 @@ def min(self, where: ir.BooleanValue | None = None) -> Scalar:
18671870
"""
18681871
return ops.Min(self, where=self._bind_to_parent_table(where)).to_expr()
18691872

1870-
def argmax(self, key: ir.Value, where: ir.BooleanValue | None = None) -> Scalar:
1873+
def argmax(self, key: ir.Value, *, where: ir.BooleanValue | None = None) -> Scalar:
18711874
"""Return the value of `self` that maximizes `key`.
18721875
18731876
If more than one value maximizes `key`, the returned value is backend
@@ -1905,7 +1908,7 @@ def argmax(self, key: ir.Value, where: ir.BooleanValue | None = None) -> Scalar:
19051908
where=self._bind_to_parent_table(where),
19061909
).to_expr()
19071910

1908-
def argmin(self, key: ir.Value, where: ir.BooleanValue | None = None) -> Scalar:
1911+
def argmin(self, key: ir.Value, *, where: ir.BooleanValue | None = None) -> Scalar:
19091912
"""Return the value of `self` that minimizes `key`.
19101913
19111914
If more than one value minimizes `key`, the returned value is backend
@@ -1944,7 +1947,7 @@ def argmin(self, key: ir.Value, where: ir.BooleanValue | None = None) -> Scalar:
19441947
where=self._bind_to_parent_table(where),
19451948
).to_expr()
19461949

1947-
def median(self, where: ir.BooleanValue | None = None) -> Scalar:
1950+
def median(self, *, where: ir.BooleanValue | None = None) -> Scalar:
19481951
"""Return the median of the column.
19491952
19501953
Parameters
@@ -2004,6 +2007,7 @@ def median(self, where: ir.BooleanValue | None = None) -> Scalar:
20042007
def quantile(
20052008
self,
20062009
quantile: float | ir.NumericValue | Sequence[ir.NumericValue | float],
2010+
*,
20072011
where: ir.BooleanValue | None = None,
20082012
) -> Scalar:
20092013
"""Return value at the given quantile.
@@ -2073,7 +2077,7 @@ def quantile(
20732077
op = ops.Quantile
20742078
return op(self, quantile, where=self._bind_to_parent_table(where)).to_expr()
20752079

2076-
def nunique(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
2080+
def nunique(self, *, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
20772081
"""Compute the number of distinct rows in an expression.
20782082
20792083
Parameters
@@ -2194,7 +2198,7 @@ def topk(
21942198

21952199
return table.aggregate(metric, by=[self]).order_by(metric.desc()).limit(k)
21962200

2197-
def arbitrary(self, where: ir.BooleanValue | None = None) -> Scalar:
2201+
def arbitrary(self, *, where: ir.BooleanValue | None = None) -> Scalar:
21982202
"""Select an arbitrary value in a column.
21992203
22002204
Returns an arbitrary (nondeterministic, backend-specific) value from
@@ -2238,7 +2242,7 @@ def arbitrary(self, where: ir.BooleanValue | None = None) -> Scalar:
22382242
"""
22392243
return ops.Arbitrary(self, where=self._bind_to_parent_table(where)).to_expr()
22402244

2241-
def count(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
2245+
def count(self, *, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
22422246
"""Compute the number of rows in an expression.
22432247
22442248
Parameters
@@ -2332,6 +2336,7 @@ def value_counts(self, *, name: str | None = None) -> ir.Table:
23322336

23332337
def first(
23342338
self,
2339+
*,
23352340
where: ir.BooleanValue | None = None,
23362341
order_by: Any = None,
23372342
include_null: bool = False,
@@ -2385,6 +2390,7 @@ def first(
23852390

23862391
def last(
23872392
self,
2393+
*,
23882394
where: ir.BooleanValue | None = None,
23892395
order_by: Any = None,
23902396
include_null: bool = False,

ibis/expr/types/logical.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class BooleanScalar(NumericScalar, BooleanValue):
247247

248248
@public
249249
class BooleanColumn(NumericColumn, BooleanValue):
250-
def any(self, where: BooleanValue | None = None) -> BooleanValue:
250+
def any(self, *, where: BooleanValue | None = None) -> BooleanValue:
251251
"""Return whether at least one element is `True`.
252252
253253
If the expression does not reference any foreign tables, the result
@@ -339,7 +339,7 @@ def resolve_exists_subquery(outer):
339339

340340
return op.to_expr()
341341

342-
def notany(self, where: BooleanValue | None = None) -> BooleanValue:
342+
def notany(self, *, where: BooleanValue | None = None) -> BooleanValue:
343343
"""Return whether no elements are `True`.
344344
345345
Parameters
@@ -373,7 +373,7 @@ def notany(self, where: BooleanValue | None = None) -> BooleanValue:
373373
"""
374374
return ~self.any(where=where)
375375

376-
def all(self, where: BooleanValue | None = None) -> BooleanScalar:
376+
def all(self, *, where: BooleanValue | None = None) -> BooleanScalar:
377377
"""Return whether all elements are `True`.
378378
379379
Parameters
@@ -410,7 +410,7 @@ def all(self, where: BooleanValue | None = None) -> BooleanScalar:
410410
"""
411411
return ops.All(self, where=self._bind_to_parent_table(where)).to_expr()
412412

413-
def notall(self, where: BooleanValue | None = None) -> BooleanScalar:
413+
def notall(self, *, where: BooleanValue | None = None) -> BooleanScalar:
414414
"""Return whether not all elements are `True`.
415415
416416
Parameters

ibis/expr/types/numeric.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ class NumericScalar(Scalar, NumericValue):
768768
class NumericColumn(Column, NumericValue):
769769
def std(
770770
self,
771+
*,
771772
where: ir.BooleanValue | None = None,
772773
how: Literal["sample", "pop"] = "sample",
773774
) -> NumericScalar:
@@ -818,6 +819,7 @@ def std(
818819

819820
def var(
820821
self,
822+
*,
821823
where: ir.BooleanValue | None = None,
822824
how: Literal["sample", "pop"] = "sample",
823825
) -> NumericScalar:
@@ -869,6 +871,8 @@ def var(
869871
def corr(
870872
self,
871873
right: NumericColumn,
874+
/,
875+
*,
872876
where: ir.BooleanValue | None = None,
873877
how: Literal["sample", "pop"] = "sample",
874878
) -> NumericScalar:
@@ -926,6 +930,8 @@ def corr(
926930
def cov(
927931
self,
928932
right: NumericColumn,
933+
/,
934+
*,
929935
where: ir.BooleanValue | None = None,
930936
how: Literal["sample", "pop"] = "sample",
931937
) -> NumericScalar:
@@ -984,10 +990,7 @@ def cov(
984990
where=self._bind_to_parent_table(where),
985991
).to_expr()
986992

987-
def mean(
988-
self,
989-
where: ir.BooleanValue | None = None,
990-
) -> NumericScalar:
993+
def mean(self, *, where: ir.BooleanValue | None = None) -> NumericScalar:
991994
"""Return the mean of a numeric column.
992995
993996
Parameters
@@ -1091,10 +1094,7 @@ def cummean(self, *, where=None, group_by=None, order_by=None) -> NumericColumn:
10911094
ibis.cumulative_window(group_by=group_by, order_by=order_by)
10921095
)
10931096

1094-
def sum(
1095-
self,
1096-
where: ir.BooleanValue | None = None,
1097-
) -> NumericScalar:
1097+
def sum(self, *, where: ir.BooleanValue | None = None) -> NumericScalar:
10981098
"""Return the sum of a numeric column.
10991099
11001100
Parameters
@@ -1362,6 +1362,8 @@ def histogram(
13621362
def approx_quantile(
13631363
self,
13641364
quantile: float | ir.NumericValue | Sequence[ir.NumericValue | float],
1365+
/,
1366+
*,
13651367
where: ir.BooleanValue | None = None,
13661368
) -> NumericScalar:
13671369
"""Compute one or more approximate quantiles of a column.
@@ -1600,7 +1602,7 @@ class IntegerScalar(NumericScalar, IntegerValue):
16001602

16011603
@public
16021604
class IntegerColumn(NumericColumn, IntegerValue):
1603-
def bit_and(self, where: ir.BooleanValue | None = None) -> IntegerScalar:
1605+
def bit_and(self, *, where: ir.BooleanValue | None = None) -> IntegerScalar:
16041606
"""Aggregate the column using the bitwise and operator.
16051607
16061608
Examples
@@ -1619,7 +1621,7 @@ def bit_and(self, where: ir.BooleanValue | None = None) -> IntegerScalar:
16191621
"""
16201622
return ops.BitAnd(self, where=self._bind_to_parent_table(where)).to_expr()
16211623

1622-
def bit_or(self, where: ir.BooleanValue | None = None) -> IntegerScalar:
1624+
def bit_or(self, *, where: ir.BooleanValue | None = None) -> IntegerScalar:
16231625
"""Aggregate the column using the bitwise or operator.
16241626
16251627
Examples
@@ -1638,7 +1640,7 @@ def bit_or(self, where: ir.BooleanValue | None = None) -> IntegerScalar:
16381640
"""
16391641
return ops.BitOr(self, where=self._bind_to_parent_table(where)).to_expr()
16401642

1641-
def bit_xor(self, where: ir.BooleanValue | None = None) -> IntegerScalar:
1643+
def bit_xor(self, *, where: ir.BooleanValue | None = None) -> IntegerScalar:
16421644
"""Aggregate the column using the bitwise exclusive or operator.
16431645
16441646
Examples

ibis/expr/types/relations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@ def filter(
25162516
raise com.IbisInputError("You must pass at least one predicate to filter")
25172517
return ops.Filter(self, preds).to_expr()
25182518

2519-
def nunique(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
2519+
def nunique(self, *, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
25202520
"""Compute the number of unique rows in the table.
25212521
25222522
Parameters
@@ -2548,7 +2548,7 @@ def nunique(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
25482548
┌───┐
25492549
│ 2 │
25502550
└───┘
2551-
>>> t.nunique(t.a != "foo")
2551+
>>> t.nunique(where=t.a != "foo")
25522552
┌───┐
25532553
│ 1 │
25542554
└───┘
@@ -2557,7 +2557,7 @@ def nunique(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
25572557
(where,) = bind(self, where)
25582558
return ops.CountDistinctStar(self, where=where).to_expr()
25592559

2560-
def count(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
2560+
def count(self, *, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
25612561
"""Compute the number of rows in the table.
25622562
25632563
Parameters
@@ -2589,7 +2589,7 @@ def count(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
25892589
┌───┐
25902590
│ 3 │
25912591
└───┘
2592-
>>> t.count(t.a != "foo")
2592+
>>> t.count(where=t.a != "foo")
25932593
┌───┐
25942594
│ 2 │
25952595
└───┘

0 commit comments

Comments
 (0)