Skip to content

Commit e6372e2

Browse files
cpcloudkszucs
authored andcommitted
depr(api): deprecate get_column/s in favor of __getitem__/__getattr__ syntax
1 parent 42d95b0 commit e6372e2

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

ibis/expr/sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def convert_binary(binary, catalog):
233233
# expr is a table expression
234234
assert len(expr.columns) == 1
235235
name = expr.columns[0]
236-
expr = expr.get_column(name)
236+
expr = expr[name]
237237

238238
return op(this, expr)
239239

ibis/expr/types/relations.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __getitem__(self, what):
115115
from ibis.expr.types.logical import BooleanValue
116116

117117
if isinstance(what, (str, int)):
118-
return self.get_column(what)
118+
return ops.TableColumn(self, what).to_expr()
119119

120120
if isinstance(what, slice):
121121
step = what.step
@@ -154,7 +154,7 @@ def __len__(self):
154154

155155
def __getattr__(self, key):
156156
with contextlib.suppress(com.IbisTypeError):
157-
return self.get_column(key)
157+
return ops.TableColumn(self, key).to_expr()
158158

159159
# Handle deprecated `groupby` and `sort_by` methods
160160
if key == "groupby":
@@ -210,33 +210,39 @@ def _ensure_expr(self, expr):
210210
else:
211211
return expr
212212

213+
@util.deprecated(
214+
version="5.0", instead="use a list comprehension and attribute/getitem syntax"
215+
)
213216
def get_columns(self, iterable: Iterable[str]) -> list[Column]:
214217
"""Get multiple columns from the table.
215218
219+
Parameters
220+
----------
221+
iterable
222+
An iterable of column names
223+
216224
Examples
217225
--------
218226
>>> import ibis
219-
>>> table = ibis.table(
220-
... [
221-
... ('a', 'int64'),
222-
... ('b', 'string'),
223-
... ('c', 'timestamp'),
224-
... ('d', 'float'),
225-
... ],
226-
... name='t'
227-
... )
227+
>>> table = ibis.table(dict(a='int64', b='string', c='timestamp', d='float'))
228228
>>> a, b, c = table.get_columns(['a', 'b', 'c'])
229229
230230
Returns
231231
-------
232232
list[ir.Column]
233233
List of column expressions
234234
"""
235-
return [self.get_column(x) for x in iterable]
235+
return list(map(self.get_column, iterable))
236236

237+
@util.deprecated(version="5.0", instead="use t.<name> or t[name]")
237238
def get_column(self, name: str) -> Column:
238239
"""Get a reference to a single column from the table.
239240
241+
Parameters
242+
----------
243+
name
244+
A column name
245+
240246
Returns
241247
-------
242248
Column

0 commit comments

Comments
 (0)