• 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

63.82
/src/dftracer/utils/python/ops.cpp
1
// The Python view of the dataframe op registry: op_list / op_info for
2
// discovery, and one generic op_run that decodes an op's packed signature to
3
// marshal the Python arguments into dftu_op_arg and hand columns to/from the
4
// engine. All work is the C ABI's (dftu_op_*); this file only marshals.
5

6
#include <dftracer/utils/core/common/config.h>  // DFTRACER_UTILS_ENABLE_ARROW
7
#include <dftracer/utils/dataframe/abi.h>
8
#include <dftracer/utils/dataframe/series.h>
9
#include <dftracer/utils/python/ops.h>
10
#include <dftracer/utils/python/py_scalar_helpers.h>
11
#include <dftracer/utils/python/series.h>
12
#include <dftracer/utils/python/series_detail.h>
13

14
namespace dftracer::utils::python {
15
namespace {
16

17
PyObject* op_list(PyObject*, PyObject*) {
98 ✔
18
    uint32_t n = dftu_op_count();
98 ✔
19
    PyObject* out = PyList_New(n);
98 ✔
20
    if (!out) return nullptr;
98 !
21
    for (uint32_t i = 0; i < n; ++i) {
23,128 ✔
22
        const dftu_op_desc* op = dftu_op_at(i);
23,030 ✔
23
        PyObject* name = PyUnicode_FromString(op ? op->name : "");
23,030 !
24
        if (!name) {
23,030 !
25
            Py_DECREF(out);
26
            return nullptr;
×
27
        }
28
        PyList_SET_ITEM(out, i, name);  // steals name
23,030 ✔
29
    }
30
    return out;
98 ✔
31
}
32

33
PyObject* op_info(PyObject*, PyObject* args) {
569 ✔
34
    const char* name = nullptr;
569 ✔
35
    if (!PyArg_ParseTuple(args, "s", &name)) return nullptr;
569 !
36
    const dftu_op_desc* op = dftu_op_find(name);
569 !
37
    if (!op) {
569 ✔
38
        PyErr_Format(PyExc_KeyError, "no op named '%s'", name);
1 !
39
        return nullptr;
1 ✔
40
    }
41
    const char* kind = "series";
568 ✔
42
    switch (dftu_op_kind_of(op->sig)) {
568 !
43
        case DFTU_OP_KIND_SERIES:
278 ✔
44
            kind = "series";
278 ✔
45
            break;
278 ✔
46
        case DFTU_OP_KIND_AGGREGATE:
38 ✔
47
            kind = "aggregate";
38 ✔
48
            break;
38 ✔
49
        case DFTU_OP_KIND_FRAME:
164 ✔
50
            kind = "frame";
164 ✔
51
            break;
164 ✔
52
        case DFTU_OP_KIND_LAZY:
88 ✔
53
            kind = "lazy";
88 ✔
54
            break;
88 ✔
55
    }
56
    return Py_BuildValue("{s:s,s:s,s:I,s:s}", "name", op->name, "kind", kind,
568 !
57
                         "arity", dftu_op_arity(op->sig), "signature",
568 !
58
                         dftu_op_signature(op->sig));
1,136 !
59
}
60

61
using series_detail::scalar_to_py;  // numbers, str, and the refusal TypeError
62

63
PyObject* op_run(PyObject*, PyObject* args) {
6,564 ✔
64
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
6,564 ✔
65
    if (nargs < 1) {
6,564 !
66
        PyErr_SetString(PyExc_TypeError,
×
67
                        "op_run(name, *args): name is required");
68
        return nullptr;
×
69
    }
70
    const char* name = PyUnicode_AsUTF8(PyTuple_GET_ITEM(args, 0));
6,564 !
71
    if (!name) return nullptr;
6,564 !
72
    const dftu_op_desc* op = dftu_op_find(name);
6,564 !
73
    if (!op) {
6,564 !
74
        PyErr_Format(PyExc_KeyError, "no op named '%s'", name);
×
75
        return nullptr;
×
76
    }
77

78
    if (dftu_op_kind_of(op->sig) == DFTU_OP_KIND_FRAME) {
6,564 !
79
        PyErr_Format(
×
80
            PyExc_NotImplementedError,
81
            "op '%s' is a frame op; call the matching DataFrame method", name);
82
        return nullptr;
×
83
    }
84
    if (dftu_op_kind_of(op->sig) == DFTU_OP_KIND_LAZY) {
6,564 !
85
        PyErr_Format(PyExc_NotImplementedError,
×
86
                     "op '%s' is a lazy op; call the matching LazyFrame method",
87
                     name);
88
        return nullptr;
×
89
    }
90

91
    // Walk the signature's operand tokens in order, pulling each from the next
92
    // positional argument: a column into `in`, every other operand into the
93
    // matching args[i] slot.
94
    const dftu_series* in[2] = {nullptr, nullptr};
6,564 ✔
95
    uint32_t n_series = 0;
6,564 ✔
96
    dftu_op_arg arg{};
6,564 ✔
97
    Py_ssize_t next = 1;
6,564 ✔
98
    for (int i = 0; i < DFTU_OP_MAX_ARGS; ++i) {
18,400 !
99
        dftu_op_tok t = DFTU_OP_SIG_ARG(op->sig, i);
18,400 ✔
100
        if (t == DFTU_TOK_NONE) break;
18,400 ✔
101
        if (next >= nargs) {
11,883 ✔
102
            PyErr_Format(PyExc_TypeError, "op '%s' expects more arguments",
1 !
103
                         name);
104
            return nullptr;
1 ✔
105
        }
106
        PyObject* a = PyTuple_GET_ITEM(args, next++);
11,882 !
107
        dftu_op_val& slot = arg.args[i];
11,882 ✔
108
        switch (t) {
11,882 !
109
            case DFTU_TOK_SERIES: {
7,351 ✔
110
                const dataframe::Series* s = unwrap_vec_column(a);
7,351 !
111
                if (!s) {
7,351 !
112
                    PyErr_Format(PyExc_TypeError,
×
113
                                 "op '%s' argument %zd must be a Series", name,
114
                                 next - 1);
115
                    return nullptr;
×
116
                }
117
                // Series ride in[] for series-return ops and args[i] for
118
                // aggregate/frame ops (e.g. dot's second column).
119
                slot.series = s->handle();
7,351 ✔
120
                if (n_series < 2) in[n_series++] = s->handle();
7,351 ✔
121
                break;
7,351 ✔
122
            }
123
            case DFTU_TOK_SCALAR:
649 ✔
124
                if (!py_to_scalar(a, &slot.scalar)) return nullptr;
649 !
125
                break;
649 ✔
126
            case DFTU_TOK_F64: {
185 ✔
127
                double d = PyFloat_AsDouble(a);
185 !
128
                if (d == -1.0 && PyErr_Occurred()) return nullptr;
185 !
129
                slot.f64 = d;
185 ✔
130
                break;
185 ✔
131
            }
132
            case DFTU_TOK_CMP:
1,157 ✔
133
            case DFTU_TOK_PRIM:
134
            case DFTU_TOK_LOGICAL:
135
            case DFTU_TOK_DTYPE:
136
            case DFTU_TOK_REDUCE:
137
            case DFTU_TOK_I32:
138
            case DFTU_TOK_RANK:
139
            case DFTU_TOK_ROLLING:
140
                slot.i32 = static_cast<int32_t>(PyLong_AsLong(a));
1,157 !
141
                if (slot.i32 == -1 && PyErr_Occurred()) return nullptr;
1,157 !
142
                break;
1,157 ✔
143
            case DFTU_TOK_STR: {
1,206 ✔
144
                Py_ssize_t len = 0;
1,206 ✔
145
                const char* p = PyUnicode_AsUTF8AndSize(a, &len);
1,206 !
146
                if (!p) return nullptr;
1,206 !
147
                slot.str.ptr = p;
1,206 ✔
148
                slot.str.len = static_cast<int32_t>(len);
1,206 ✔
149
                break;
1,206 ✔
150
            }
151
            case DFTU_TOK_I64: {
1,104 ✔
152
                long long v = PyLong_AsLongLong(a);
1,104 !
153
                if (v == -1 && PyErr_Occurred()) return nullptr;
1,104 !
154
                slot.i64 = v;
1,104 ✔
155
                break;
1,104 ✔
156
            }
157
            case DFTU_TOK_U64: {
46 ✔
158
                unsigned long long v = PyLong_AsUnsignedLongLong(a);
46 !
159
                if (v == static_cast<unsigned long long>(-1) &&
46 !
160
                    PyErr_Occurred())
×
161
                    return nullptr;
×
162
                slot.u64 = v;
46 ✔
163
                break;
46 ✔
164
            }
165
            case DFTU_TOK_CHAR: {
138 ✔
166
                Py_ssize_t len = 0;
138 ✔
167
                const char* p = PyUnicode_AsUTF8AndSize(a, &len);
138 !
168
                if (!p) return nullptr;
138 !
169
                if (len != 1) {
138 !
170
                    PyErr_Format(PyExc_ValueError,
×
171
                                 "op '%s' expects a single character", name);
172
                    return nullptr;
×
173
                }
174
                slot.ch = p[0];
138 ✔
175
                break;
138 ✔
176
            }
177
            case DFTU_TOK_FRAME:
46 ✔
178
            case DFTU_TOK_LAZY:
179
            case DFTU_TOK_STRLIST:
180
            case DFTU_TOK_I32LIST:
181
            case DFTU_TOK_I64LIST:
182
            case DFTU_TOK_EXPR:
183
            case DFTU_TOK_AGGLIST:
184
            case DFTU_TOK_WINLIST:
185
            case DFTU_TOK_DUQL:
186
                PyErr_Format(PyExc_NotImplementedError,
46 !
187
                             "op '%s' takes a frame/plan/list/expr/query "
188
                             "operand not yet runnable via ops.run",
189
                             name);
190
                return nullptr;
46 ✔
191
            case DFTU_TOK_NONE:
×
192
            case DFTU_TOK_BOOL:
193
                break;
×
194
        }
195
    }
196
    if (next != nargs) {
6,517 !
197
        PyErr_Format(PyExc_TypeError, "op '%s' got too many arguments", name);
×
198
        return nullptr;
×
199
    }
200

201
    if (dftu_op_kind_of(op->sig) == DFTU_OP_KIND_SERIES) {
6,517 !
202
        dftu_series* out = dftu_op_run(op, in, n_series, &arg);
5,772 !
203
        if (!out) {
5,772 ✔
204
            PyErr_Format(PyExc_RuntimeError, "op '%s' failed", name);
2,520 !
205
            return nullptr;
2,520 ✔
206
        }
207
        return wrap_vec_column(dataframe::Series{out});
3,252 !
208
    }
209
    int ok = 0;
745 ✔
210
    dftu_scalar r = dftu_op_run_aggregate(op, in[0], &arg, &ok);
745 !
211
    if (!ok) {
745 !
212
        PyErr_Format(PyExc_RuntimeError, "op '%s' failed", name);
×
213
        return nullptr;
×
214
    }
215
    return scalar_to_py(r);
745 !
216
}
217

218
PyMethodDef ops_methods[] = {
219
    {"op_list", op_list, METH_NOARGS,
220
     "op_list(): the names of every registered op."},
221
    {"op_info", op_info, METH_VARARGS,
222
     "op_info(name): {name, kind, arity, signature} for a registered op."},
223
    {"op_run", op_run, METH_VARARGS,
224
     "op_run(name, *args): run a registered op; columns are Series, other "
225
     "operands follow the op's signature. Returns a Series or a scalar."},
226
    {nullptr, nullptr, 0, nullptr}};
227

228
}  // namespace
229

230
int init_ops(PyObject* m) { return PyModule_AddFunctions(m, ops_methods); }
7 ✔
231

232
}  // 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