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

bug: module 'ibis' has no attribute 'cases'. #10371

Closed
1 task done
jongmmm opened this issue Oct 25, 2024 · 1 comment
Closed
1 task done

bug: module 'ibis' has no attribute 'cases'. #10371

jongmmm opened this issue Oct 25, 2024 · 1 comment
Labels
bug Incorrect behavior inside of ibis

Comments

@jongmmm
Copy link

jongmmm commented Oct 25, 2024

What happened?

I ran the example code from here copied below:

import ibis
ibis.options.interactive = True
v = ibis.memtable({"values": [1, 2, 1, 2, 3, 2, 4]}).values
ibis.cases((v == 1, "a"), (v > 2, "b"), else_="unk").name("cases")

Then got the below error:

AttributeError: module 'ibis' has no attribute 'cases'.

What version of ibis are you using?

9.5.0

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

No response

Relevant log output

In [7]: >>> import ibis
   ...: >>> ibis.options.interactive = True
   ...: >>> v = ibis.memtable({"values": [1, 2, 1, 2, 3, 2, 4]}).values
   ...: >>> ibis.cases((v == 1, "a"), (v > 2, "b"), else_="unk").name("cases")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [7], line 4
      2 ibis.options.interactive = True
      3 v = ibis.memtable({"values": [1, 2, 1, 2, 3, 2, 4]}).values
----> 4 ibis.cases((v == 1, "a"), (v > 2, "b"), else_="unk").name("cases")

File ~/micromamba/envs/gym/lib/python3.10/site-packages/ibis/__init__.py:142, in __getattr__(name)
    140     return null()  # noqa: F405
    141 else:
--> 142     return load_backend(name)

File ~/micromamba/envs/gym/lib/python3.10/site-packages/ibis/__init__.py:66, in load_backend(name)
     63     if name in _KNOWN_BACKENDS:
     64         msg += f"""If you are trying to access the '{name}' backend,
     65                 try installing it first with `pip install 'ibis-framework[{name}]'`"""
---> 66     raise AttributeError(msg)
     68 if len(entry_points) > 1:
     69     raise RuntimeError(
     70         f"{len(entry_points)} packages found for backend '{name}': "
     71         f"{entry_points}\n"
     72         "There should be only one, please uninstall the unused packages "
     73         "and just leave the one that needs to be used."
     74     )

AttributeError: module 'ibis' has no attribute 'cases'.

In [8]: import ibis
   ...: ibis.options.interactive = True
   ...: ibis.memtable({"values": [1, 2, 1, 2, 3, 2, 4]}).values
   ...: ibis.cases((v == 1, "a"), (v > 2, "b"), else_="unk").name("cases")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [8], line 4
      2 ibis.options.interactive = True
      3 ibis.memtable({"values": [1, 2, 1, 2, 3, 2, 4]}).values
----> 4 ibis.cases((v == 1, "a"), (v > 2, "b"), else_="unk").name("cases")

File ~/micromamba/envs/gym/lib/python3.10/site-packages/ibis/__init__.py:142, in __getattr__(name)
    140     return null()  # noqa: F405
    141 else:
--> 142     return load_backend(name)

File ~/micromamba/envs/gym/lib/python3.10/site-packages/ibis/__init__.py:66, in load_backend(name)
     63     if name in _KNOWN_BACKENDS:
     64         msg += f"""If you are trying to access the '{name}' backend,
     65                 try installing it first with `pip install 'ibis-framework[{name}]'`"""
---> 66     raise AttributeError(msg)
     68 if len(entry_points) > 1:
     69     raise RuntimeError(
     70         f"{len(entry_points)} packages found for backend '{name}': "
     71         f"{entry_points}\n"
     72         "There should be only one, please uninstall the unused packages "
     73         "and just leave the one that needs to be used."
     74     )

AttributeError: module 'ibis' has no attribute 'cases'.

In [9]: ibis.__version__
Out[9]: '9.5.0'

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jongmmm jongmmm added the bug Incorrect behavior inside of ibis label Oct 25, 2024
@NickCrews
Copy link
Contributor

NickCrews commented Oct 25, 2024

We recently migrated from a .case() API to a .cases() API. The docs show this new API, but we haven't released this new version yet. Once we release the new version, that code snippet will work. See these archived docs on how to use .case() in the meantime.

Or, if you know what you are doing, monkeypatch in this new API in the meantime, and then delete this once 10.0 comes out.

from ibis.expr import types as it
import ibis

def cases(
     branch: tuple[ir.BooleanValue, ir.Value],
    *branches: tuple[ir.BooleanValue, ir.Value],
    else_: ir.Value | None = None,
) -> ir.Value:
    builder = ibis.case()
    builder = builder.when(*branch)
    for case, result in branches:
        builder = builder.when(case, result)
    return builder.else_(else_).end()

ibis.cases = cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior inside of ibis
Projects
Archived in project
Development

No branches or pull requests

2 participants