MCPcopy Create free account
hub / github.com/PyTables/PyTables / _get_idx_expr_recurse

Function _get_idx_expr_recurse

tables/conditions.py:194–329  ·  view source on GitHub ↗

Actual implementation of the `get_idx_expr()` wrapper. 'idxexprs' is a list of expressions in the form ``(var, (ops), (limits))``. 'strexpr' is the indexable expression in string format. These parameters will be received empty (i.e. [], ['']) for the first time and populated during

(
    exprnode: ne.expressions.ExpressionNode,
    indexedcols: frozenset[str],
    idxexprs: list,
    strexpr: list[str],
)

Source from the content-addressed store, hash-verified

192
193
194def _get_idx_expr_recurse(
195 exprnode: ne.expressions.ExpressionNode,
196 indexedcols: frozenset[str],
197 idxexprs: list,
198 strexpr: list[str],
199) -> (
200 list[tuple[Any, tuple[str], tuple[Any]]]
201 | list[
202 tuple[ne.expressions.ExpressionNode, tuple[str, str], tuple[Any, Any]]
203 ]
204 | tuple[list, list[str]]
205):
206 """Actual implementation of the `get_idx_expr()` wrapper.
207
208 'idxexprs' is a list of expressions in the form ``(var, (ops),
209 (limits))``. 'strexpr' is the indexable expression in string format.
210 These parameters will be received empty (i.e. [], ['']) for the
211 first time and populated during the different recursive calls.
212 Finally, they are returned in the last level to the original
213 wrapper. If 'exprnode' is not indexable, it will return the tuple
214 ([], ['']) so as to signal this.
215
216 """
217 not_indexable = ([], [""])
218 op_conv = {
219 "and": "&",
220 "or": "|",
221 "not": "~",
222 }
223 negcmp = {
224 "lt": "ge",
225 "le": "gt",
226 "ge": "lt",
227 "gt": "le",
228 }
229
230 def fix_invert(
231 idxcmp: tuple[Any, str, Any] | tuple[None, None, None],
232 exprnode: ne.expressions.ExpressionNode,
233 indexedcols: frozenset[str],
234 ) -> tuple[
235 tuple[Any, str, Any] | tuple[None, None, None],
236 ne.expressions.ExpressionNode,
237 bool,
238 ]:
239 invert = False
240 # Loop until all leading negations have been dealt with
241 while idxcmp[1] == "invert":
242 invert ^= True
243 # The information about the negated node is in first position
244 exprnode = idxcmp[0]
245 idxcmp = _get_indexable_cmp(exprnode, indexedcols)
246 return idxcmp, exprnode, invert
247
248 # Indexable variable-constant comparison.
249 idxcmp = _get_indexable_cmp(exprnode, indexedcols)
250 idxcmp, exprnode, invert = fix_invert(idxcmp, exprnode, indexedcols)
251 if idxcmp[0]:

Callers 1

_get_idx_exprFunction · 0.85

Calls 4

_get_indexable_cmpFunction · 0.85
fix_invertFunction · 0.85
_equiv_expr_nodeFunction · 0.85
add_exprFunction · 0.85

Tested by

no test coverage detected