Skip to content

Commit

Permalink
Raise error in case of invalid options subquery
Browse files Browse the repository at this point in the history
  • Loading branch information
parkervg committed Jun 19, 2024
1 parent 1446145 commit afcd701
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions blendsql/blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def _blend(
if table_to_title is not None:
kwargs_dict["table_to_title"] = table_to_title

# Optionally, recursively call blend() again to get subtable
# Optionally, recursively call blend() again to get subtable from args
# This applies to `context` and `options`
for i, unpack_kwarg in enumerate(
[IngredientKwarg.CONTEXT, IngredientKwarg.OPTIONS]
Expand Down Expand Up @@ -654,8 +654,12 @@ def _blend(
)
_prev_passed_values = _smoothie.meta.num_values_passed
subtable = _smoothie.df
if len(subtable.columns) != 1:
raise InvalidBlendSQL(
f"Invalid subquery passed to `options`!\nNeeds to return exactly one column, got {len(subtable.columns)} instead"
)
if unpack_kwarg == IngredientKwarg.OPTIONS:
# Here, we need to format as a flat list
# Here, we need to format as a flat set
kwargs_dict[unpack_kwarg] = list(subtable.values.flat)
else:
kwargs_dict[unpack_kwarg] = subtable
Expand Down

0 comments on commit afcd701

Please sign in to comment.