• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

llnl-asr / dftracer-utils / 38033748054

10 Oct 2026 07:14AM UTC coverage: 62.608% (+5.2%) from 57.391%
38033748054

push

github

rayandrew
ci: shard the test job

The coverage jobs ran 64 minutes of C++ tests in one process. Each shard
runs every n-th test with ctest -I, the Python tests and the type check
run in shard 1 only, and each shard uploads its own coverage report to
Coveralls, which merges the parallel uploads.

117733 of 235605 branches covered (49.97%)

Branch coverage included in aggregate %.

102379 of 115969 relevant lines covered (88.28%)

3014114.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.71
/src/dftracer/utils/python/columnar_eval.cpp
1
// Binding for the native columnar expression engine. Python serializes its
2
// expression tree to a flat post-order AST; this rebuilds it as a
3
// dataframe::Expr and evaluates it - all the compiler work (type inference,
4
// CSE, lowering, fused chunked + parallel evaluation) lives in vec, so C/C++
5
// consumers get the same engine. This TU also installs the runtime-backed
6
// parallel backend so vec's parallelism seam fans out across the coroutine
7
// pool.
8

9
#include <dftracer/utils/core/common/config.h>  // DFTRACER_UTILS_ENABLE_ARROW
10
#include <dftracer/utils/core/runtime.h>
11
#include <dftracer/utils/dataframe/abi.h>
12
#include <dftracer/utils/dataframe/dataframe.h>
13
#include <dftracer/utils/dataframe/expr.h>
14
#include <dftracer/utils/dataframe/parallel.h>
15
#include <dftracer/utils/python/columnar_eval.h>
16
#include <dftracer/utils/python/py_method.h>
17
#include <dftracer/utils/python/py_scalar_helpers.h>
18
#include <dftracer/utils/python/series.h>
19

20
#include <cstdint>
21
#include <string>
22
#include <string_view>
23
#include <utility>
24
#include <vector>
25

26
namespace dataframe = dftracer::utils::dataframe;
27

28
namespace {
29

30
// AST node opcodes (mirror the serializer in columnar.py).
31
enum {
32
    AST_COL = 0,
33
    AST_LIT_I = 1,
34
    AST_LIT_F = 2,
35
    AST_BIN = 3,
36
    AST_PRIM = 4,
37
    AST_CMP = 5,
38
    AST_LOGICAL = 6,
39
    AST_NOT = 7,
40
    AST_CAST = 8,
41
    AST_UNARY = 9,
42
    AST_CLIP = 10,
43
    AST_FILLNA = 11,
44
    AST_STR_PRED = 12,
45
    AST_STR_MAP = 13,
46
    AST_STR_LEN = 14,
47
    AST_STR_FIND = 15,
48
    AST_STR_REPLACE = 16,
49
    AST_STR_SLICE = 17,
50
    AST_IS_IN = 18,
51
    AST_SELECT = 19,
52
    AST_IS_NULL = 20,
53
    AST_CMP_EXPR = 21,
54
    AST_STR_FN = 22,  // (fn, text, text2, i0, i1, operand count)
55
    AST_STR_PRED_COL = 23,
56
    AST_STR_REPLACE_COL = 24,
57
    AST_LIT_S = 25,
58
};
59

60
// A borrowed view of a Python str; valid while `o` lives, which the ast list
61
// guarantees for the duration of build_expr.
62
bool py_str_view(PyObject* o, std::string_view* out) {
454 ✔
63
    Py_ssize_t n = 0;
454 ✔
64
    const char* s = PyUnicode_AsUTF8AndSize(o, &n);
454 !
65
    if (!s) return false;
454 !
66
    *out = std::string_view(s, static_cast<std::size_t>(n));
454 ✔
67
    return true;
454 ✔
68
}
69

70
// The is_in value list as a Series: all ints (Int64) or all strs (String).
71
bool py_values_series(PyObject* list, dataframe::Series* out) {
12 ✔
72
    PyObject* seq = PySequence_Fast(list, "is_in values must be a sequence");
12 ✔
73
    if (!seq) return false;
12 !
74
    const Py_ssize_t n = PySequence_Fast_GET_SIZE(seq);
12 !
75
    bool all_str = n > 0;
12 ✔
76
    bool all_int = n > 0;
12 ✔
77
    for (Py_ssize_t i = 0; i < n; ++i) {
37 ✔
78
        PyObject* v = PySequence_Fast_GET_ITEM(seq, i);
25 !
79
        if (!PyUnicode_Check(v)) all_str = false;
25 ✔
80
        if (PyBool_Check(v) || !PyLong_Check(v)) all_int = false;
25 !
81
    }
82
    if (all_str) {
12 ✔
83
        std::vector<std::string> values;
5 ✔
84
        values.reserve(static_cast<std::size_t>(n));
5 !
85
        for (Py_ssize_t i = 0; i < n; ++i) {
14 ✔
86
            std::string_view s;
9 ✔
87
            if (!py_str_view(PySequence_Fast_GET_ITEM(seq, i), &s)) {
9 !
88
                Py_DECREF(seq);
89
                return false;
×
90
            }
91
            values.emplace_back(s);
9 !
92
        }
93
        Py_DECREF(seq);
94
        *out = dataframe::Series::strings(values);
5 !
95
        return true;
5 ✔
96
    }
5 ✔
97
    if (all_int) {
7 !
98
        std::vector<std::int64_t> values;
7 ✔
99
        values.reserve(static_cast<std::size_t>(n));
7 !
100
        for (Py_ssize_t i = 0; i < n; ++i) {
23 ✔
101
            values.push_back(static_cast<std::int64_t>(
×
102
                PyLong_AsLongLong(PySequence_Fast_GET_ITEM(seq, i))));
16 !
103
            if (PyErr_Occurred()) {
16 !
104
                Py_DECREF(seq);
105
                return false;
×
106
            }
107
        }
108
        Py_DECREF(seq);
109
        *out = dataframe::Series::flat_i64(values.data(),
14 !
110
                                           static_cast<std::int64_t>(n));
7 ✔
111
        return true;
7 ✔
112
    }
7 ✔
113
    Py_DECREF(seq);
114
    PyErr_SetString(PyExc_TypeError,
×
115
                    "is_in values must be a non-empty list of all ints or all "
116
                    "strings");
117
    return false;
×
118
}
119

120
// Rebuild a dataframe::Expr from a post-order list of (op, arg0[, arg1])
121
// tuples.
122
bool build_expr(PyObject* ast, dataframe::Expr* out) {
1,406 ✔
123
    if (!PyList_Check(ast)) {
1,406 !
124
        PyErr_SetString(PyExc_TypeError, "ast must be a list");
×
125
        return false;
×
126
    }
127
    std::vector<dataframe::Expr> stack;
1,406 ✔
128
    Py_ssize_t n = PyList_GET_SIZE(ast);
1,406 ✔
129
    for (Py_ssize_t k = 0; k < n; ++k) {
5,958 ✔
130
        PyObject* t = PyList_GET_ITEM(ast, k);
4,552 !
131
        if (!PyTuple_Check(t) || PyTuple_GET_SIZE(t) < 1) {
4,552 !
132
            PyErr_SetString(PyExc_TypeError, "each ast node is a tuple");
×
133
            return false;
×
134
        }
135
        int op = static_cast<int>(PyLong_AsLong(PyTuple_GET_ITEM(t, 0)));
4,552 !
136
        auto arg = [&](int i) { return PyTuple_GET_ITEM(t, i); };
6,087 !
137
        auto pop = [&]() {
3,146 ✔
138
            dataframe::Expr e = std::move(stack.back());
3,146 ✔
139
            stack.pop_back();
3,146 ✔
140
            return e;
3,146 ✔
141
        };
4,552 ✔
142
        switch (op) {
4,552 !
143
            case AST_COL:
2,023 ✔
144
                stack.push_back(dataframe::expr_col(
2,023 !
145
                    static_cast<std::int32_t>(PyLong_AsLong(arg(1)))));
2,023 !
146
                break;
2,023 ✔
147
            case AST_LIT_I:
342 ✔
148
                stack.push_back(dataframe::expr_lit(
342 !
149
                    static_cast<std::int64_t>(PyLong_AsLongLong(arg(1)))));
342 !
150
                break;
342 ✔
151
            case AST_LIT_F:
67 ✔
152
                stack.push_back(dataframe::expr_lit(PyFloat_AsDouble(arg(1))));
67 !
153
                break;
67 ✔
154
            case AST_LIT_S: {
4 ✔
155
                std::string_view v;
4 ✔
156
                if (!py_str_view(arg(1), &v)) return false;
4 !
157
                stack.push_back(dataframe::expr_lit_str(v));
4 !
158
                break;
4 ✔
159
            }
160
            case AST_BIN: {
769 ✔
161
                dataframe::Expr b = pop(), a = pop();
769 ✔
162
                stack.push_back(dataframe::expr_binary(
769 !
163
                    static_cast<dataframe::BinaryOp>(PyLong_AsLong(arg(1))), a,
769 !
164
                    b));
165
                break;
769 ✔
166
            }
769 ✔
167
            case AST_PRIM: {
10 ✔
168
                dataframe::Expr a = pop();
10 ✔
169
                stack.push_back(dataframe::expr_prim(
10 !
170
                    static_cast<dataframe::PrimOp>(PyLong_AsLong(arg(1))), a));
10 !
171
                break;
10 ✔
172
            }
10 ✔
173
            case AST_CMP: {
313 ✔
174
                dftu_scalar rhs{};
313 ✔
175
                if (PyUnicode_Check(arg(2))) {
313 ✔
176
                    // expr_cmp copies the text into the node, so the borrow
177
                    // ends with this call.
178
                    std::string_view s;
12 ✔
179
                    if (!py_str_view(arg(2), &s)) return false;
12 !
180
                    rhs.kind = DFTU_SCALAR_TAG_STR;
12 ✔
181
                    rhs.len = static_cast<std::uint32_t>(s.size());
12 ✔
182
                    rhs.value.s = s.data();
12 ✔
183
                } else if (!py_to_scalar(arg(2), &rhs)) {
301 !
184
                    return false;
×
185
                }
186
                dataframe::Expr a = pop();
313 ✔
187
                stack.push_back(dataframe::expr_cmp(
626 !
188
                    static_cast<dataframe::CmpOp>(PyLong_AsLong(arg(1))), a,
313 !
189
                    rhs));
190
                break;
313 ✔
191
            }
313 ✔
192
            case AST_CMP_EXPR: {
15 ✔
193
                dataframe::Expr b = pop(), a = pop();
15 ✔
194
                stack.push_back(dataframe::expr_cmp_expr(
15 !
195
                    static_cast<dataframe::CmpOp>(PyLong_AsLong(arg(1))), a,
15 !
196
                    b));
197
                break;
15 ✔
198
            }
15 ✔
199
            case AST_LOGICAL: {
122 ✔
200
                dataframe::Expr b = pop(), a = pop();
122 ✔
201
                stack.push_back(dataframe::expr_logical(
122 !
202
                    static_cast<dataframe::LogicalOp>(PyLong_AsLong(arg(1))), a,
122 !
203
                    b));
204
                break;
122 ✔
205
            }
122 ✔
206
            case AST_NOT: {
15 ✔
207
                dataframe::Expr a = pop();
15 ✔
208
                stack.push_back(dataframe::expr_not(a));
15 !
209
                break;
15 ✔
210
            }
15 ✔
211
            case AST_CAST: {
60 ✔
212
                dataframe::Expr a = pop();
60 ✔
213
                stack.push_back(dataframe::expr_cast(
60 !
214
                    static_cast<dataframe::TypeId>(PyLong_AsLong(arg(1))), a));
60 !
215
                break;
60 ✔
216
            }
60 ✔
217
            case AST_UNARY: {
154 ✔
218
                dataframe::Expr a = pop();
154 ✔
219
                stack.push_back(dataframe::expr_unary(
154 !
220
                    static_cast<dataframe::UnaryOp>(PyLong_AsLong(arg(1))), a));
154 !
221
                break;
154 ✔
222
            }
154 ✔
223
            case AST_CLIP: {
4 ✔
224
                dftu_scalar lo{}, hi{};
4 ✔
225
                if (!py_to_scalar(arg(1), &lo) || !py_to_scalar(arg(2), &hi))
4 !
226
                    return false;
×
227
                dataframe::Expr a = pop();
4 ✔
228
                stack.push_back(dataframe::expr_clip(a, lo, hi));
4 !
229
                break;
4 ✔
230
            }
4 ✔
231
            case AST_FILLNA: {
7 ✔
232
                dftu_scalar fill{};
7 ✔
233
                if (!py_to_scalar(arg(1), &fill)) return false;
7 !
234
                dataframe::Expr a = pop();
7 ✔
235
                stack.push_back(dataframe::expr_fillna(a, fill));
7 !
236
                break;
7 ✔
237
            }
7 ✔
238
            case AST_STR_PRED: {
52 ✔
239
                std::string_view pattern;
52 ✔
240
                if (!py_str_view(arg(2), &pattern)) return false;
52 !
241
                dataframe::Expr a = pop();
52 ✔
242
                stack.push_back(dataframe::expr_str_pred(
52 !
243
                    static_cast<dataframe::StrPredOp>(PyLong_AsLong(arg(1))), a,
52 !
244
                    pattern));
245
                break;
52 ✔
246
            }
52 ✔
247
            case AST_STR_PRED_COL: {
16 ✔
248
                if (stack.size() < 2) {
16 !
249
                    PyErr_SetString(PyExc_ValueError,
×
250
                                    "string predicate needs its operands");
251
                    return false;
×
252
                }
253
                dataframe::Expr needle = pop();
16 ✔
254
                dataframe::Expr a = pop();
16 ✔
255
                stack.push_back(dataframe::expr_str_pred_col(
16 !
256
                    static_cast<dataframe::StrPredOp>(PyLong_AsLong(arg(1))), a,
16 !
257
                    needle));
258
                break;
16 ✔
259
            }
16 ✔
260
            case AST_STR_REPLACE_COL: {
8 ✔
261
                if (stack.size() < 3) {
8 !
262
                    PyErr_SetString(PyExc_ValueError,
×
263
                                    "replace needs its operands");
264
                    return false;
×
265
                }
266
                dataframe::Expr to = pop();
8 ✔
267
                dataframe::Expr from = pop();
8 ✔
268
                dataframe::Expr a = pop();
8 ✔
269
                stack.push_back(dataframe::expr_str_replace_col(a, from, to));
8 !
270
                break;
8 ✔
271
            }
8 ✔
272
            case AST_STR_MAP: {
44 ✔
273
                dataframe::Expr a = pop();
44 ✔
274
                stack.push_back(dataframe::expr_str_map(
44 !
275
                    static_cast<dataframe::StrMapOp>(PyLong_AsLong(arg(1))),
44 !
276
                    a));
277
                break;
44 ✔
278
            }
44 ✔
279
            case AST_STR_FN: {
181 ✔
280
                std::string_view text, text2;
181 ✔
281
                if (PyTuple_GET_SIZE(t) != 7 || !py_str_view(arg(2), &text) ||
362 !
282
                    !py_str_view(arg(3), &text2))
181 !
283
                    return false;
×
284
                const long fn = PyLong_AsLong(arg(1));
181 !
285
                const long long i0 = PyLong_AsLongLong(arg(4));
181 !
286
                const long long i1 = PyLong_AsLongLong(arg(5));
181 !
287
                const long nargs = PyLong_AsLong(arg(6));
181 !
288
                if (PyErr_Occurred()) return false;
181 !
289
                if (nargs < 1 || nargs > 2 ||
362 !
290
                    stack.size() < static_cast<std::size_t>(nargs)) {
181 !
291
                    PyErr_SetString(PyExc_ValueError,
×
292
                                    "string method needs its operands");
293
                    return false;
×
294
                }
295
                dataframe::Expr b;
181 ✔
296
                if (nargs == 2) b = pop();
181 ✔
297
                dataframe::Expr a = pop();
181 ✔
298
                stack.push_back(dataframe::expr_str_fn(
181 !
299
                    static_cast<dataframe::StrFn>(fn), a,
300
                    nargs == 2 ? &b : nullptr, text, text2, i0, i1));
301
                break;
181 ✔
302
            }
181 ✔
303
            case AST_STR_LEN: {
7 ✔
304
                dataframe::Expr a = pop();
7 ✔
305
                stack.push_back(
7 !
306
                    dataframe::expr_str_len(a, PyLong_AsLong(arg(1)) != 0));
14 !
307
                break;
7 ✔
308
            }
7 ✔
309
            case AST_STR_FIND: {
1 ✔
310
                std::string_view needle;
1 ✔
311
                if (!py_str_view(arg(1), &needle)) return false;
1 !
312
                dataframe::Expr a = pop();
1 ✔
313
                stack.push_back(dataframe::expr_str_find(a, needle));
1 !
314
                break;
1 ✔
315
            }
1 ✔
316
            case AST_STR_REPLACE: {
7 ✔
317
                std::string_view from, to;
7 ✔
318
                if (!py_str_view(arg(1), &from) || !py_str_view(arg(2), &to))
7 !
319
                    return false;
×
320
                dataframe::Expr a = pop();
7 ✔
321
                stack.push_back(dataframe::expr_str_replace(
7 !
322
                    a, from, to, PyLong_AsLong(arg(3)) != 0));
7 !
323
                break;
7 ✔
324
            }
7 ✔
325
            case AST_STR_SLICE: {
1 ✔
326
                const long long start = PyLong_AsLongLong(arg(1));
1 !
327
                const long long len = PyLong_AsLongLong(arg(2));
1 !
328
                if (PyErr_Occurred()) return false;
1 !
329
                dataframe::Expr a = pop();
1 ✔
330
                stack.push_back(dataframe::expr_str_slice(a, start, len));
1 !
331
                break;
1 ✔
332
            }
1 ✔
333
            case AST_IS_IN: {
12 ✔
334
                dataframe::Series values;
12 ✔
335
                if (!py_values_series(arg(1), &values)) return false;
12 !
336
                dataframe::Expr a = pop();
12 ✔
337
                stack.push_back(dataframe::expr_is_in(a, std::move(values)));
12 !
338
                break;
12 ✔
339
            }
24 !
340
            case AST_SELECT: {
44 ✔
341
                if (stack.size() < 3) {
44 !
342
                    PyErr_SetString(PyExc_ValueError,
×
343
                                    "select needs three operands");
344
                    return false;
×
345
                }
346
                dataframe::Expr b = pop(), a = pop(), cond = pop();
44 ✔
347
                stack.push_back(dataframe::expr_select(cond, a, b));
44 !
348
                break;
44 ✔
349
            }
44 ✔
350
            case AST_IS_NULL: {
274 ✔
351
                if (stack.empty()) {
274 !
352
                    PyErr_SetString(PyExc_ValueError,
×
353
                                    "is_null needs an operand");
354
                    return false;
×
355
                }
356
                const long null = PyLong_AsLong(arg(1));
274 !
357
                if (null == -1 && PyErr_Occurred()) return false;
274 !
358
                dataframe::Expr a = pop();
274 ✔
359
                stack.push_back(dataframe::expr_is_null(a, null != 0));
274 !
360
                break;
274 ✔
361
            }
274 ✔
362
            default:
×
363
                PyErr_Format(PyExc_ValueError, "bad ast op %d", op);
×
364
                return false;
×
365
        }
366
        if (PyErr_Occurred()) return false;
4,552 !
367
    }
368
    if (stack.size() != 1) {
1,406 !
369
        PyErr_SetString(PyExc_ValueError,
×
370
                        "ast did not reduce to one expression");
371
        return false;
×
372
    }
373
    *out = std::move(stack.back());
1,406 ✔
374
    return true;
1,406 ✔
375
}
1,406 ✔
376

377
// The runtime-backed backend for vec's parallel_for seam: fan chunks across the
378
// process default runtime (lazily created, so import stays cheap).
379
void runtime_backend(void*, std::int64_t n, std::int64_t grain,
9,154 ✔
380
                     void (*body)(void*, std::int64_t, std::int64_t),
381
                     void* bctx) {
382
    dftracer::utils::default_runtime().parallel_for(
9,154 ✔
383
        n, grain, [&](std::int64_t b, std::int64_t e) { body(bctx, b, e); });
160,371 ✔
384
}
9,154 ✔
385

386
}  // namespace
387

388
namespace dftracer::utils::python {
389

390
bool build_expr_from_ast(PyObject* ast, dataframe::Expr* out) {
928 ✔
391
    return build_expr(ast, out);
928 ✔
392
}
393

394
// vec_eval(ast, [Series, ...]) -> Series
395
PyObject* vec_eval(PyObject* /*self*/, PyObject* args) {
475 ✔
396
    PyObject* ast = nullptr;
475 ✔
397
    PyObject* cols_obj = nullptr;
475 ✔
398
    if (!PyArg_ParseTuple(args, "OO", &ast, &cols_obj)) return nullptr;
475 !
399

400
    dataframe::Expr expr;
475 ✔
401
    if (!build_expr(ast, &expr)) return nullptr;
475 !
402

403
    PyObject* seq = PySequence_Fast(cols_obj, "columns must be a sequence");
475 !
404
    if (!seq) return nullptr;
475 !
405
    Py_ssize_t nc = PySequence_Fast_GET_SIZE(seq);
475 !
406
    std::vector<const dataframe::Series*> inputs;
475 ✔
407
    inputs.reserve(static_cast<std::size_t>(nc));
475 !
408
    for (Py_ssize_t i = 0; i < nc; ++i) {
1,070 ✔
409
        const dataframe::Series* c =
410
            unwrap_vec_column(PySequence_Fast_GET_ITEM(seq, i));
595 !
411
        if (!c) {
595 !
412
            Py_DECREF(seq);
413
            PyErr_SetString(PyExc_TypeError, "columns must be SeriesList");
×
414
            return nullptr;
×
415
        }
416
        inputs.push_back(c);
595 !
417
    }
418
    Py_DECREF(seq);
419

420
    try {
421
        return wrap_vec_column(dataframe::eval(expr, inputs));
475 !
422
    } catch (const std::exception& ex) {
7 !
423
        PyErr_SetString(PyExc_RuntimeError, ex.what());
7 !
424
        return nullptr;
7 ✔
425
    }
7 ✔
426
}
475 ✔
427

428
// vec_eval_many([ast, ...], [Series, ...]) -> [Series, ...]
429
// Compiles all roots into one program so CSE spans them (a subexpression shared
430
// across outputs is computed once), sharing the same input column list.
431
PyObject* vec_eval_many(PyObject* /*self*/, PyObject* args) {
1 ✔
432
    PyObject* asts_obj = nullptr;
1 ✔
433
    PyObject* cols_obj = nullptr;
1 ✔
434
    if (!PyArg_ParseTuple(args, "OO", &asts_obj, &cols_obj)) return nullptr;
1 !
435

436
    PyObject* aseq = PySequence_Fast(asts_obj, "asts must be a sequence");
1 !
437
    if (!aseq) return nullptr;
1 !
438
    Py_ssize_t ne = PySequence_Fast_GET_SIZE(aseq);
1 !
439
    std::vector<dataframe::Expr> roots(static_cast<std::size_t>(ne));
1 !
440
    for (Py_ssize_t i = 0; i < ne; ++i) {
4 ✔
441
        if (!build_expr(PySequence_Fast_GET_ITEM(aseq, i),
3 !
442
                        &roots[static_cast<std::size_t>(i)])) {
3 ✔
443
            Py_DECREF(aseq);
444
            return nullptr;
×
445
        }
446
    }
447
    Py_DECREF(aseq);
448

449
    PyObject* seq = PySequence_Fast(cols_obj, "columns must be a sequence");
1 !
450
    if (!seq) return nullptr;
1 !
451
    Py_ssize_t nc = PySequence_Fast_GET_SIZE(seq);
1 !
452
    std::vector<const dataframe::Series*> inputs;
1 ✔
453
    inputs.reserve(static_cast<std::size_t>(nc));
1 !
454
    for (Py_ssize_t i = 0; i < nc; ++i) {
4 ✔
455
        const dataframe::Series* c =
456
            unwrap_vec_column(PySequence_Fast_GET_ITEM(seq, i));
3 !
457
        if (!c) {
3 !
458
            Py_DECREF(seq);
459
            PyErr_SetString(PyExc_TypeError, "columns must be Series");
×
460
            return nullptr;
×
461
        }
462
        inputs.push_back(c);
3 !
463
    }
464
    Py_DECREF(seq);
465

466
    try {
467
        std::vector<dataframe::Series> outs =
468
            dataframe::eval_many(roots, inputs);
1 !
469
        PyObject* list = PyList_New(static_cast<Py_ssize_t>(outs.size()));
1 !
470
        if (!list) return nullptr;
1 !
471
        for (std::size_t i = 0; i < outs.size(); ++i) {
4 ✔
472
            PyObject* s = wrap_vec_column(std::move(outs[i]));
3 !
473
            if (!s) {
3 !
474
                Py_DECREF(list);
475
                return nullptr;
×
476
            }
477
            PyList_SET_ITEM(list, static_cast<Py_ssize_t>(i), s);
3 ✔
478
        }
479
        return list;
1 ✔
480
    } catch (const std::exception& ex) {
1 !
481
        PyErr_SetString(PyExc_RuntimeError, ex.what());
×
482
        return nullptr;
×
483
    }
×
484
}
1 ✔
485

486
int init_columnar_eval(PyObject* m) {
7 ✔
487
    dataframe::set_parallel_backend(runtime_backend, nullptr);
7 ✔
488
    static PyMethodDef def = {
489
        "vec_eval", vec_eval, METH_VARARGS,
490
        "vec_eval(ast, columns) -> Series: compile (type inference + CSE) "
491
        "and fused chunked evaluation of a columnar expression."};
492
    PyObject* fn = PyCFunction_NewEx(&def, nullptr, nullptr);
7 ✔
493
    if (!fn) return -1;
7 !
494
    if (PyModule_AddObject(m, "vec_eval", fn) < 0) {
7 !
495
        Py_DECREF(fn);
496
        return -1;
×
497
    }
498
    static PyMethodDef def_many = {
499
        "vec_eval_many", vec_eval_many, METH_VARARGS,
500
        "vec_eval_many(asts, columns) -> [Series]: compile several roots into "
501
        "one CSE'd program over a shared input list and evaluate in one pass."};
502
    PyObject* fn_many = PyCFunction_NewEx(&def_many, nullptr, nullptr);
7 ✔
503
    if (!fn_many) return -1;
7 !
504
    if (PyModule_AddObject(m, "vec_eval_many", fn_many) < 0) {
7 !
505
        Py_DECREF(fn_many);
506
        return -1;
×
507
    }
508
    return 0;
7 ✔
509
}
510

511
}  // namespace dftracer::utils::python
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc