Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(drop): use _fast_bind to speed up drop even more #9646

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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