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: AttributeError: 'NoneType' object has no attribute 'pop' #8768

Closed
1 task done
yazad3 opened this issue Mar 25, 2024 · 5 comments · Fixed by #8846
Closed
1 task done

bug: AttributeError: 'NoneType' object has no attribute 'pop' #8768

yazad3 opened this issue Mar 25, 2024 · 5 comments · Fixed by #8846
Assignees
Labels
bug Incorrect behavior inside of ibis
Milestone

Comments

@yazad3
Copy link

yazad3 commented Mar 25, 2024

What happened?

Context

Not sure if this is an sqlglot bug or truely an ibis bug - but either ways would need a fix in ibis code or dependency on a certain version of sqlglot. The error AttributeError: 'NoneType' object has no attribute 'pop' is coming from deep inside sqlglot's add_within_group_for_percentiles function.

Error

Traceback (most recent call last):
  File "/Users/xyz/abc/abc_ds/trial/tests_trial/sanity/ibis/test_ibis_sanity.py", line 129, in test_sanity_snowflake
    .to_pandas()
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/ibis/expr/types/relations.py", line 3332, in to_pandas
    return self.execute(**kwargs)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/ibis/expr/types/core.py", line 359, in execute
    return self._find_backend(use_default=True).execute(
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/ibis/backends/sql/__init__.py", line 242, in execute
    sql = self.compile(table, params=params, limit=limit, **kwargs)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/ibis/backends/sql/__init__.py", line 127, in compile
    sql = query.sql(dialect=self.dialect, pretty=pretty, copy=False)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/expressions.py", line 561, in sql
    return Dialect.get_or_raise(dialect).generate(self, **opts)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/dialects/dialect.py", line 498, in generate
    return self.generator(**opts).generate(expression, copy=copy)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/generator.py", line 583, in generate
    sql = self.sql(expression).strip()
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/generator.py", line 734, in sql
    sql = transform(self, expression)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/transforms.py", line 601, in _to_sql
    return _sql_handler(expression)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/generator.py", line 2199, in select_sql
    expressions = self.expressions(expression)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/generator.py", line 3229, in expressions
    sql = self.sql(e, comment=False)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/generator.py", line 739, in sql
    sql = getattr(self, exp_handler_name)(expression)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/generator.py", line 2725, in alias_sql
    return f"{self.sql(expression, 'this')}{alias}"
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/generator.py", line 728, in sql
    return self.sql(value)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/generator.py", line 734, in sql
    sql = transform(self, expression)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/transforms.py", line 595, in _to_sql
    expression = transforms[0](expression)
  File "/Users/xyz/opt/anaconda3/envs/trial_env/lib/python3.10/site-packages/sqlglot/transforms.py", line 329, in add_within_group_for_percentiles
    column = expression.this.pop()
AttributeError: 'NoneType' object has no attribute 'pop'

Snippet that cuased the error

# Using the following import to avoid confusion with ignore variables (`_`)
from ibis import _ as c
# INFORMATION_SCHEMA
tables_table: Table = snowflake_backend.table("TABLES")

filtered_table: Table = tables_table.filter(
	tables_table.TABLE_SCHEMA == "TESTING"
).select(
	"TABLE_CATALOG",
	"TABLE_SCHEMA",
	"TABLE_NAME",
	"TABLE_OWNER",
	"ROW_COUNT",
	"BYTES",
)

row_count_stats: dict[str, int | float] = (
	filtered_table.aggregate(
		min_row_count=c.ROW_COUNT.min(),
		max_row_count=c.ROW_COUNT.max(),
		sum_row_count=c.ROW_COUNT.sum(),
		mean_row_count=c.ROW_COUNT.mean(),
		median_row_count=c.ROW_COUNT.median(),
		quantile_0_25_row_count=c.ROW_COUNT.quantile(0.25),
		quantile_0_75_row_count=c.ROW_COUNT.quantile(0.75),
	)
	.to_pandas()
	.to_dict("records")[0]
)

Environment Information

Python

Anaconda Python 3.10 on Mac

Installed requirements

sqlglot==23.0.5
ibis-framework[pandas,snowflake,duckdb]==9.0.0.dev511

What version of ibis are you using?

latest dev veriosn - 9.0.0.dev511

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

Snowflake

Relevant log output

Stacktrace in "What happened?"

Code of Conduct

  • I agree to follow this project's Code of Conduct
@yazad3 yazad3 added the bug Incorrect behavior inside of ibis label Mar 25, 2024
@jcrist jcrist added this to the 9.0 milestone Mar 29, 2024
@gforsyth gforsyth self-assigned this Apr 1, 2024
@gforsyth
Copy link
Member

gforsyth commented Apr 1, 2024

Hey @yazad3! Thanks for reporting this!
I can reproduce the issue and I've got a proximate cause identified, just working on tracking down a simpler reproducer and then we should be able to push up a fix.

@yazad3
Copy link
Author

yazad3 commented Apr 1, 2024

Thank you! Let me know if I can be of any help with reproduction and / or fixing.

@cpcloud
Copy link
Member

cpcloud commented Apr 12, 2024

@gforsyth Can we close this out?

@cpcloud
Copy link
Member

cpcloud commented Apr 12, 2024

Whoops, didn't see the PR, reviewing now!

@yazad3
Copy link
Author

yazad3 commented Apr 13, 2024

Thank you for the fix!

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

Successfully merging a pull request may close this issue.

4 participants