PyDough fails with an unhandled IndexError: list index out of range when a partitioned variable name (c1) is referenced inside its own CALCULATE expression, rather than raising a user-friendly domain error message (e.g., Unrecognized term...).
Traceback (most recent call last):
File "/home/juankx/svc/PyDough/pydough_test.py", line 182, in <module>
sql = pydough.to_sql(unqualified_node, session=tester.session)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/evaluation/evaluate_unqualified.py", line 166, in to_sql
relational: RelationalRoot = convert_ast_to_relational(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/relational_converter.py", line 1888, in convert_ast_to_relational
hybrid: HybridTree = hybrid_translator.convert_qdag_to_hybrid(node)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/hybrid_translator.py", line 1751, in convert_qdag_to_hybrid
hybrid: HybridTree = self.make_hybrid_tree(node, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/hybrid_translator.py", line 1469, in make_hybrid_tree
hybrid = self.make_hybrid_tree(
^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/hybrid_translator.py", line 1472, in make_hybrid_tree
self.populate_children(hybrid, node, child_ref_mapping)
File "/home/juankx/svc/PyDough/pydough/conversion/hybrid_translator.py", line 422, in populate_children
subtree: HybridTree = self.make_hybrid_tree(
^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/hybrid_translator.py", line 1640, in make_hybrid_tree
self.populate_children(
File "/home/juankx/svc/PyDough/pydough/conversion/hybrid_translator.py", line 422, in populate_children
subtree: HybridTree = self.make_hybrid_tree(
^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/hybrid_translator.py", line 1634, in make_hybrid_tree
HybridPartitionChild(source.children[0].subtree),
~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
Minimal reproducible example:
# Raises "IndexError: list index out of range"
c1 = customers.PARTITION(name="by_marketsegment", by=market_segment)
r1 = c1.CALCULATE(x=COUNT(c1))
LLM Explanation Discrepancy
While code execution fails with an IndexError, calling pydough.explain_llm() on the exact same code completes without reporting an error ("error": false):
{
"error": false,
"query_summary": "Accesses 'customers', partitioned by market_segment, computing counting customers records per group as 'x'."
}
Expected Behavior:
If c1 is out-of-scope or invalid within the expression c1.CALCULATE(...), PyDough should raise a descriptive context error instead of crashing with a generic IndexError:
Unrecognized term of TPCH.Partition(customers, name='by_marketsegment', by=market_segment): 'c1'. Did you mean: customers, market_segment?
Additional Context / Comparison:
Standard error reporting works as expected when referencing undefined or out-of-scope terms in other partition scenarios (r1 and r2):
c1 = customers.PARTITION(name="by_marketsegment", by=market_segment)
c2 = suppliers.PARTITION(name="by_nationname", by=nation.name)
r1 = c1.CALCULATE(x=COUNT(c3))
r2 = c2.CALCULATE(x=COUNT(c1))
Schema Context (TPCH Collections Used):
customers
└── market_segment
nations
├── name
└── suppliers [multiple customers]
suppliers
└── nation [one member of nations]
PyDough fails with an unhandled
IndexError: list index out of rangewhen a partitioned variable name (c1) is referenced inside its ownCALCULATEexpression, rather than raising a user-friendly domain error message (e.g.,Unrecognized term...).Minimal reproducible example:
LLM Explanation Discrepancy
While code execution fails with an
IndexError, callingpydough.explain_llm()on the exact same code completes without reporting an error ("error": false):{ "error": false, "query_summary": "Accesses 'customers', partitioned by market_segment, computing counting customers records per group as 'x'." }Expected Behavior:
If
c1is out-of-scope or invalid within the expressionc1.CALCULATE(...), PyDough should raise a descriptive context error instead of crashing with a genericIndexError:Unrecognized term of TPCH.Partition(customers, name='by_marketsegment', by=market_segment): 'c1'. Did you mean: customers, market_segment?Additional Context / Comparison:
Standard error reporting works as expected when referencing undefined or out-of-scope terms in other partition scenarios (
r1andr2):Schema Context (TPCH Collections Used):