question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ux(sql): unhelpful assertion error message: `AssertionError: num_froms == 2`

See original GitHub issue

Here 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:open
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cpcloudcommented, Nov 3, 2022

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.

1reaction
cpcloudcommented, Oct 29, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found