Skip to content

Commit 6278f7e

Browse files
committed
refactor(api): remove IntegerValue.label
BREAKING CHANGE: `IntegerValue.label` is redundant with the `IntegerValue.cases` method, use that instead. Replace `expr.label(labels)` with `expr.cases(*enumerate(labels))`
1 parent ee976c4 commit 6278f7e

File tree

4 files changed

+35
-79
lines changed

4 files changed

+35
-79
lines changed

ibis/backends/impala/tests/test_bucket_histogram.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def test_bucket_assign_labels(table, snapshot):
8181
bucket = table.f.bucket(buckets, include_under=True)
8282

8383
size = table.group_by(bucket.name("tier")).size()
84-
labelled = size.tier.label(
85-
["Under 0", "0 to 10", "10 to 25", "25 to 50"], nulls="error"
84+
labelled = size.tier.cases(
85+
*enumerate(["Under 0", "0 to 10", "10 to 25", "25 to 50"]), else_="error"
8686
).name("tier2")
8787
expr = size.select(labelled, size[1])
8888

ibis/backends/postgres/tests/test_functions.py

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -357,21 +357,14 @@ def test_coalesce(con, expr, expected):
357357

358358

359359
@pytest.mark.parametrize(
360-
("expr", "expected"),
360+
"expr",
361361
[
362-
param(ibis.coalesce(ibis.null(), ibis.null()), None, id="all_null"),
363-
param(
364-
ibis.coalesce(
365-
ibis.null().cast("int8"),
366-
ibis.null().cast("int8"),
367-
ibis.null().cast("int8"),
368-
),
369-
None,
370-
id="all_nulls_with_all_cast",
371-
),
362+
ibis.coalesce(*([ibis.null()] * 2)),
363+
ibis.coalesce(*([ibis.null().cast("int8")] * 3)),
372364
],
365+
ids=["all", "all_with_cast"],
373366
)
374-
def test_coalesce_all_na(con, expr, expected):
367+
def test_coalesce_all_na(con, expr):
375368
assert con.execute(expr) is None
376369

377370

@@ -469,7 +462,7 @@ def test_category_label(alltypes, df):
469462
bins = [0, 10, 25, 50, 100]
470463
labels = ["a", "b", "c", "d"]
471464
bucket = d.bucket(bins)
472-
expr = bucket.label(labels)
465+
expr = bucket.cases(*enumerate(labels), else_=None)
473466
result = expr.execute()
474467

475468
with warnings.catch_warnings():
@@ -497,68 +490,68 @@ def test_union_cte(alltypes, distinct, assert_sql):
497490
("func", "pandas_func"),
498491
[
499492
param(
500-
lambda t, cond: t.bool_col.count(),
501-
lambda df, cond: df.bool_col.count(),
493+
lambda t, _: t.bool_col.count(),
494+
lambda df, _: df.bool_col.count(),
502495
id="count",
503496
),
504497
param(
505-
lambda t, cond: t.bool_col.any(),
506-
lambda df, cond: df.bool_col.any(),
498+
lambda t, _: t.bool_col.any(),
499+
lambda df, _: df.bool_col.any(),
507500
id="any",
508501
),
509502
param(
510-
lambda t, cond: t.bool_col.all(),
511-
lambda df, cond: df.bool_col.all(),
503+
lambda t, _: t.bool_col.all(),
504+
lambda df, _: df.bool_col.all(),
512505
id="all",
513506
),
514507
param(
515-
lambda t, cond: t.bool_col.notany(),
516-
lambda df, cond: ~df.bool_col.any(),
508+
lambda t, _: t.bool_col.notany(),
509+
lambda df, _: ~df.bool_col.any(),
517510
id="notany",
518511
),
519512
param(
520-
lambda t, cond: t.bool_col.notall(),
521-
lambda df, cond: ~df.bool_col.all(),
513+
lambda t, _: t.bool_col.notall(),
514+
lambda df, _: ~df.bool_col.all(),
522515
id="notall",
523516
),
524517
param(
525-
lambda t, cond: t.double_col.sum(),
526-
lambda df, cond: df.double_col.sum(),
518+
lambda t, _: t.double_col.sum(),
519+
lambda df, _: df.double_col.sum(),
527520
id="sum",
528521
),
529522
param(
530-
lambda t, cond: t.double_col.mean(),
531-
lambda df, cond: df.double_col.mean(),
523+
lambda t, _: t.double_col.mean(),
524+
lambda df, _: df.double_col.mean(),
532525
id="mean",
533526
),
534527
param(
535-
lambda t, cond: t.double_col.min(),
536-
lambda df, cond: df.double_col.min(),
528+
lambda t, _: t.double_col.min(),
529+
lambda df, _: df.double_col.min(),
537530
id="min",
538531
),
539532
param(
540-
lambda t, cond: t.double_col.max(),
541-
lambda df, cond: df.double_col.max(),
533+
lambda t, _: t.double_col.max(),
534+
lambda df, _: df.double_col.max(),
542535
id="max",
543536
),
544537
param(
545-
lambda t, cond: t.double_col.var(),
546-
lambda df, cond: df.double_col.var(),
538+
lambda t, _: t.double_col.var(),
539+
lambda df, _: df.double_col.var(),
547540
id="var",
548541
),
549542
param(
550-
lambda t, cond: t.double_col.std(),
551-
lambda df, cond: df.double_col.std(),
543+
lambda t, _: t.double_col.std(),
544+
lambda df, _: df.double_col.std(),
552545
id="std",
553546
),
554547
param(
555-
lambda t, cond: t.double_col.var(how="sample"),
556-
lambda df, cond: df.double_col.var(ddof=1),
548+
lambda t, _: t.double_col.var(how="sample"),
549+
lambda df, _: df.double_col.var(ddof=1),
557550
id="samp_var",
558551
),
559552
param(
560-
lambda t, cond: t.double_col.std(how="pop"),
561-
lambda df, cond: df.double_col.std(ddof=0),
553+
lambda t, _: t.double_col.std(how="pop"),
554+
lambda df, _: df.double_col.std(ddof=0),
562555
id="pop_std",
563556
),
564557
param(

ibis/backends/risingwave/tests/test_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def test_category_label(alltypes, df):
301301
bins = [0, 10, 25, 50, 100]
302302
labels = ["a", "b", "c", "d"]
303303
bucket = d.bucket(bins)
304-
expr = bucket.label(labels)
304+
expr = bucket.cases(*enumerate(labels), else_=None)
305305
result = expr.execute()
306306

307307
with warnings.catch_warnings():

ibis/expr/types/numeric.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from ibis.util import deprecated
1414

1515
if TYPE_CHECKING:
16-
from collections.abc import Iterable
17-
1816
import ibis.expr.types as ir
1917

2018

@@ -1594,41 +1592,6 @@ def __invert__(self) -> IntegerValue:
15941592
else:
15951593
return node.to_expr()
15961594

1597-
def label(self, labels: Iterable[str], nulls: str | None = None) -> ir.StringValue:
1598-
"""Label a set of integer values with strings.
1599-
1600-
Parameters
1601-
----------
1602-
labels
1603-
An iterable of string labels. Each integer value in `self` will be mapped to
1604-
a value in `labels`.
1605-
nulls
1606-
String label to use for `NULL` values
1607-
1608-
Returns
1609-
-------
1610-
StringValue
1611-
`self` labeled with `labels`
1612-
1613-
Examples
1614-
--------
1615-
>>> import ibis
1616-
>>> ibis.options.interactive = True
1617-
>>> t = ibis.memtable({"a": [0, 1, 0, 2]})
1618-
>>> t.select(t.a, labeled=t.a.label(["a", "b", "c"]))
1619-
┏━━━━━━━┳━━━━━━━━━┓
1620-
┃ a ┃ labeled ┃
1621-
┡━━━━━━━╇━━━━━━━━━┩
1622-
│ int64 │ string │
1623-
├───────┼─────────┤
1624-
│ 0 │ a │
1625-
│ 1 │ b │
1626-
│ 0 │ a │
1627-
│ 2 │ c │
1628-
└───────┴─────────┘
1629-
"""
1630-
return self.cases(*enumerate(labels), else_=nulls)
1631-
16321595

16331596
@public
16341597
class IntegerScalar(NumericScalar, IntegerValue):

0 commit comments

Comments
 (0)