ux(sql): unhelpful assertion error message: `AssertionError: num_froms == 2`
See original GitHub issueHere is one way to trigger it:
>>> import numpy as np
>>> import pandas as pd
>>> import ibis
>>> df = pd.DataFrame({"a": np.random.randn(10000)})
>>> t = ibis.memtable(df)
>>> t.mutate(chunk=ibis.row_number() // 100).group_by(ibis._.chunk).aggregate(b=t.a.mean()).execute()
Traceback (most recent call last):
Input In [5] in <cell line: 5>
t.mutate(chunk=ibis.row_number() // 100).group_by(ibis._.chunk).aggregate(b=t.a.mean()).execute()
File ~/code/ibis/ibis/expr/types/core.py:274 in execute
return self._find_backend(use_default=True).execute(
File ~/code/ibis/ibis/backends/base/sql/__init__.py:247 in execute
sql = query_ast.compile()
File ~/code/ibis/ibis/backends/base/sql/compiler/base.py:39 in compile
compiled_queries = [q.compile() for q in self.queries]
File ~/code/ibis/ibis/backends/base/sql/compiler/base.py:39 in <listcomp>
compiled_queries = [q.compile() for q in self.queries]
File ~/code/ibis/ibis/backends/base/sql/alchemy/query_builder.py:186 in compile
frag = step(frag)
File ~/code/ibis/ibis/backends/base/sql/alchemy/query_builder.py:279 in _add_select
assert num_froms == 1, f"num_froms == {num_froms:d}"
AssertionError: num_froms == 2
while using a deferred field reference would have worked:
>>> t.mutate(chunk=ibis.row_number() // 100).group_by(ibis._.chunk).aggregate(b=ibis._.a.mean()).execute()
chunk b
0 0 -0.002539
1 1 0.211258
2 2 -0.034153
3 3 0.054345
4 4 -0.063897
.. ... ...
95 83 0.077232
96 87 -0.018670
97 91 -0.153058
98 95 0.062328
99 99 -0.131931
[100 rows x 2 columns]
I am not sure if this is a bug or just a bad error message.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Assertion error when you run internal query in batch mode for ...
Assume that you have full-text index on a computed large object (LOB) column for a table in SQL Server 2019. When batch mode...
Read more >AssertionError: assertion failed: No plan for DeleteFromTable ...
I'm new to Databricks but I'm sure I ran similar command on another table (without WHERE clause). The table is created basing on...
Read more >SQL Server Assertion Error – SQLServerCentral Forums
Hi,. We have started to receive the error below for a couple of months now, I have executed a number of DBCC CheckDB...
Read more >#24525 (AssertionError at `Query.change_aliases`) – Django
I'm getting an assertion error on the first line of Query.change_aliases : assert set(change_map.keys()).intersection(set(change_map.values())) == set().
Read more >assertion failed: Unable to delete the record but I am able to ...
Error in SQL statement: AssertionError: assertion failed: No plan for ... on the Parquet files - right now on Databricks, it's supported for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Generally speaking you’ll probably have a bad time if you reference tables further down the tree than the current table. In some cases ibis tries to be smart and infer what you mean (in this case when you reference
t
), but fails to actually be smart and this is a case of that.The assertion is correct but you shouldn’t be hitting it. We need to catch the error earlier and give a more helpful and more usefully-typed message.