Skip to content

Commit 7706a86

Browse files
cpcloudkszucs
authored andcommitted
depr(api): deprecate .to_projection in favor of .as_table
1 parent 4a1c7c9 commit 7706a86

File tree

7 files changed

+13
-11
lines changed

7 files changed

+13
-11
lines changed

ibis/backends/base/sql/compiler/select_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def _adapt_operation(node):
9999
table_expr = node.table.to_expr()[[node.name]]
100100
result_handler = _get_column(node.name)
101101
else:
102-
table_expr = node.to_expr().to_projection()
102+
table_expr = node.to_expr().as_table()
103103
result_handler = _get_column(node.name)
104104

105105
return table_expr.op(), result_handler

ibis/backends/base/sql/registry/binary_infix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def translate(translator, op):
7272
ctx.is_foreign_expr(leaf)
7373
for leaf in an.find_immediate_parent_tables(op.options)
7474
):
75-
array = op.options.to_expr().to_projection().to_array().op()
75+
array = op.options.to_expr().as_table().to_array().op()
7676
right = table_array_view(translator, array)
7777
else:
7878
right = translator.translate(op.options)

ibis/backends/datafusion/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ def _get_frame(
213213
return self.compile(expr, params, **kwargs)
214214
elif isinstance(expr, ir.Column):
215215
# expression must be named for the projection
216-
expr = expr.name('tmp').to_projection()
216+
expr = expr.name('tmp').as_table()
217217
return self.compile(expr, params, **kwargs)
218218
elif isinstance(expr, ir.Scalar):
219219
if an.find_immediate_parent_tables(expr.op()):
220220
# there are associated datafusion tables so convert the expr
221221
# to a selection which we can directly convert to a datafusion
222222
# plan
223-
expr = expr.name('tmp').to_projection()
223+
expr = expr.name('tmp').as_table()
224224
frame = self.compile(expr, params, **kwargs)
225225
else:
226226
# doesn't have any tables associated so create a plan from a

ibis/backends/pandas/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def _apply_schema(op: ops.Node, result: pd.DataFrame | pd.Series):
505505
schema = op.schema
506506
return schema.apply_to(df.loc[:, list(schema.names)])
507507
elif isinstance(result, pd.Series):
508-
schema = op.to_expr().to_projection().schema()
508+
schema = op.to_expr().as_table().schema()
509509
return schema.apply_to(result.to_frame()).iloc[:, 0].reset_index(drop=True)
510510
return result
511511

ibis/backends/polars/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def compile(
252252
return translate(node)
253253
elif isinstance(expr, ir.Column):
254254
# expression must be named for the projection
255-
node = expr.to_projection().op()
255+
node = expr.as_table().op()
256256
return translate(node)
257257
elif isinstance(expr, ir.Scalar):
258258
if an.is_scalar_reduction(node):

ibis/expr/types/generic.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import ibis.common.exceptions as com
1010
import ibis.expr.datatypes as dt
1111
import ibis.expr.operations as ops
12+
from ibis import util
1213
from ibis.common.grounds import Singleton
1314
from ibis.expr.types.core import Expr, _binop
1415

@@ -480,7 +481,11 @@ def desc(self) -> ir.Value:
480481
"""Sort an expression descending."""
481482
return ops.SortKey(self, ascending=False).to_expr()
482483

484+
@util.deprecated(version="5.0", instead="use `.as_table()`")
483485
def to_projection(self) -> ir.Table:
486+
return self.as_table()
487+
488+
def as_table(self) -> ir.Table:
484489
"""Promote this value expression to a projection."""
485490
from ibis.expr.analysis import find_immediate_parent_tables
486491

@@ -492,7 +497,7 @@ def to_projection(self) -> ir.Table:
492497
'to a projection'
493498
)
494499
table = roots[0].to_expr()
495-
return table.projection([self])
500+
return table.select(self)
496501

497502

498503
@public
@@ -536,9 +541,6 @@ class Column(Value, JupyterMixin):
536541
def __array__(self, dtype=None):
537542
return self.execute().__array__(dtype)
538543

539-
def as_table(self):
540-
return self.to_projection()
541-
542544
def __rich_console__(self, console, options):
543545
named = self.name(self.op().name)
544546
projection = named.as_table()

ibis/tests/expr/mocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def execute(self, expr, limit=None, params=None, **kwargs):
395395
try:
396396
schema = expr.schema()
397397
except AttributeError:
398-
schema = expr.to_projection().schema()
398+
schema = expr.as_table().schema()
399399
df = schema.apply_to(pd.DataFrame([], columns=schema.names))
400400
if isinstance(expr, ir.Scalar):
401401
return None

0 commit comments

Comments
 (0)