Skip to content

Commit

Permalink
perf(drop): use _fast_bind to speed up drop even more (#9646)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored Jul 22, 2024
1 parent f3ed10c commit 4f39d69
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -236,7 +236,28 @@ def bind(self, *args, **kwargs):
)
(value,) = bindings
values.append(value.name(key))
return values

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())
result = []
Expand Down Expand Up @@ -2488,7 +2509,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()

Expand Down

0 comments on commit 4f39d69

Please sign in to comment.