From 6ec612541b141f2f744443743db4d1b337300543 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Sun, 21 Jul 2024 06:41:03 -0400 Subject: [PATCH 1/3] refactor(perf): add `_fast_bind` to skip dereferencing for `str` and selectors --- ibis/expr/types/relations.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ibis/expr/types/relations.py b/ibis/expr/types/relations.py index f66d6d64c0c0..aa09e54a1680 100644 --- a/ibis/expr/types/relations.py +++ b/ibis/expr/types/relations.py @@ -213,7 +213,7 @@ def __polars_result__(self, df: pl.DataFrame) -> Any: return PolarsData.convert_table(df, self.schema()) - def bind(self, *args, **kwargs): + def _fast_bind(self, *args, **kwargs): # allow the first argument to be either a dictionary or a list of values if len(args) == 1: if isinstance(args[0], dict): @@ -236,7 +236,10 @@ def bind(self, *args, **kwargs): ) (value,) = bindings values.append(value.name(key)) + return values + def bind(self, *args, **kwargs): + values = self._fast_bind(*args, **kwargs) # dereference the values to `self` dm = DerefMap.from_targets(self.op()) result = [] From 5d4a099d02c799ea851f75f19d0548ff07157744 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Sun, 21 Jul 2024 06:41:35 -0400 Subject: [PATCH 2/3] perf(drop): use `_fast_bind` to speed up `drop` even more --- ibis/expr/types/relations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibis/expr/types/relations.py b/ibis/expr/types/relations.py index aa09e54a1680..5ed4eceb813c 100644 --- a/ibis/expr/types/relations.py +++ b/ibis/expr/types/relations.py @@ -2491,7 +2491,7 @@ def drop(self, *fields: str | Selector) -> Table: return self columns_to_drop = tuple( - map(operator.methodcaller("get_name"), self.bind(*fields)) + map(operator.methodcaller("get_name"), self._fast_bind(*fields)) ) return ops.DropColumns(parent=self, columns_to_drop=columns_to_drop).to_expr() From 13b7b9d4db89927ac440a2a6d2dfaf2f06c76f3e Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Sun, 21 Jul 2024 07:07:14 -0400 Subject: [PATCH 3/3] docs(api): document `Table.bind` --- ibis/expr/types/relations.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ibis/expr/types/relations.py b/ibis/expr/types/relations.py index 5ed4eceb813c..1e9c958e0775 100644 --- a/ibis/expr/types/relations.py +++ b/ibis/expr/types/relations.py @@ -238,7 +238,25 @@ def _fast_bind(self, *args, **kwargs): values.append(value.name(key)) return values - def bind(self, *args, **kwargs): + def bind(self, *args: Any, **kwargs: Any) -> tuple[Value, ...]: + """Bind column values to a table expression. + + This method handles the binding of every kind of column-like value that + Ibis handles, including strings, integers, deferred expressions and + selectors, to a table expression. + + Parameters + ---------- + args + Column-like values to bind. + kwargs + Column-like values to bind, with names. + + Returns + ------- + tuple[Value, ...] + A tuple of bound values + """ values = self._fast_bind(*args, **kwargs) # dereference the values to `self` dm = DerefMap.from_targets(self.op())