44import ast
55
66
7- def _actionable_splits (parents : list [ast .expr ], node : ast .expr | None ) -> dict [str , list ]:
7+ def _subexprs_by_nest (parents : list [ast .expr ], node : ast .expr | None ) -> dict [str , list ]:
88 """
9- Given an expression which contains references to both base and nested columns,
10- return a dictionary of the sub-expressions that should be evaluated independently.
11- The key of the dictionary is the name of the nested column, and will be a blank
12- string in the case of base columns. The value is a list of the parent nodes
13- that lead to sub-expressions that can be evaluated successfully.
9+ Given an expression which contains references to both base and nested
10+ columns, return a dictionary of the sub-expressions that should be
11+ evaluated independently, keyed by nesting context.
1412
15- While this is not in use today for automatically splitting expressions, it can
16- be used to detect whether an expression is suitably structured for evaluation:
17- the returned dictionary should have a single key.
13+ The key of the dictionary is the name of the nested column, and will
14+ be a blank string in the case of base columns. The value is a list
15+ of the parent nodes that lead to sub-expressions that can be evaluated
16+ successfully.
17+
18+ While this is not in use today for automatically splitting expressions,
19+ it can be used to detect whether an expression is suitably structured
20+ for evaluation: the returned dictionary should have a single key.
1821 """
1922 if not isinstance (node , ast .expr ):
2023 return {}
@@ -28,8 +31,8 @@ def _actionable_splits(parents: list[ast.expr], node: ast.expr | None) -> dict[s
2831 + getattr (node , "comparators" , [])
2932 )
3033 result : dict [str , list ] = {}
31- for s in sources :
32- child = _actionable_splits (parents , s )
34+ for source in sources :
35+ child = _subexprs_by_nest (parents , source )
3336 for k , v in child .items ():
3437 result .setdefault (k , []).append (v )
3538 # After a complete traversal across sources, check for any necessary splits.
@@ -47,12 +50,12 @@ def _actionable_splits(parents: list[ast.expr], node: ast.expr | None) -> dict[s
4750 return result
4851
4952
50- def check_expr_nesting (expr : str ) -> set [str ]:
53+ def extract_nest_names (expr : str ) -> set [str ]:
5154 """
5255 Given a string expression, parse it and visit the resulting AST, surfacing
5356 the nesting types. The purpose is to identify expressions that attempt
5457 to mix base and nested columns, or columns from two different nests.
5558 """
5659 expr_tree = ast .parse (expr , mode = "eval" ).body
57- separable = _actionable_splits ([], expr_tree )
60+ separable = _subexprs_by_nest ([], expr_tree )
5861 return set (separable .keys ())
0 commit comments