• 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

80.31
/src/dftracer/utils/python/series.cpp
1
// A native vec column exposed to Python: the DSL and pipeline operate on our
2
// own SIMD columnar format (dataframe::Series, Highway kernels) and only cross
3
// to Arrow at the edges - construction from a pyarrow array and export via the
4
// Arrow PyCapsule interface (__arrow_c_array__).
5
//
6
// This is the entry translation unit: it owns the SeriesType type object, the
7
// PyMethodDef table, init_series, and the shared make_series/as_series
8
// file-statics. The method bodies live in series/{arith,math,window,stats,
9
// reduce,string,arrow}.cpp and are declared in series_detail.h.
10

11
#include <dftracer/utils/core/common/config.h>  // DFTRACER_UTILS_ENABLE_ARROW
12
#include <dftracer/utils/dataframe/abi.h>
13
#include <dftracer/utils/dataframe/dataframe.h>
14
#include <dftracer/utils/python/py_method.h>
15
#include <dftracer/utils/python/py_type_helpers.h>
16
#include <dftracer/utils/python/series.h>
17
#include <dftracer/utils/python/series_detail.h>
18

19
#include <cstdint>
20
#include <new>
21
#include <utility>
22

23
namespace dftracer::utils::python::series_detail {
24

25
namespace {
26

27
PyTypeObject SeriesType;
28

29
void Series_dealloc(SeriesObject* self) {
25,142 ✔
30
    self->col.~Series();
25,142 ✔
31
    Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self));
25,142 ✔
32
}
25,142 ✔
33

34
}  // namespace
35

36
PyObject* make_series(Series&& col) {
25,154 ✔
37
    if (!col.valid()) {
25,154 ✔
38
        PyErr_SetString(PyExc_RuntimeError,
12 ✔
39
                        "dataframe kernel produced a null column");
40
        return nullptr;
12 ✔
41
    }
42
    auto* self =
43
        reinterpret_cast<SeriesObject*>(SeriesType.tp_alloc(&SeriesType, 0));
25,142 ✔
44
    if (!self) return nullptr;
25,142 !
45
    new (&self->col) Series(std::move(col));
25,142 ✔
46
    return reinterpret_cast<PyObject*>(self);
25,142 ✔
47
}
48

49
Series* as_series(PyObject* o) {
39,971 ✔
50
    if (!PyObject_TypeCheck(o, &SeriesType)) {
39,971 !
51
        PyErr_SetString(PyExc_TypeError, "expected a Series");
×
52
        return nullptr;
×
53
    }
54
    return &reinterpret_cast<SeriesObject*>(o)->col;
39,971 ✔
55
}
56

57
Series* as_series_or_null(PyObject* o) {
53 ✔
58
    if (!PyObject_TypeCheck(o, &SeriesType)) return nullptr;
53 ✔
59
    return &reinterpret_cast<SeriesObject*>(o)->col;
16 ✔
60
}
61

62
namespace {
63

64
Py_ssize_t Series_length_sq(PyObject* self) {
7 ✔
65
    Series* a = as_series(self);
7 ✔
66
    if (!a) return -1;
7 !
67
    return static_cast<Py_ssize_t>(a->length());
7 ✔
68
}
69

70
// Expose a FLAT, non-null, fixed-width numeric column as a 1-D read-only buffer
71
// so numpy reads it (np.asarray) with no pyarrow. Bit-packed Bool, strings,
72
// nulls, and non-FLAT encodings raise BufferError; the Python wrapper then
73
// falls back to the Arrow path.
74
int Series_getbuffer(PyObject* self, Py_buffer* view, int flags) {
885 ✔
75
    view->obj = nullptr;
885 ✔
76
    Series* a = as_series(self);
885 ✔
77
    if (!a) return -1;
885 !
78
    if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
885 !
79
        PyErr_SetString(PyExc_BufferError, "Series buffer is read-only");
×
80
        return -1;
×
81
    }
82
    dftu_series* h = a->handle();
885 ✔
83
    if (dftu_series_encoding(h) != 0 || dftu_series_null_count(h) != 0) {
885 ✔
84
        PyErr_SetString(PyExc_BufferError,
92 ✔
85
                        "Series is not a flat, non-null column");
86
        return -1;
92 ✔
87
    }
88
    const char* fmt = nullptr;
793 ✔
89
    Py_ssize_t itemsize = 0;
793 ✔
90
    switch (static_cast<TypeId>(dftu_series_type(h))) {
793 !
91
        case TypeId::Int8:
1 ✔
92
            fmt = "b";
1 ✔
93
            itemsize = 1;
1 ✔
94
            break;
1 ✔
95
        case TypeId::Int16:
1 ✔
96
            fmt = "h";
1 ✔
97
            itemsize = 2;
1 ✔
98
            break;
1 ✔
99
        case TypeId::Int32:
1 ✔
100
            fmt = "i";
1 ✔
101
            itemsize = 4;
1 ✔
102
            break;
1 ✔
103
        case TypeId::Int64:
349 ✔
104
            fmt = "q";
349 ✔
105
            itemsize = 8;
349 ✔
106
            break;
349 ✔
107
        case TypeId::Uint8:
×
108
            fmt = "B";
×
109
            itemsize = 1;
×
110
            break;
×
111
        case TypeId::Uint16:
×
112
            fmt = "H";
×
113
            itemsize = 2;
×
114
            break;
×
115
        case TypeId::Uint32:
1 ✔
116
            fmt = "I";
1 ✔
117
            itemsize = 4;
1 ✔
118
            break;
1 ✔
119
        case TypeId::Uint64:
50 ✔
120
            fmt = "Q";
50 ✔
121
            itemsize = 8;
50 ✔
122
            break;
50 ✔
123
        case TypeId::Float32:
1 ✔
124
            fmt = "f";
1 ✔
125
            itemsize = 4;
1 ✔
126
            break;
1 ✔
127
        case TypeId::Float64:
313 ✔
128
            fmt = "d";
313 ✔
129
            itemsize = 8;
313 ✔
130
            break;
313 ✔
131
        default:
76 ✔
132
            PyErr_SetString(PyExc_BufferError,
76 ✔
133
                            "Series type has no plain numeric buffer");
134
            return -1;
76 ✔
135
    }
136
    const void* data = dftu_series_data(h);
717 ✔
137
    std::int64_t n = dftu_series_length(h);
717 ✔
138
    if (!data && n > 0) {
717 !
139
        PyErr_SetString(PyExc_BufferError, "Series has no contiguous buffer");
×
140
        return -1;
×
141
    }
142
    // The values buffer is exposed as-is (zero-copy); shape/stride live in the
143
    // object (constant for an immutable column), so there is nothing to free.
144
    auto* obj = reinterpret_cast<SeriesObject*>(self);
717 ✔
145
    obj->buf_shape = static_cast<Py_ssize_t>(n);
717 ✔
146
    obj->buf_stride = itemsize;
717 !
147
    Py_INCREF(self);
148
    view->obj = self;
717 ✔
149
    view->buf = const_cast<void*>(data);
717 ✔
150
    view->len = static_cast<Py_ssize_t>(n) * itemsize;
717 ✔
151
    view->readonly = 1;
717 ✔
152
    view->itemsize = itemsize;
717 ✔
153
    view->format = (flags & PyBUF_FORMAT) ? const_cast<char*>(fmt) : nullptr;
717 !
154
    view->ndim = 1;
717 ✔
155
    view->shape = &obj->buf_shape;
717 ✔
156
    view->strides = &obj->buf_stride;
717 ✔
157
    view->suboffsets = nullptr;
717 ✔
158
    view->internal = nullptr;
717 ✔
159
    return 0;
717 ✔
160
}
161

162
// ---- getters -------------------------------------------------------------
163

164
PyObject* Series_get_type(PyObject* self, void*) {
4,539 ✔
165
    Series* a = as_series(self);
4,539 ✔
166
    if (!a) return nullptr;
4,539 !
167
    return PyLong_FromLong(static_cast<long>(a->type()));
4,539 ✔
168
}
169
PyObject* Series_get_length(PyObject* self, void*) {
347 ✔
170
    Series* a = as_series(self);
347 ✔
171
    if (!a) return nullptr;
347 !
172
    return PyLong_FromLongLong(a->length());
347 ✔
173
}
174
PyObject* Series_get_null_count(PyObject* self, void*) {
694 ✔
175
    Series* a = as_series(self);
694 ✔
176
    if (!a) return nullptr;
694 !
177
    return PyLong_FromLongLong(a->null_count());
694 ✔
178
}
179
PyObject* Series_get_encoding(PyObject* self, void*) {
957 ✔
180
    Series* a = as_series(self);
957 ✔
181
    if (!a) return nullptr;
957 !
182
    return PyLong_FromLong(static_cast<long>(a->encoding()));
957 ✔
183
}
184
PyObject* Series_get_time_unit(PyObject* self, void*) {
56 ✔
185
    Series* a = as_series(self);
56 ✔
186
    if (!a) return nullptr;
56 !
187
    return PyLong_FromLong(
112 ✔
188
        static_cast<long>(dftu_series_time_unit(a->handle())));
56 ✔
189
}
190

191
PyObject* Series_get_timezone(PyObject* self, void*) {
43 ✔
192
    Series* a = as_series(self);
43 ✔
193
    if (!a) return nullptr;
43 !
194
    return PyUnicode_FromString(dftu_series_timezone(a->handle()));
43 ✔
195
}
196

197
PyObject* Series_get_is_json(PyObject* self, void*) {
9,701 ✔
198
    Series* a = as_series(self);
9,701 ✔
199
    if (!a) return nullptr;
9,701 !
200
    return PyBool_FromLong(dftu_series_is_json(a->handle()));
9,701 ✔
201
}
202

203
PyMethodDef Series_methods[] = {
204
    {"add", Series_add, METH_O, "Elementwise a + b."},
205
    {"sub", Series_sub, METH_O, "Elementwise a - b."},
206
    {"mul", Series_mul, METH_O, "Elementwise a * b."},
207
    {"div", Series_div, METH_O, "Elementwise a / b."},
208
    {"add_scalar", Series_add_scalar, METH_O, "Broadcast a + scalar."},
209
    {"sub_scalar", Series_sub_scalar, METH_O, "Broadcast a - scalar."},
210
    {"mul_scalar", Series_mul_scalar, METH_O, "Broadcast a * scalar."},
211
    {"div_scalar", Series_div_scalar, METH_O, "Broadcast a / scalar."},
212
    {"floordiv", Series_floordiv, METH_VARARGS,
213
     "floordiv(other, reverse=False) -> a // other (a Series or a number; "
214
     "reverse computes other // a), Python's floor rule; a zero divisor is "
215
     "null."},
216
    {"mod", Series_mod, METH_VARARGS,
217
     "mod(other, reverse=False) -> a % other with the divisor's sign; a zero "
218
     "divisor is null."},
219
    {"pow", Series_pow, METH_VARARGS,
220
     "pow(other, reverse=False) -> a ** other; Int64 for two integers (a "
221
     "negative exponent is null), else Float64."},
222
    {"ffill", series_unary<dftu_series_ffill>, METH_NOARGS,
223
     "ffill() -> nulls filled from the nearest present value before them."},
224
    {"bfill", series_unary<dftu_series_bfill>, METH_NOARGS,
225
     "bfill() -> nulls filled from the nearest present value after them."},
226
    {"cast", Series_cast, METH_O,
227
     "Cast to a TypeId code; TypeError names both types for a pair the engine "
228
     "refuses."},
229
    {"prim", Series_prim, METH_O,
230
     "Apply a unary numeric primitive by Prim code (i64 in, i64 out)."},
231
    {"compare", Series_compare, METH_VARARGS,
232
     "compare(op, scalar) -> Bool column (op is a DFTU_CMP_* code)."},
233
    {"logical", Series_logical, METH_VARARGS,
234
     "logical(op, other) -> Bool column (op is a DFTU_LOGICAL_* code)."},
235
    {"logical_not", Series_logical_not, METH_NOARGS,
236
     "Boolean NOT of a Bool column."},
237
#ifdef DFTRACER_UTILS_ENABLE_ARROW
238
    {"__arrow_c_array__", Series_arrow_c_array, METH_VARARGS,
239
     "Arrow PyCapsule export: (schema_capsule, array_capsule)."},
240
#endif
241
    {"quantile", Series_quantile, METH_O,
242
     "quantile(q) -> float (linear interpolation, SIMD sort)."},
243
    {"median", Series_median, METH_NOARGS, "Median (quantile 0.5)."},
244
    {"variance", Series_variance, METH_VARARGS,
245
     "variance(sample=True) -> float."},
246
    {"stddev", Series_stddev, METH_VARARGS, "stddev(sample=True) -> float."},
247
    {"skewness", Series_skewness, METH_NOARGS, "Population skewness."},
248
    {"kurtosis", Series_kurtosis, METH_NOARGS, "Excess kurtosis."},
249
    {"nunique", Series_nunique, METH_NOARGS, "Number of distinct values."},
250
    {"unique", series_unary<dftu_series_unique>, METH_NOARGS,
251
     "Distinct values (ascending) -> Series."},
252
    {"value_counts", Series_value_counts, METH_NOARGS,
253
     "value_counts() -> DataFrame of distinct values and counts, "
254
     "most-frequent first."},
255
    {"abs", series_unary<dftu_series_abs>, METH_NOARGS,
256
     "Elementwise absolute value (SIMD)."},
257
    {"clip", Series_clip, METH_VARARGS,
258
     "clip(lo, hi) -> Series clamped to [lo, hi] (SIMD)."},
259
    {"round", series_unary<dftu_series_round>, METH_NOARGS,
260
     "Round floats to nearest (SIMD)."},
261
    {"fillna", Series_fillna, METH_O,
262
     "fillna(value) -> Series with nulls replaced."},
263
    {"cumsum", series_unary<dftu_series_cumsum>, METH_NOARGS,
264
     "Cumulative sum -> Series."},
265
    {"cummax", series_unary<dftu_series_cummax>, METH_NOARGS,
266
     "Running maximum -> Series."},
267
    {"cummin", series_unary<dftu_series_cummin>, METH_NOARGS,
268
     "Running minimum -> Series."},
269
    {"cum_prod", series_unary<dftu_series_cum_prod>, METH_NOARGS,
270
     "Running product -> Series."},
271
    {"cum_count", series_unary<dftu_series_cum_count>, METH_NOARGS,
272
     "Running count of non-null rows -> Int64 Series."},
273
    {"ceil", series_unary<dftu_series_ceil>, METH_NOARGS,
274
     "Round floats toward +inf (SIMD)."},
275
    {"floor", series_unary<dftu_series_floor>, METH_NOARGS,
276
     "Round floats toward -inf (SIMD)."},
277
    {"trunc", series_unary<dftu_series_trunc>, METH_NOARGS,
278
     "Round floats toward zero (SIMD)."},
279
    {"sign", series_unary<dftu_series_sign>, METH_NOARGS,
280
     "Sign as -1/0/1 (SIMD)."},
281
    {"negate", series_unary<dftu_series_negate>, METH_NOARGS,
282
     "Unary minus (SIMD)."},
283
    {"diff", series_unary<dftu_series_diff>, METH_NOARGS,
284
     "First difference x[i]-x[i-1]; row 0 null."},
285
    {"pct_change", series_unary<dftu_series_pct_change>, METH_NOARGS,
286
     "Percent change -> Float64 Series; row 0 null."},
287
    {"sqrt", series_unary<dftu_series_sqrt>, METH_NOARGS,
288
     "Square root -> Float64 Series (SIMD)."},
289
    {"exp", series_unary<dftu_series_exp>, METH_NOARGS,
290
     "Exponential -> Float64 Series."},
291
    {"log", series_unary<dftu_series_log>, METH_NOARGS,
292
     "Natural log -> Float64 Series."},
293
    {"null_mask", series_unary<dftu_series_null_mask>, METH_NOARGS,
294
     "Bool mask: row is null."},
295
    {"valid_mask", series_unary<dftu_series_valid_mask>, METH_NOARGS,
296
     "Bool mask: row is present."},
297
    {"is_nan", series_unary<dftu_series_is_nan>, METH_NOARGS,
298
     "Bool mask: value is NaN (SIMD)."},
299
    {"is_finite", series_unary<dftu_series_is_finite>, METH_NOARGS,
300
     "Bool mask: value is finite (SIMD)."},
301
    {"is_infinite", series_unary<dftu_series_is_infinite>, METH_NOARGS,
302
     "Bool mask: value is +/-Inf (SIMD)."},
303
    {"is_unique", series_unary<dftu_series_is_unique>, METH_NOARGS,
304
     "Bool mask: value occurs exactly once."},
305
    {"is_duplicated", series_unary<dftu_series_is_duplicated>, METH_NOARGS,
306
     "Bool mask: value is repeated."},
307
    {"is_sorted", DFTU_PYCFUNCTION(Series_is_sorted),
308
     METH_VARARGS | METH_KEYWORDS, "is_sorted(descending=False) -> bool."},
309
    {"drop_nulls", series_unary<dftu_series_drop_nulls>, METH_NOARGS,
310
     "Drop null rows -> Series."},
311
    {"is_in", Series_is_in, METH_O,
312
     "is_in(values) -> Bool mask where the value is in the values Series."},
313
    {"sort", DFTU_PYCFUNCTION(Series_sort), METH_VARARGS | METH_KEYWORDS,
314
     "sort(descending=False) -> sorted Series."},
315
    {"head", Series_head, METH_O, "head(n) -> first n rows Series."},
316
    {"tail", Series_tail, METH_O, "tail(n) -> last n rows Series."},
317
    {"reverse", series_unary<dftu_series_reverse>, METH_NOARGS,
318
     "Rows in reverse order -> Series."},
319
    {"shift", Series_shift, METH_O,
320
     "shift(n) -> Series shifted by n (vacated rows null)."},
321
    {"top_k", Series_top_k, METH_O, "top_k(k) -> the k largest rows Series."},
322
    {"bottom_k", Series_bottom_k, METH_O,
323
     "bottom_k(k) -> the k smallest rows Series."},
324
    {"sample", DFTU_PYCFUNCTION(Series_sample), METH_VARARGS | METH_KEYWORDS,
325
     "sample(n, seed=0) -> deterministic sample of n rows Series."},
326
    {"rank", DFTU_PYCFUNCTION(Series_rank), METH_VARARGS | METH_KEYWORDS,
327
     "rank(method='average', descending=False) -> Float64 Series "
328
     "(method: average|min|dense|ordinal)."},
329
    {"rolling", DFTU_PYCFUNCTION(Series_rolling), METH_VARARGS | METH_KEYWORDS,
330
     "rolling(window, op='sum') -> Float64 Series (op: sum|mean|min|max)."},
331
    {"rolling_var", Series_rolling_var, METH_O,
332
     "rolling_var(window) -> Float64 Series of per-window sample variance."},
333
    {"rolling_std", Series_rolling_std, METH_O,
334
     "rolling_std(window) -> Float64 Series of per-window sample std."},
335
    {"rolling_median", Series_rolling_median, METH_O,
336
     "rolling_median(window) -> Float64 Series of per-window median."},
337
    {"rolling_quantile", Series_rolling_quantile, METH_VARARGS,
338
     "rolling_quantile(window, q) -> Float64 Series of per-window quantile q."},
339
    {"ewm_mean", Series_ewm_mean, METH_O,
340
     "ewm_mean(alpha) -> Float64 Series, exponentially weighted mean."},
341
    {"ewm_std", Series_ewm_std, METH_O,
342
     "ewm_std(alpha) -> Float64 Series, exponentially weighted sample std."},
343
    {"cut", Series_cut, METH_VARARGS,
344
     "cut(breaks, flags=0) -> Int32 Series binning by the ascending breaks "
345
     "Series; flags 1 closes each interval on the right, 2 gives null outside "
346
     "the interior intervals and numbers them from 0."},
347
    {"qcut", Series_qcut, METH_O,
348
     "qcut(q) -> Int32 Series binning by the column's q-quantile edges."},
349
    {"search_sorted", Series_search_sorted, METH_O,
350
     "search_sorted(values) -> Int64 Series of lower-bound insertion indices."},
351
    {"interpolate", series_unary<dftu_series_interpolate>, METH_NOARGS,
352
     "interpolate() -> Float64 Series with null interiors linearly filled."},
353
    {"is_between", Series_is_between, METH_VARARGS,
354
     "is_between(lo, hi) -> Bool mask where lo <= value <= hi (SIMD)."},
355
    {"dot", Series_dot, METH_O,
356
     "dot(other) -> scalar sum of x[i]*y[i] over non-null pairs (SIMD)."},
357
    {"sum", series_reduce_scalar<&Series::sum>, METH_NOARGS,
358
     "Sum of non-null values -> scalar."},
359
    {"min", series_reduce_scalar<&Series::min>, METH_NOARGS,
360
     "Minimum non-null value -> scalar."},
361
    {"max", series_reduce_scalar<&Series::max>, METH_NOARGS,
362
     "Maximum non-null value -> scalar."},
363
    {"mean", series_reduce_f64<&Series::mean>, METH_NOARGS,
364
     "Mean of non-null values -> float."},
365
    {"count", series_reduce_i64<&Series::count>, METH_NOARGS,
366
     "Non-null row count -> int."},
367
    {"product", series_reduce_scalar<&Series::product>, METH_NOARGS,
368
     "Product of non-null values -> scalar."},
369
    {"mode", series_reduce_scalar<&Series::mode>, METH_NOARGS,
370
     "Most frequent non-null value -> scalar."},
371
    {"all", Series_all, METH_NOARGS,
372
     "Whether every non-null Bool value is true."},
373
    {"any", Series_any, METH_NOARGS,
374
     "Whether any non-null Bool value is true."},
375
    {"arg_min", series_reduce_i64<&Series::arg_min>, METH_NOARGS,
376
     "Index of the minimum non-null value (-1 if none)."},
377
    {"arg_max", series_reduce_i64<&Series::arg_max>, METH_NOARGS,
378
     "Index of the maximum non-null value (-1 if none)."},
379
    {"take", Series_take, METH_O,
380
     "take(indices) -> Series gathered at the given row indices."},
381
    {"where", Series_where, METH_VARARGS,
382
     "where(mask, other) -> Series: this value where the Bool mask is true, "
383
     "else other's (a null mask row takes other)."},
384
    {"filter", Series_filter, METH_O,
385
     "filter(mask) -> Series keeping rows where the Bool mask is true."},
386
    {"argsort", DFTU_PYCFUNCTION(Series_argsort), METH_VARARGS | METH_KEYWORDS,
387
     "argsort(descending=False) -> Int64 Series of the sorted row order."},
388
    {"dictionary_encode", Series_dictionary_encode, METH_NOARGS,
389
     "Dictionary-encode a String/Binary column -> Series."},
390
    {"str_into", Series_str_into, METH_VARARGS,
391
     "str_into(out, na=None): a String column's rows into a numpy object "
392
     "array of its length, null rows holding `na`."},
393
    {"np_parts", Series_np_parts, METH_VARARGS,
394
     "np_parts(nullable=False, na=None) -> (values, mask, dtype): the column "
395
     "in one native pass for numpy.frombuffer (bytearrays; a list of str for "
396
     "a String column, null rows holding `na`); mask is 1 = null or None."},
397
    {"to_pylist", Series_to_pylist, METH_NOARGS,
398
     "to_pylist() -> list of Python values, None for null; TypeError for a "
399
     "column type with no native conversion."},
400
    {"physical", Series_physical, METH_NOARGS,
401
     "physical() -> _Series: the integers of a date, time, timestamp, "
402
     "duration or float16 column (buffers shared)."},
403
    {"to_bytes", Series_to_bytes, METH_NOARGS,
404
     "to_bytes() -> bytes: the column in the native frame format."},
405
    {"item", Series_item, METH_O,
406
     "item(i) -> the value at row i as a Python object (None for null)."},
407
    {"materialize", Series_materialize, METH_NOARGS,
408
     "Materialize any encoding to a new FLAT Series (gather)."},
409
    {"share", Series_share, METH_NOARGS,
410
     "A new owned Series sharing this column's buffers zero-copy."},
411
    {"slice", Series_slice, METH_VARARGS,
412
     "slice(offset, length) -> view Series of a row range, sharing the "
413
     "value buffers and keeping the layout; raises for list, map and struct."},
414
    {"str_eq", Series_str_eq, METH_O,
415
     "str_eq(rhs) -> Bool Series where the string equals rhs."},
416
    {"str_contains", Series_str_contains, METH_O,
417
     "str_contains(needle) -> Bool Series where the string contains needle."},
418
    {"str_starts_with", Series_str_starts_with, METH_O,
419
     "str_starts_with(prefix) -> Bool Series where the string starts with "
420
     "prefix."},
421
    {"str_ends_with", Series_str_ends_with, METH_O,
422
     "str_ends_with(suffix) -> Bool Series where the string ends with suffix."},
423
    {"str_like", Series_str_like, METH_O,
424
     "str_like(pattern) -> Bool Series matching the SQL LIKE / glob pattern "
425
     "(% any run, _ one char, backslash escapes a literal %/_/backslash)."},
426
    {"str_matches", Series_str_matches, METH_O,
427
     "str_matches(pattern) -> Bool Series where the whole string matches the "
428
     "duql regex."},
429
    {"str_search", Series_str_search, METH_O,
430
     "str_search(pattern) -> Bool Series where the duql regex matches "
431
     "anywhere in the string."},
432
    {"str_len_bytes", Series_str_len_bytes, METH_NOARGS,
433
     "str_len_bytes() -> Int64 Series of per-row byte length."},
434
    {"str_len_chars", Series_str_len_chars, METH_NOARGS,
435
     "str_len_chars() -> Int64 Series of per-row UTF-8 codepoint count."},
436
    {"str_find", Series_str_find, METH_O,
437
     "str_find(needle) -> Int64 Series of the first byte index, or -1."},
438
    {"fnv1a", Series_fnv1a, METH_NOARGS,
439
     "fnv1a() -> UInt64 Series of the FNV-1a 64 hash of each row's bytes."},
440
    {"hex64_parse", Series_hex64_parse, METH_NOARGS,
441
     "hex64_parse() -> UInt64 Series parsing each row as hex64; unparsable "
442
     "rows are null."},
443
    {"hex64_format", Series_hex64_format, METH_NOARGS,
444
     "hex64_format() -> String Series formatting each UInt64/Int64 row as "
445
     "dftracer's 16-lowercase-hex-digit form; the inverse of hex64_parse."},
446
    {"to_lowercase", Series_to_lowercase, METH_NOARGS,
447
     "to_lowercase() -> String Series, ASCII case fold (non-ASCII unchanged)."},
448
    {"to_uppercase", Series_to_uppercase, METH_NOARGS,
449
     "to_uppercase() -> String Series, ASCII case fold (non-ASCII unchanged)."},
450
    {"str_strip", Series_str_strip, METH_NOARGS,
451
     "str_strip() -> String Series trimmed of ASCII whitespace both ends."},
452
    {"str_lstrip", Series_str_lstrip, METH_NOARGS,
453
     "str_lstrip() -> String Series trimmed of leading ASCII whitespace."},
454
    {"str_rstrip", Series_str_rstrip, METH_NOARGS,
455
     "str_rstrip() -> String Series trimmed of trailing ASCII whitespace."},
456
    {"str_replace", Series_str_replace, METH_VARARGS,
457
     "str_replace(pat, repl) -> String Series, first literal occurrence."},
458
    {"str_replace_all", Series_str_replace_all, METH_VARARGS,
459
     "str_replace_all(pat, repl) -> String Series, all literal occurrences."},
460
    {"str_slice", Series_str_slice, METH_VARARGS,
461
     "str_slice(start, length=-1) -> String Series substring by byte offset."},
462
    {"str_pad_start", DFTU_PYCFUNCTION(Series_str_pad_start),
463
     METH_VARARGS | METH_KEYWORDS,
464
     "str_pad_start(width, fill=' ') -> left-padded String Series."},
465
    {"str_pad_end", DFTU_PYCFUNCTION(Series_str_pad_end),
466
     METH_VARARGS | METH_KEYWORDS,
467
     "str_pad_end(width, fill=' ') -> right-padded String Series."},
468
    {"str_zfill", Series_str_zfill, METH_O,
469
     "str_zfill(width) -> String Series left-padded with '0' after any sign."},
470
    {"str_split", Series_str_split, METH_O,
471
     "str_split(sep) -> List<String> Series split on the literal sep."},
472
    {"str_extract", Series_str_extract, METH_VARARGS,
473
     "str_extract(pattern, group=1) -> String Series of the regex capture "
474
     "group per row, null where there is no match."},
475
    {"str_regex_replace", Series_str_regex_replace, METH_VARARGS,
476
     "str_regex_replace(pattern, to) -> String Series with every regex match "
477
     "replaced by to ($n, ${n}, ${name}, $$ insert groups)."},
478
    {"list_len", Series_list_len, METH_NOARGS,
479
     "list_len() -> Int64 Series of each row's list length."},
480
    {"list_get", Series_list_get, METH_O,
481
     "list_get(index) -> the element at index of each row's list (negative "
482
     "from the end), null where the list is too short."},
483
    {"list_join", Series_list_join, METH_O,
484
     "list_join(sep) -> each row's list of strings joined with sep."},
485
    {"str_case", Series_str_case, METH_O,
486
     "str_case(code) -> ASCII case form: 0 capitalize, 1 title, 2 swapcase."},
487
    {"str_is", Series_str_is, METH_O,
488
     "str_is(code) -> Bool: 0 alnum, 1 alpha, 2 digit, 3 decimal, 4 numeric, "
489
     "5 space, 6 lower, 7 upper, 8 title (ASCII; an empty string is false)."},
490
    {"str_count", Series_str_count, METH_O,
491
     "str_count(pat) -> Int64 non-overlapping occurrences of the literal."},
492
    {"str_rfind", Series_str_rfind, METH_O,
493
     "str_rfind(needle) -> Int64 byte index of the last occurrence, or -1."},
494
    {"str_remove_prefix", Series_str_remove_prefix, METH_O,
495
     "str_remove_prefix(prefix) -> each row without a leading prefix."},
496
    {"str_remove_suffix", Series_str_remove_suffix, METH_O,
497
     "str_remove_suffix(suffix) -> each row without a trailing suffix."},
498
    {"str_repeat", Series_str_repeat, METH_O,
499
     "str_repeat(n) -> each row repeated n times."},
500
    {"str_center", DFTU_PYCFUNCTION(Series_str_center),
501
     METH_VARARGS | METH_KEYWORDS,
502
     "str_center(width, fill=' ') -> each row centered in width bytes."},
503
    {"str_cat", Series_str_cat, METH_O,
504
     "str_cat(other) -> row-wise concatenation with another String Series."},
505
    {"str_findall", Series_str_findall, METH_O,
506
     "str_findall(pattern) -> List<String> of every regex match per row."},
507
    {"str_partition", DFTU_PYCFUNCTION(Series_str_partition),
508
     METH_VARARGS | METH_KEYWORDS,
509
     "str_partition(sep, from_right=False) -> List<String> of (head, sep, "
510
     "tail) per row at the first (last) occurrence."},
511
    {"dt_part", Series_dt_part, METH_VARARGS,
512
     "dt_part(code, unit=2) -> Int64 calendar part (0 year .. 16 epoch days) "
513
     "of a Timestamp / Date / Duration column, or an Int64 column read in "
514
     "unit (0 s, 1 ms, 2 us, 3 ns)."},
515
    {"dt_format", Series_dt_format, METH_VARARGS,
516
     "dt_format(fmt, unit=2) -> String strftime of a Timestamp / Date column, "
517
     "or an Int64 column read in unit (0 s, 1 ms, 2 us, 3 ns); raises "
518
     "ValueError on an unsupported directive."},
519
    {"dt_round", Series_dt_round, METH_VARARGS,
520
     "dt_round(every, mode) -> each instant rounded to a multiple of every "
521
     "(the column's unit) by mode 0 floor, 1 ceil, 2 round (half to even)."},
522
    {"with_timezone", Series_with_timezone, METH_O,
523
     "with_timezone(tz) -> the same instants under zone tz ('' for naive); "
524
     "Timestamp only."},
525
    {"is_null", Series_is_null, METH_O, "is_null(i) -> whether row i is null."},
526
    {"num_children", Series_num_children, METH_NOARGS,
527
     "Child count: 1 for a List, the field count for a Struct, else 0."},
528
    {"child", Series_child, METH_O,
529
     "child(i) -> child Series (List: 0=values; Struct: field i)."},
530
    {nullptr, nullptr, 0, nullptr}};
531

532
PySequenceMethods Series_as_sequence = {};
533
PyBufferProcs Series_as_buffer = {};
534

535
PyGetSetDef Series_getset[] = {
536
    {"type", Series_get_type, nullptr, "TypeId code.", nullptr},
537
    {"length", Series_get_length, nullptr, "Row count.", nullptr},
538
    {"null_count", Series_get_null_count, nullptr, "Null row count.", nullptr},
539
    {"encoding", Series_get_encoding, nullptr, "Encoding code.", nullptr},
540
    {"time_unit", Series_get_time_unit, nullptr,
541
     "dftu_time_unit code of a Timestamp / Time / Duration column (0 s, 1 "
542
     "ms, 2 us, 3 ns).",
543
     nullptr},
544
    {"timezone", Series_get_timezone, nullptr,
545
     "Zone name of a Timestamp column; '' for a naive one or another type.",
546
     nullptr},
547
    {"nbytes", Series_get_nbytes, nullptr,
548
     "Bytes held by the column's buffers, children included.", nullptr},
549
    {"is_json", Series_get_is_json, nullptr,
550
     "Whether this String column holds canonical JSON text per value.",
551
     nullptr},
552
    {nullptr, nullptr, nullptr, nullptr, nullptr}};
553

554
}  // namespace
555

556
}  // namespace dftracer::utils::python::series_detail
557

558
namespace dftracer::utils::python {
559

560
PyObject* wrap_vec_column(dftracer::utils::dataframe::Series&& col) {
11,592 ✔
561
    return series_detail::make_series(std::move(col));
11,592 ✔
562
}
563

564
const dftracer::utils::dataframe::Series* unwrap_vec_column(PyObject* o) {
11,921 ✔
565
    if (!PyObject_TypeCheck(o, &series_detail::SeriesType)) return nullptr;
11,921 !
566
    return &reinterpret_cast<series_detail::SeriesObject*>(o)->col;
11,921 ✔
567
}
568

569
#ifdef DFTRACER_UTILS_ENABLE_ARROW
570
dftracer::utils::dataframe::Series column_from_arrow(PyObject* arrow_array) {
688 ✔
571
    return series_detail::import_arrow_column(arrow_array);
688 ✔
572
}
573
#endif
574

575
int init_series(PyObject* m) {
7 ✔
576
    using namespace series_detail;
577
    SeriesType = {};
7 ✔
578
    SeriesType.ob_base = {PyObject_HEAD_INIT(nullptr) 0};
7 ✔
579
    SeriesType.tp_name = "dftracer_utils_ext._Series";
7 ✔
580
    SeriesType.tp_basicsize = sizeof(SeriesObject);
7 ✔
581
    SeriesType.tp_flags = Py_TPFLAGS_DEFAULT;
7 ✔
582
    SeriesType.tp_doc =
7 ✔
583
        "Native columnar Series handle (SIMD ops + Arrow capsule).";
584
    SeriesType.tp_dealloc = reinterpret_cast<destructor>(Series_dealloc);
7 ✔
585
    Series_as_sequence.sq_length = Series_length_sq;
7 ✔
586
    SeriesType.tp_as_sequence = &Series_as_sequence;
7 ✔
587
    Series_as_buffer.bf_getbuffer = Series_getbuffer;
7 ✔
588
    SeriesType.tp_as_buffer = &Series_as_buffer;
7 ✔
589
    SeriesType.tp_methods = Series_methods;
7 ✔
590
    SeriesType.tp_getset = Series_getset;
7 ✔
591
    SeriesType.tp_new =
7 ✔
592
        nullptr;  // created only via _series_from_arrow / kernels
593
    if (register_type(m, &SeriesType, "_Series") < 0) return -1;
7 !
594

595
#ifdef DFTRACER_UTILS_ENABLE_ARROW
596
    static PyMethodDef from_arrow_def = {
597
        "_series_from_arrow", vec_from_arrow, METH_O,
598
        "_series_from_arrow(arrow_array) -> _Series: import a pyarrow array "
599
        "into a native columnar Series."};
600
    PyObject* fn = PyCFunction_NewEx(&from_arrow_def, nullptr, nullptr);
7 ✔
601
    if (!fn) return -1;
7 !
602
    if (PyModule_AddObject(m, "_series_from_arrow", fn) < 0) {
7 !
603
        Py_DECREF(fn);
604
        return -1;
×
605
    }
606
#endif
607

608
    static PyMethodDef from_list_def = {
609
        "_series_from_list", vec_from_list, METH_VARARGS,
610
        "_series_from_list(values[, type_id]) -> _Series: a column from a list "
611
        "of bool, int, float, str, bytes, datetime, date, time, timedelta or "
612
        "Decimal (None is null), typed `type_id` when given; TypeError "
613
        "otherwise."};
614
    PyObject* list_fn = PyCFunction_NewEx(&from_list_def, nullptr, nullptr);
7 ✔
615
    if (!list_fn) return -1;
7 !
616
    if (PyModule_AddObject(m, "_series_from_list", list_fn) < 0) {
7 !
617
        Py_DECREF(list_fn);
618
        return -1;
×
619
    }
620

621
    static PyMethodDef nulls_def = {
622
        "_series_nulls", series_nulls, METH_VARARGS,
623
        "_series_nulls(type_id, n) -> _Series: a column of `n` nulls of that "
624
        "type."};
625
    PyObject* nulls_fn = PyCFunction_NewEx(&nulls_def, nullptr, nullptr);
7 ✔
626
    if (!nulls_fn) return -1;
7 !
627
    if (PyModule_AddObject(m, "_series_nulls", nulls_fn) < 0) {
7 !
628
        Py_DECREF(nulls_fn);
629
        return -1;
×
630
    }
631

632
    static PyMethodDef retype_def = {
633
        "_series_retype", series_retype, METH_VARARGS,
634
        "_series_retype(series, type_id[, unit, timezone, precision, scale, "
635
        "width]) -> _Series: the same buffers read as another type of the "
636
        "same width."};
637
    PyObject* retype_fn = PyCFunction_NewEx(&retype_def, nullptr, nullptr);
7 ✔
638
    if (!retype_fn) return -1;
7 !
639
    if (PyModule_AddObject(m, "_series_retype", retype_fn) < 0) {
7 !
640
        Py_DECREF(retype_fn);
641
        return -1;
×
642
    }
643
    static PyMethodDef from_bytes_def = {
644
        "_series_from_bytes", series_from_bytes, METH_O,
645
        "_series_from_bytes(bytes) -> _Series written by Series.to_bytes."};
646
    PyObject* bytes_fn = PyCFunction_NewEx(&from_bytes_def, nullptr, nullptr);
7 ✔
647
    if (!bytes_fn) return -1;
7 !
648
    if (PyModule_AddObject(m, "_series_from_bytes", bytes_fn) < 0) {
7 !
649
        Py_DECREF(bytes_fn);
650
        return -1;
×
651
    }
652

653
    static PyMethodDef from_numpy_def = {
654
        "_series_from_numpy", vec_from_numpy, METH_VARARGS,
655
        "_series_from_numpy(array[, mask]) -> _Series: import a 1-D "
656
        "C-contiguous numeric, float16 or bool numpy array (buffer protocol; "
657
        "numbers borrow the memory, no pyarrow); `mask` is a bool array, true "
658
        "where null."};
659
    PyObject* np_fn = PyCFunction_NewEx(&from_numpy_def, nullptr, nullptr);
7 ✔
660
    if (!np_fn) return -1;
7 !
661
    if (PyModule_AddObject(m, "_series_from_numpy", np_fn) < 0) {
7 !
662
        Py_DECREF(np_fn);
663
        return -1;
×
664
    }
665
    return 0;
7 ✔
666
}
667

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