Skip to content

Bug: Unhandled exceptions and descriptive errors for unsupported partition keys (literals, non-iterables, relationship references) #573

Description

@juankx-bodo

Passing a single integer or non-iterable value to .PARTITION(by=...) (e.g., by=1) causes PyDough to crash with an unhandled Python TypeError: 'int' object is not iterable inside PARTITION() when attempting list(by).

PyDough should either handle single scalar terms gracefully or raise a descriptive validation error explaining allowed partition keys.

Minimal Reproducible Example

result = customers.WHERE(
    account_balance > 0
).PARTITION(
    name="all_group",
    by=1
).CALCULATE(
    total=COUNT(customers)
)

Error Traceback

Traceback (most recent call last):
  File "/home/juankx/svc/PyDough/pydough_test.py", line 166, in <module>
    unqualified_node : UnqualifiedNode = pydough.from_string(pydough_code, answer_variable, tester.session.metadata)
  File "/home/juankx/svc/PyDough/pydough/unqualified/unqualified_transform.py", line 524, in from_string
    exec(compile_ast, execution_context, execution_context)
  File "<ast>", line 3, in <module>
  File "/home/juankx/svc/PyDough/pydough/unqualified/unqualified_node.py", line 379, in PARTITION
    return UnqualifiedPartition(self, name, list(by))
TypeError: 'int' object is not iterable

Expected Behavior

  • If by=1 is an invalid partition key: PyDough should raise a descriptive domain error (e.g., Invalid partition key '1'. Partition keys must be references to scalar expressions from the data collection) instead of failing on a raw list(by) call.
  • If single non-iterable terms are allowed: PARTITION() should handle it.

Documentation Context

According to the PyDough Partition Documentation:

Warning: PyDough currently only supports using references to scalar expressions from the data collection itself as partition keys, not an ancestor term, or a term from a child collection, or the result of a function call.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions