-
Notifications
You must be signed in to change notification settings - Fork 608
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
feat: publicly export Deferred #7613
Comments
I think this should be exposed in this API: |
That is fine with me as long as it is canonical and stable. |
Can you provide a couple of examples where you either use |
@kszucs FWIW, I encountered this here: googleapis/python-bigquery-dataframes#53 I needed to call self._column_names = {
(
column.resolve(table)
# TODO(https://github.com/ibis-project/ibis/issues/7613): use
# public API to refer to Deferred type.
if isinstance(column, ibis.common.deferred.Deferred)
else column
).get_name(): column
for column in self._columns
} |
A polymorphic function that can either take python builtins int or float, or ibis types. Perhaps I'm not doing this the best way, if you have a way of avoiding the Deferred then I'm all ears. @overload
def round_to(nums: NumericValue | Deferred, n: int) -> NumericValue:
...
@overload
def round_to(nums: int | float, n: int) -> int:
...
def round_to(nums: NumericValue | Deferred | int | float, n: int) -> IntegerValue:
"""Round to the nearest n, eg 5."""
if isinstance(nums, (NumericValue, Deferred)):
return (nums / n).round().cast(int) * n
else:
return round(nums / n) * n
def test_round_to_deferred():
x = ibis.memtable({"inp": [1, 2, 4], "expected": [0, 0, 5]})
x = x.mutate(result=round_to(_.inp, 5))
df = x.to_pandas()
assert df["result"].equals(df["expected"]) |
@kszucs Any thoughts here based on feedback from Tim and Nick? |
I am also using it as a type annotation for a dataclass like |
Another use case I have: I have a Table -> Table function. I have some legacy pandas code that operates on DFs, but I want to use this new Table function. So I wrote I have a similar decorator for Columns/pd.Series. |
This was fixed in #9008. Closing. |
Is your feature request related to a problem?
I want to use this in type hints.
Before, I did
from ibis.expr.deferred import Deferred
but this recently broke, now I have to dofrom ibis.common.deferred import Deferred
.Describe the solution you'd like
It would be great to export this stably. just
from ibis import Deferred
should work?What version of ibis are you running?
7.1.0
What backend(s) are you using, if any?
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: