You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously (under Ibis 7.2.0), we had defined a SAFE_CAST operation for our usage of Ibis with bigquery with the following:
importibisimportibis.expr.datatypesasdtimportibis.expr.rulesasrlzfromibis.backends.bigquery.datatypesimportBigQueryTypefromibis.expr.operations.coreimportValueasValueOpfromibis.expr.typesimportValueasValueTypeclassSafeCast(ValueOp):
"""Safe cast value or column to a specific data type."""arg: ValueOpto: dt.DataTypeshape=rlz.shape_like("arg")
@propertydefname(self): # noqareturnf"SAFE_CAST({self.arg.name} as {self.to})"@propertydefdtype(self): # noqareturnself.todefsafe_cast(col, dtype):
"""Safely cast a column to a specific data type."""returnSafeCast(col, dtype).to_expr()
@ibis.bigquery.add_operation(SafeCast)def_safe_cast_gbq(translator, expr):
arg, target_dtype=expr.argscompiled_arg=translator.translate(arg)
sql_type=BigQueryType.from_ibis(target_dtype)
returnf"SAFE_CAST({compiled_arg} as {sql_type})"ValueType.safe_cast=safe_cast
When attempting to update to Ibis 9.0.0, this broke with the error: AttributeError: 'BigQueryCompiler' object has no attribute 'translator_class'
Not sure if this is a bug or an intended change in the way a user can add an operation to Ibis
What version of ibis are you using?
7.2.0 originally, 9.0.0 for the error
What backend(s) are you using, if any?
BigQuery
Relevant log output
No response
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
Hey @DavidSlayback -- looks like we forgot to update how add_operation works with the new sqlglot backends. We'll get that fixed up for 9.1, and I'll see if I can get you a workaround in the meantime
Hey @DavidSlayback -- I forgot, we added built-in support for try_cast (or SAFE_CAST). That doesn't answer the larger issue about adding custom ops, but for your particular use-case, you can do
some_table.my_int_col.try_cast("float64")
e.g.
[ins] In [1]: importibis
[ins] In [2]: t=ibis.memtable({"b": [1, 2]})
[ins] In [3]: ibis.to_sql(t.b.try_cast("float64"), dialect="bigquery")
Out[3]:
SELECTSAFE_CAST(`t0`.`b`ASFLOAT64) AS`TryCast_b_ Float64`FROM`ibis_pandas_memtable_cywg4g55dbgethukk5btbdeyve`AS`t0`
gforsyth
changed the title
(BigQuery) Adding operations to bigquery backend fails in Ibis 9
bug: add_operation attempt to call into removed translator_classMay 8, 2024
gforsyth
changed the title
bug: add_operation attempt to call into removed translator_class
bug: add_operation attempts to call into removed translator_classMay 8, 2024
Thank you! Both for pointing to existing functionality and for considering a fix next release. Overall we get a ton of use out of this project, thanks for building it 😀
What happened?
Previously (under Ibis 7.2.0), we had defined a
SAFE_CAST
operation for our usage of Ibis with bigquery with the following:When attempting to update to Ibis 9.0.0, this broke with the error:
AttributeError: 'BigQueryCompiler' object has no attribute 'translator_class'
Not sure if this is a bug or an intended change in the way a user can add an operation to Ibis
What version of ibis are you using?
7.2.0 originally, 9.0.0 for the error
What backend(s) are you using, if any?
BigQuery
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: