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: can't use ArrayValue.filter() and friends with Deferreds #7626

Closed
1 task done
NickCrews opened this issue Nov 27, 2023 · 1 comment · Fixed by #7956
Closed
1 task done

bug: can't use ArrayValue.filter() and friends with Deferreds #7626

NickCrews opened this issue Nov 27, 2023 · 1 comment · Fixed by #7956
Labels
bug Incorrect behavior inside of ibis ux User experience related issues

Comments

@NickCrews
Copy link
Contributor

NickCrews commented Nov 27, 2023

What happened?

import ibis
from ibis import _

ibis.options.interactive = True

t = ibis.memtable({"x": [[1, 2, 3]]})
t.mutate(t.x.filter(lambda y: y == 2))  # works
t.mutate(t.x.map(lambda y: y + 1))  # works
t.mutate(_.x.filter(lambda y: y == 2))  # error
t.mutate(_.x.map(lambda y: y + 1))  # error

See log below.

What version of ibis are you using?

d6a2f09 (master as of this posting)

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

NA

Relevant log output

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/nc/code/ibis/.scratch/deferred_filter.ipynb Cell 1 line 1
      8 t = ibis.memtable({"x": [[1, 2, 3]]})
      9 t.mutate(t.x.filter(lambda y: y == 2))  # works
---> 10 t.mutate(_.x.filter(lambda y: y == 2))  # error

File ~/code/ibis/ibis/expr/types/relations.py:1813, in Table.mutate(self, exprs, **mutations)
   1802 exprs = [] if exprs is None else util.promote_list(exprs)
   1803 exprs = itertools.chain(
   1804     itertools.chain.from_iterable(
   1805         util.promote_list(_ensure_expr(self, expr)) for expr in exprs
   (...)
   1811     ),
   1812 )
-> 1813 mutation_exprs = an.get_mutation_exprs(list(exprs), self)
   1814 return self.select(mutation_exprs)

File ~/code/ibis/ibis/expr/types/relations.py:1805, in <genexpr>(.0)
   1800 import ibis.expr.analysis as an
   1802 exprs = [] if exprs is None else util.promote_list(exprs)
   1803 exprs = itertools.chain(
   1804     itertools.chain.from_iterable(
-> 1805         util.promote_list(_ensure_expr(self, expr)) for expr in exprs
   1806     ),
   1807     (
   1808         e.name(name)
   1809         for name, expr in mutations.items()
   1810         for e in util.promote_list(_ensure_expr(self, expr))
   1811     ),
   1812 )
   1813 mutation_exprs = an.get_mutation_exprs(list(exprs), self)
   1814 return self.select(mutation_exprs)

File ~/code/ibis/ibis/expr/types/relations.py:50, in _ensure_expr(table, expr)
     48     return expr(table)
     49 elif isinstance(expr, Deferred):
---> 50     return expr.resolve(table)
     51 elif isinstance(expr, Selector):
     52     return expr.expand(table)

File ~/code/ibis/ibis/common/deferred.py:87, in Deferred.resolve(self, _, **kwargs)
     85 def resolve(self, _=None, **kwargs):
     86     context = {"_": _, **kwargs}
---> 87     return self._resolver.resolve(context)

File ~/code/ibis/ibis/common/deferred.py:391, in Call.resolve(self, context)
    389 def resolve(self, context):
    390     func = self.func.resolve(context)
--> 391     args = tuple(arg.resolve(context) for arg in self.args)
    392     kwargs = {k: v.resolve(context) for k, v in self.kwargs.items()}
    393     return func(*args, **kwargs)

File ~/code/ibis/ibis/common/deferred.py:391, in <genexpr>(.0)
    389 def resolve(self, context):
    390     func = self.func.resolve(context)
--> 391     args = tuple(arg.resolve(context) for arg in self.args)
    392     kwargs = {k: v.resolve(context) for k, v in self.kwargs.items()}
    393     return func(*args, **kwargs)

File ~/code/ibis/ibis/common/deferred.py:313, in Factory.resolve(self, context)
    312 def resolve(self, context):
--> 313     return self.func(**context)

TypeError: <lambda>() got an unexpected keyword argument '_'

Code of Conduct

  • I agree to follow this project's Code of Conduct
@NickCrews NickCrews added the bug Incorrect behavior inside of ibis label Nov 27, 2023
@NickCrews NickCrews changed the title bug: can't use .filter() with Deferreds bug: can't use .filter() and friends with Deferreds Nov 27, 2023
@cpcloud
Copy link
Member

cpcloud commented Dec 7, 2023

@kszucs Let's make sure to add a test for this in #7580

@lostmygithubaccount lostmygithubaccount moved this from backlog to todo in Ibis planning and roadmap Dec 11, 2023
@cpcloud cpcloud added the ux User experience related issues label Dec 18, 2023
@cpcloud cpcloud changed the title bug: can't use .filter() and friends with Deferreds bug: can't use ArrayValue.filter() and friends with Deferreds Dec 31, 2023
@cpcloud cpcloud linked a pull request Jan 11, 2024 that will close this issue
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 ux User experience related issues
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants