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

feat(consider): Make isinstance(ibis.Deferred, ibis.Value) return true #9936

Closed
1 task done
NickCrews opened this issue Aug 27, 2024 · 1 comment
Closed
1 task done
Labels
feature Features or general enhancements

Comments

@NickCrews
Copy link
Contributor

Is your feature request related to a problem?

I have several util functions that I want to make polymorphic between ibis and vanilla python types:

def odds_to_prob(odds):
    normal = odds / (1 + odds)
    if isinstance(odds, (Deferred, ir.NumericValue)):
        return ibis.ifelse(odds.isinf(), 1.0, normal)
    else:
        return 1 if odds == float("inf") else normal

def round_to(nums: ir.NumericValue | Deferred | int | float, n: int) -> ir.IntegerValue:
    """Round to the nearest n, eg 5.

    eg with n=5:
    0 -> 0
    1 -> 0
    2 -> 0
    3 -> 5
    4 -> 5
    5 -> 5
    """
    if not isinstance(n, int):
        raise TypeError(f"n must be int, not {type(n)}")
    if isinstance(nums, (ir.NumericValue, Deferred)):
        return (nums / n).round().cast(int) * n
    else:
        return round(nums / n) * n

The first time I implemented these, I forgot to include the Deferred in the instance check, and that led to errors. Really what I am trying to test for is "is this an ibis thing that I can call ibis APIs on?" IDK, it might be a nice to help users avoid footguns like I ran into. On the other hand, maybe I should be forced to be explicit here.

I thought I would throw this up for discussion.

What is the motivation behind your request?

No response

Describe the solution you'd like

Make isinstance(ibis.Deferred, ir.Value) return True

What version of ibis are you running?

main

What backend(s) are you using, if any?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@NickCrews NickCrews added the feature Features or general enhancements label Aug 27, 2024
@ibis-project ibis-project deleted a comment Aug 27, 2024
@ibis-project ibis-project deleted a comment from amir1387aht Aug 27, 2024
@ibis-project ibis-project deleted a comment Aug 27, 2024
@cpcloud
Copy link
Member

cpcloud commented Aug 28, 2024

@NickCrews I think this is out of scope for Ibis. Deferred and Value are quite different and need to be handled separately.

@cpcloud cpcloud closed this as not planned Won't fix, can't repro, duplicate, stale Aug 28, 2024
@github-project-automation github-project-automation bot moved this from backlog to done in Ibis planning and roadmap Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Features or general enhancements
Projects
Archived in project
Development

No branches or pull requests

2 participants