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

llnl-asr / dftracer-utils / 38350517275

13 Oct 2026 05:15AM UTC coverage: 63.708% (+1.1%) from 62.623%
38350517275

push

github

rayandrew
feat(python): fill the pandas api gaps and print frames like pandas

Adds normalize, translate, wrap and a sketch_quantile group aggregate as
engine kernels, and the rest as compositions of existing ops.

Merging stored sketches now skips every sketch whose accuracy is not the
default, in duql too: keeping the first accuracy seen made the result
depend on row order once a group was split across partial states.

128013 of 248204 branches covered (51.58%)

Branch coverage included in aggregate %.

652 of 696 new or added lines in 15 files covered. (93.68%)

376 existing lines in 32 files now uncovered.

106752 of 120300 relevant lines covered (88.74%)

3382973.47 hits per line

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

66.99
/src/dftracer/utils/python/series/string.cpp
1
#include <dftracer/utils/python/series_detail.h>
2

3
#include <cstddef>
4
#include <cstdint>
5
#include <string_view>
6

7
namespace dftracer::utils::python::series_detail {
8

9
namespace {
10

11
// Read a Python str as a string_view; the buffer stays owned by `arg`.
12
bool as_str_view(PyObject* arg, std::string_view* out) {
438 ✔
13
    Py_ssize_t len = 0;
438 ✔
14
    const char* data = PyUnicode_AsUTF8AndSize(arg, &len);
438 !
15
    if (!data) return false;
438 ✔
16
    *out = std::string_view(data, static_cast<std::size_t>(len));
438 ✔
17
    return true;
438 ✔
18
}
219 ✔
19

20
// A single-character pad string -> its first byte; empty is rejected.
21
bool as_fill_char(PyObject* arg, char* out) {
38 ✔
22
    std::string_view s;
38 ✔
23
    if (!as_str_view(arg, &s)) return false;
38 !
24
    if (s.empty()) {
38 !
25
        PyErr_SetString(PyExc_ValueError, "fill must be a non-empty string");
×
26
        return false;
×
27
    }
28
    *out = s[0];
38 ✔
29
    return true;
38 ✔
30
}
19 ✔
31

32
}  // namespace
33

34
PyObject* Series_str_eq(PyObject* self, PyObject* arg) {
50 ✔
35
    Series* a = as_series(self);
50 !
36
    if (!a) return nullptr;
50 ✔
37
    std::string_view rhs;
50 ✔
38
    if (!as_str_view(arg, &rhs)) return nullptr;
50 !
39
    return make_series(a->str_eq(rhs));
50 !
40
}
25 ✔
41
PyObject* Series_str_contains(PyObject* self, PyObject* arg) {
10 ✔
42
    Series* a = as_series(self);
10 !
43
    if (!a) return nullptr;
10 ✔
44
    std::string_view needle;
10 ✔
45
    if (!as_str_view(arg, &needle)) return nullptr;
10 !
46
    return make_series(a->str_contains(needle));
10 !
47
}
5 ✔
48
PyObject* Series_str_starts_with(PyObject* self, PyObject* arg) {
6 ✔
49
    Series* a = as_series(self);
6 !
50
    if (!a) return nullptr;
6 ✔
51
    std::string_view prefix;
6 ✔
52
    if (!as_str_view(arg, &prefix)) return nullptr;
6 !
53
    return make_series(a->str_starts_with(prefix));
6 !
54
}
3 ✔
55
PyObject* Series_str_ends_with(PyObject* self, PyObject* arg) {
6 ✔
56
    Series* a = as_series(self);
6 !
57
    if (!a) return nullptr;
6 ✔
58
    std::string_view suffix;
6 ✔
59
    if (!as_str_view(arg, &suffix)) return nullptr;
6 !
60
    return make_series(a->str_ends_with(suffix));
6 !
61
}
3 ✔
62
PyObject* Series_str_matches(PyObject* self, PyObject* arg) {
8 ✔
63
    Series* a = as_series(self);
8 !
64
    if (!a) return nullptr;
8 ✔
65
    std::string_view pattern;
8 ✔
66
    if (!as_str_view(arg, &pattern)) return nullptr;
8 !
67
    return make_series(a->str_matches(pattern));
8 !
68
}
4 ✔
69
PyObject* Series_str_search(PyObject* self, PyObject* arg) {
6 ✔
70
    Series* a = as_series(self);
6 !
71
    if (!a) return nullptr;
6 ✔
72
    std::string_view pattern;
6 ✔
73
    if (!as_str_view(arg, &pattern)) return nullptr;
6 !
74
    return make_series(a->str_search(pattern));
6 !
75
}
3 ✔
76
PyObject* Series_str_like(PyObject* self, PyObject* arg) {
12 ✔
77
    Series* a = as_series(self);
12 !
78
    if (!a) return nullptr;
12 ✔
79
    std::string_view pattern;
12 ✔
80
    if (!as_str_view(arg, &pattern)) return nullptr;
12 !
81
    return make_series(a->str_like(pattern));
12 !
82
}
6 ✔
83
PyObject* Series_str_len_bytes(PyObject* self, PyObject*) {
16 ✔
84
    Series* a = as_series(self);
16 ✔
85
    if (!a) return nullptr;
16 ✔
86
    return make_series(a->str_len_bytes());
16 !
87
}
8 ✔
88
PyObject* Series_str_len_chars(PyObject* self, PyObject*) {
10 ✔
89
    Series* a = as_series(self);
10 ✔
90
    if (!a) return nullptr;
10 ✔
91
    return make_series(a->str_len_chars());
10 !
92
}
5 ✔
93
PyObject* Series_str_find(PyObject* self, PyObject* arg) {
12 ✔
94
    Series* a = as_series(self);
12 !
95
    if (!a) return nullptr;
12 ✔
96
    std::string_view needle;
12 ✔
97
    if (!as_str_view(arg, &needle)) return nullptr;
12 !
98
    return make_series(a->str_find(needle));
12 !
99
}
6 ✔
100
PyObject* Series_fnv1a(PyObject* self, PyObject*) {
2 ✔
101
    Series* a = as_series(self);
2 ✔
102
    if (!a) return nullptr;
2 ✔
103
    return make_series(a->fnv1a());
2 !
104
}
1 ✔
105
PyObject* Series_hex64_parse(PyObject* self, PyObject*) {
4 ✔
106
    Series* a = as_series(self);
4 ✔
107
    if (!a) return nullptr;
4 ✔
108
    return make_series(a->hex64_parse());
4 !
109
}
2 ✔
110
PyObject* Series_hex64_format(PyObject* self, PyObject*) {
2 ✔
111
    Series* a = as_series(self);
2 ✔
112
    if (!a) return nullptr;
2 ✔
113
    return make_series(a->hex64_format());
2 !
114
}
1 ✔
115
PyObject* Series_to_lowercase(PyObject* self, PyObject*) {
14 ✔
116
    Series* a = as_series(self);
14 ✔
117
    if (!a) return nullptr;
14 ✔
118
    return make_series(a->to_lowercase());
14 !
119
}
7 ✔
120
PyObject* Series_to_uppercase(PyObject* self, PyObject*) {
10 ✔
121
    Series* a = as_series(self);
10 ✔
122
    if (!a) return nullptr;
10 ✔
123
    return make_series(a->to_uppercase());
10 !
124
}
5 ✔
125
PyObject* Series_str_strip(PyObject* self, PyObject*) {
8 ✔
126
    Series* a = as_series(self);
8 ✔
127
    if (!a) return nullptr;
8 ✔
128
    return make_series(a->str_strip());
8 !
129
}
4 ✔
130
PyObject* Series_str_lstrip(PyObject* self, PyObject*) {
2 ✔
131
    Series* a = as_series(self);
2 ✔
132
    if (!a) return nullptr;
2 ✔
133
    return make_series(a->str_lstrip());
2 !
134
}
1 ✔
135
PyObject* Series_str_rstrip(PyObject* self, PyObject*) {
2 ✔
136
    Series* a = as_series(self);
2 ✔
137
    if (!a) return nullptr;
2 ✔
138
    return make_series(a->str_rstrip());
2 !
139
}
1 ✔
140
PyObject* Series_str_replace(PyObject* self, PyObject* args) {
6 ✔
141
    Series* a = as_series(self);
6 !
142
    if (!a) return nullptr;
6 ✔
143
    PyObject* pat = nullptr;
6 ✔
144
    PyObject* repl = nullptr;
6 ✔
145
    if (!PyArg_ParseTuple(args, "OO", &pat, &repl)) return nullptr;
6 !
146
    std::string_view p, r;
6 ✔
147
    if (!as_str_view(pat, &p) || !as_str_view(repl, &r)) return nullptr;
6 !
148
    return make_series(a->str_replace(p, r));
6 !
149
}
3 ✔
150
PyObject* Series_str_replace_all(PyObject* self, PyObject* args) {
10 ✔
151
    Series* a = as_series(self);
10 !
152
    if (!a) return nullptr;
10 ✔
153
    PyObject* pat = nullptr;
10 ✔
154
    PyObject* repl = nullptr;
10 ✔
155
    if (!PyArg_ParseTuple(args, "OO", &pat, &repl)) return nullptr;
10 !
156
    std::string_view p, r;
10 ✔
157
    if (!as_str_view(pat, &p) || !as_str_view(repl, &r)) return nullptr;
10 !
158
    return make_series(a->str_replace_all(p, r));
10 !
159
}
5 ✔
160
PyObject* Series_str_slice(PyObject* self, PyObject* args) {
34 ✔
161
    Series* a = as_series(self);
34 !
162
    if (!a) return nullptr;
34 ✔
163
    long long start = 0;
34 ✔
164
    long long length = -1;
34 ✔
165
    if (!PyArg_ParseTuple(args, "L|L", &start, &length)) return nullptr;
34 !
166
    return make_series(a->str_slice(static_cast<std::int64_t>(start),
68 !
167
                                    static_cast<std::int64_t>(length)));
34 ✔
168
}
17 ✔
169
PyObject* Series_str_pad_start(PyObject* self, PyObject* args, PyObject* kwds) {
14 ✔
170
    Series* a = as_series(self);
14 !
171
    if (!a) return nullptr;
14 ✔
172
    long long width = 0;
14 ✔
173
    PyObject* fill = nullptr;
14 ✔
174
    static const char* kwlist[] = {"width", "fill", nullptr};
175
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "L|O",
14 !
176
                                     const_cast<char**>(kwlist), &width, &fill))
177
        return nullptr;
×
178
    char f = ' ';
14 ✔
179
    if (fill && !as_fill_char(fill, &f)) return nullptr;
14 !
180
    return make_series(a->str_pad_start(static_cast<std::int64_t>(width), f));
14 !
181
}
7 ✔
182
PyObject* Series_str_pad_end(PyObject* self, PyObject* args, PyObject* kwds) {
14 ✔
183
    Series* a = as_series(self);
14 !
184
    if (!a) return nullptr;
14 ✔
185
    long long width = 0;
14 ✔
186
    PyObject* fill = nullptr;
14 ✔
187
    static const char* kwlist[] = {"width", "fill", nullptr};
188
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "L|O",
14 !
189
                                     const_cast<char**>(kwlist), &width, &fill))
190
        return nullptr;
×
191
    char f = ' ';
14 ✔
192
    if (fill && !as_fill_char(fill, &f)) return nullptr;
14 !
193
    return make_series(a->str_pad_end(static_cast<std::int64_t>(width), f));
14 !
194
}
7 ✔
195
PyObject* Series_str_zfill(PyObject* self, PyObject* arg) {
8 ✔
196
    Series* a = as_series(self);
8 ✔
197
    if (!a) return nullptr;
8 ✔
198
    long long width = PyLong_AsLongLong(arg);
8 ✔
199
    if (width == -1 && PyErr_Occurred()) return nullptr;
8 !
200
    return make_series(a->str_zfill(static_cast<std::int64_t>(width)));
8 !
201
}
4 ✔
202
PyObject* Series_str_split(PyObject* self, PyObject* arg) {
38 ✔
203
    Series* a = as_series(self);
38 !
204
    if (!a) return nullptr;
38 ✔
205
    std::string_view sep;
38 ✔
206
    if (!as_str_view(arg, &sep)) return nullptr;
38 !
207
    return make_series(a->str_split(sep));
38 !
208
}
19 ✔
209
PyObject* Series_str_extract(PyObject* self, PyObject* args) {
20 ✔
210
    Series* a = as_series(self);
20 !
211
    if (!a) return nullptr;
20 ✔
212
    PyObject* pat = nullptr;
20 ✔
213
    long long group = 1;
20 ✔
214
    if (!PyArg_ParseTuple(args, "O|L", &pat, &group)) return nullptr;
20 !
215
    std::string_view pattern;
20 ✔
216
    if (!as_str_view(pat, &pattern)) return nullptr;
20 !
217
    if (group < 0) {
20 ✔
218
        PyErr_SetString(PyExc_ValueError, "str_extract: group must be >= 0");
2 !
219
        return nullptr;
2 ✔
220
    }
221
    Series out = a->str_extract(pattern, static_cast<std::int64_t>(group));
18 !
222
    if (!out.valid()) {
18 ✔
223
        PyErr_SetString(PyExc_ValueError,
2 !
224
                        "str_extract: the pattern does not compile");
225
        return nullptr;
2 ✔
226
    }
227
    return make_series(std::move(out));
16 !
228
}
19 ✔
229
PyObject* Series_str_regex_replace(PyObject* self, PyObject* args) {
32 ✔
230
    Series* a = as_series(self);
32 !
231
    if (!a) return nullptr;
32 ✔
232
    PyObject *pat = nullptr, *to = nullptr;
32 ✔
233
    if (!PyArg_ParseTuple(args, "OO", &pat, &to)) return nullptr;
32 !
234
    std::string_view pattern, repl;
32 ✔
235
    if (!as_str_view(pat, &pattern) || !as_str_view(to, &repl)) return nullptr;
32 !
236
    Series out = a->str_regex_replace(pattern, repl);
32 !
237
    if (!out.valid()) {
32 ✔
238
        PyErr_SetString(
8 !
239
            PyExc_ValueError,
4 ✔
240
            "str_regex_replace: the pattern or the replacement is invalid");
241
        return nullptr;
8 ✔
242
    }
243
    return make_series(std::move(out));
24 !
244
}
32 ✔
245
PyObject* Series_list_len(PyObject* self, PyObject*) {
4 ✔
246
    Series* a = as_series(self);
4 !
247
    if (!a) return nullptr;
4 ✔
248
    Series out = a->list_len();
4 !
249
    if (!out.valid()) {
4 !
250
        PyErr_SetString(PyExc_TypeError, "list_len: not a List column");
×
251
        return nullptr;
×
252
    }
253
    return make_series(std::move(out));
4 !
254
}
4 ✔
255
PyObject* Series_list_get(PyObject* self, PyObject* arg) {
54 ✔
256
    Series* a = as_series(self);
54 !
257
    if (!a) return nullptr;
54 ✔
258
    long long index = PyLong_AsLongLong(arg);
54 !
259
    if (index == -1 && PyErr_Occurred()) return nullptr;
54 !
260
    Series out = a->list_get(static_cast<std::int64_t>(index));
54 !
261
    if (!out.valid()) {
54 !
262
        PyErr_SetString(PyExc_TypeError, "list_get: not a List column");
×
263
        return nullptr;
×
264
    }
265
    return make_series(std::move(out));
54 !
266
}
54 ✔
267

268
namespace {
269

270
// A kernel that takes one str argument, refusing a non-String column.
271
template <Series (Series::*Method)(std::string_view) const>
272
PyObject* str_arg_op(PyObject* self, PyObject* arg, const char* name) {
22 ✔
273
    Series* a = as_series(self);
22 !
274
    if (!a) return nullptr;
22 !
275
    std::string_view s;
22 ✔
276
    if (!as_str_view(arg, &s)) return nullptr;
22 !
277
    Series out = (a->*Method)(s);
22 !
278
    if (!out.valid()) {
22 !
279
        PyErr_Format(PyExc_TypeError, "%s: not a String column", name);
2 !
280
        return nullptr;
2 ✔
281
    }
282
    return make_series(std::move(out));
20 !
283
}
22 ✔
284

285
}  // namespace
286

287
PyObject* Series_str_case(PyObject* self, PyObject* arg) {
50 ✔
288
    Series* a = as_series(self);
50 !
289
    if (!a) return nullptr;
50 ✔
290
    const long code = PyLong_AsLong(arg);
50 !
291
    if (code == -1 && PyErr_Occurred()) return nullptr;
50 !
292
    if (code < DFTU_STR_CAPITALIZE || code > DFTU_STR_SWAPCASE) {
50 !
293
        PyErr_SetString(PyExc_ValueError,
2 !
294
                        "str_case: code must be 0 (capitalize), 1 (title) "
295
                        "or 2 (swapcase)");
296
        return nullptr;
2 ✔
297
    }
298
    Series out = a->str_case(static_cast<std::int32_t>(code));
48 !
299
    if (!out.valid()) {
48 !
300
        PyErr_SetString(PyExc_TypeError, "str_case: not a String column");
×
301
        return nullptr;
×
302
    }
303
    return make_series(std::move(out));
48 !
304
}
49 ✔
305
PyObject* Series_str_is(PyObject* self, PyObject* arg) {
44 ✔
306
    Series* a = as_series(self);
44 !
307
    if (!a) return nullptr;
44 ✔
308
    const long code = PyLong_AsLong(arg);
44 !
309
    if (code == -1 && PyErr_Occurred()) return nullptr;
44 !
310
    if (code < DFTU_STR_ALNUM || code > DFTU_STR_TITLE) {
44 !
311
        PyErr_SetString(PyExc_ValueError,
×
312
                        "str_is: code must be 0..8 (alnum, alpha, digit, "
313
                        "decimal, numeric, space, lower, upper, title)");
314
        return nullptr;
×
315
    }
316
    Series out = a->str_is(static_cast<std::int32_t>(code));
44 !
317
    if (!out.valid()) {
44 !
318
        PyErr_SetString(PyExc_TypeError, "str_is: not a String column");
×
319
        return nullptr;
×
320
    }
321
    return make_series(std::move(out));
44 !
322
}
44 ✔
323
PyObject* Series_str_count(PyObject* self, PyObject* arg) {
6 ✔
324
    return str_arg_op<&Series::str_count>(self, arg, "str_count");
6 ✔
325
}
326
PyObject* Series_str_rfind(PyObject* self, PyObject* arg) {
8 ✔
327
    return str_arg_op<&Series::str_rfind>(self, arg, "str_rfind");
8 ✔
328
}
329
PyObject* Series_str_remove_prefix(PyObject* self, PyObject* arg) {
4 ✔
330
    return str_arg_op<&Series::str_remove_prefix>(self, arg,
4 ✔
331
                                                  "str_remove_prefix");
2 ✔
332
}
333
PyObject* Series_str_remove_suffix(PyObject* self, PyObject* arg) {
4 ✔
334
    return str_arg_op<&Series::str_remove_suffix>(self, arg,
4 ✔
335
                                                  "str_remove_suffix");
2 ✔
336
}
337
PyObject* Series_str_findall(PyObject* self, PyObject* arg) {
12 ✔
338
    Series* a = as_series(self);
12 !
339
    if (!a) return nullptr;
12 ✔
340
    std::string_view pattern;
12 ✔
341
    if (!as_str_view(arg, &pattern)) return nullptr;
12 !
342
    Series out = a->str_findall(pattern);
12 !
343
    if (!out.valid()) {
12 ✔
344
        PyErr_SetString(PyExc_ValueError,
2 !
345
                        "str_findall: not a String column, or the pattern "
346
                        "does not compile");
347
        return nullptr;
2 ✔
348
    }
349
    return make_series(std::move(out));
10 !
350
}
12 ✔
351
PyObject* Series_list_join(PyObject* self, PyObject* arg) {
4 ✔
352
    Series* a = as_series(self);
4 !
353
    if (!a) return nullptr;
4 ✔
354
    std::string_view sep;
4 ✔
355
    if (!as_str_view(arg, &sep)) return nullptr;
4 !
356
    Series out = a->list_join(sep);
4 !
357
    if (!out.valid()) {
4 !
358
        PyErr_SetString(PyExc_TypeError,
×
359
                        "list_join: not a List column of strings");
360
        return nullptr;
×
361
    }
362
    return make_series(std::move(out));
4 !
363
}
4 ✔
364
PyObject* Series_str_repeat(PyObject* self, PyObject* arg) {
6 ✔
365
    Series* a = as_series(self);
6 !
366
    if (!a) return nullptr;
6 ✔
367
    const long long n = PyLong_AsLongLong(arg);
6 !
368
    if (n == -1 && PyErr_Occurred()) return nullptr;
6 !
369
    if (n < 0) {
6 ✔
370
        PyErr_SetString(PyExc_ValueError, "str_repeat: n must be >= 0");
×
371
        return nullptr;
×
372
    }
373
    Series out = a->str_repeat(static_cast<std::int64_t>(n));
6 !
374
    if (!out.valid()) {
6 !
375
        PyErr_SetString(PyExc_TypeError, "str_repeat: not a String column");
×
376
        return nullptr;
×
377
    }
378
    return make_series(std::move(out));
6 !
379
}
6 ✔
380
PyObject* Series_str_center(PyObject* self, PyObject* args, PyObject* kwds) {
10 ✔
381
    Series* a = as_series(self);
10 !
382
    if (!a) return nullptr;
10 ✔
383
    long long width = 0;
10 ✔
384
    PyObject* fill = nullptr;
10 ✔
385
    static const char* kwlist[] = {"width", "fill", nullptr};
386
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "L|O",
10 !
387
                                     const_cast<char**>(kwlist), &width, &fill))
388
        return nullptr;
×
389
    char f = ' ';
10 ✔
390
    if (fill && !as_fill_char(fill, &f)) return nullptr;
10 !
391
    Series out = a->str_center(static_cast<std::int64_t>(width), f);
10 !
392
    if (!out.valid()) {
10 !
393
        PyErr_SetString(PyExc_TypeError, "str_center: not a String column");
×
394
        return nullptr;
×
395
    }
396
    return make_series(std::move(out));
10 !
397
}
10 ✔
398
PyObject* Series_str_cat(PyObject* self, PyObject* other) {
26 ✔
399
    Series* a = as_series(self);
26 !
400
    if (!a) return nullptr;
26 ✔
401
    Series* b = as_series(other);
26 !
402
    if (!b) return nullptr;
26 ✔
403
    Series out = a->str_cat(*b);
26 !
404
    if (!out.valid()) {
26 !
405
        PyErr_SetString(PyExc_TypeError,
×
406
                        "str_cat: both must be String columns of one length");
407
        return nullptr;
×
408
    }
409
    return make_series(std::move(out));
26 !
410
}
26 ✔
411
PyObject* Series_str_partition(PyObject* self, PyObject* args, PyObject* kwds) {
18 ✔
412
    Series* a = as_series(self);
18 !
413
    if (!a) return nullptr;
18 ✔
414
    PyObject* sep_obj = nullptr;
18 ✔
415
    int from_right = 0;
18 ✔
416
    static const char* kwlist[] = {"sep", "from_right", nullptr};
417
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|p",
18 !
418
                                     const_cast<char**>(kwlist), &sep_obj,
419
                                     &from_right))
420
        return nullptr;
×
421
    std::string_view sep;
18 ✔
422
    if (!as_str_view(sep_obj, &sep)) return nullptr;
18 !
423
    if (sep.empty()) {
18 !
424
        PyErr_SetString(PyExc_ValueError, "str_partition: empty separator");
×
425
        return nullptr;
×
426
    }
427
    Series out = a->str_partition(sep, from_right != 0);
18 !
428
    if (!out.valid()) {
18 !
429
        PyErr_SetString(PyExc_TypeError, "str_partition: not a String column");
×
430
        return nullptr;
×
431
    }
432
    return make_series(std::move(out));
18 !
433
}
18 ✔
434
PyObject* Series_str_normalize(PyObject* self, PyObject* arg) {
8 ✔
435
    Series* a = as_series(self);
8 !
436
    if (!a) return nullptr;
8 ✔
437
    const long form = PyLong_AsLong(arg);
8 !
438
    if (form == -1 && PyErr_Occurred()) return nullptr;
8 !
439
    if (form < DFTU_NORM_NFC || form > DFTU_NORM_NFKD) {
8 !
NEW
440
        PyErr_SetString(PyExc_ValueError,
×
441
                        "str_normalize: form must be 0 (NFC) to 3 (NFKD)");
NEW
442
        return nullptr;
×
443
    }
444
    Series out = a->str_normalize(static_cast<std::int32_t>(form));
8 !
445
    if (!out.valid()) {
8 !
NEW
446
        PyErr_SetString(PyExc_TypeError, "str_normalize: not a String column");
×
NEW
447
        return nullptr;
×
448
    }
449
    return make_series(std::move(out));
8 !
450
}
8 ✔
451
PyObject* Series_str_translate(PyObject* self, PyObject* args) {
12 ✔
452
    Series* a = as_series(self);
12 !
453
    if (!a) return nullptr;
12 ✔
454
    PyObject* from_obj = nullptr;
12 ✔
455
    PyObject* to_obj = nullptr;
12 ✔
456
    if (!PyArg_ParseTuple(args, "OO", &from_obj, &to_obj)) return nullptr;
12 !
457
    Series* from = as_series(from_obj);
12 !
458
    if (!from) return nullptr;
12 ✔
459
    Series* to = as_series(to_obj);
12 !
460
    if (!to) return nullptr;
12 ✔
461
    Series out = a->str_translate(*from, *to);
12 !
462
    if (!out.valid()) {
12 !
NEW
463
        PyErr_SetString(PyExc_ValueError,
×
464
                        "str_translate: not a String column, or the table is "
465
                        "not one distinct codepoint per key");
NEW
466
        return nullptr;
×
467
    }
468
    return make_series(std::move(out));
12 !
469
}
12 ✔
NEW
470
PyObject* Series_str_wrap(PyObject* self, PyObject* args) {
×
NEW
471
    Series* a = as_series(self);
×
NEW
472
    if (!a) return nullptr;
×
NEW
473
    long long width = 0;
×
NEW
474
    int flags = 0;
×
NEW
475
    if (!PyArg_ParseTuple(args, "Li", &width, &flags)) return nullptr;
×
NEW
476
    if (width < 1) {
×
NEW
477
        PyErr_SetString(PyExc_ValueError, "str_wrap: width must be >= 1");
×
NEW
478
        return nullptr;
×
479
    }
NEW
480
    Series out = a->str_wrap(static_cast<std::int64_t>(width), flags);
×
NEW
481
    if (!out.valid()) {
×
NEW
482
        PyErr_SetString(PyExc_TypeError,
×
483
                        "str_wrap: not a String column, or bad flags");
NEW
484
        return nullptr;
×
485
    }
NEW
486
    return make_series(std::move(out));
×
NEW
487
}
×
488

489
PyObject* Series_dt_part(PyObject* self, PyObject* args) {
156 ✔
490
    Series* a = as_series(self);
156 !
491
    if (!a) return nullptr;
156 ✔
492
    int part = 0;
156 ✔
493
    int unit = DFTU_TIME_UNIT_MICRO;
156 ✔
494
    if (!PyArg_ParseTuple(args, "i|i", &part, &unit)) return nullptr;
156 !
495
    if (part < DFTU_DT_YEAR || part > DFTU_DT_EPOCH_DAYS) {
156 !
496
        PyErr_SetString(PyExc_ValueError, "dt_part: code must be 0..16");
2 !
497
        return nullptr;
2 ✔
498
    }
499
    if (unit < DFTU_TIME_UNIT_SECOND || unit > DFTU_TIME_UNIT_NANO) {
154 !
500
        PyErr_SetString(PyExc_ValueError, "dt_part: unit must be 0..3");
×
501
        return nullptr;
×
502
    }
503
    Series out = a->dt_part(part, unit);
154 !
504
    if (!out.valid()) {
154 ✔
505
        PyErr_SetString(PyExc_TypeError,
2 !
506
                        "dt_part: not a Timestamp, Date, Duration or Int64 "
507
                        "column");
508
        return nullptr;
2 ✔
509
    }
510
    return make_series(std::move(out));
152 !
511
}
155 ✔
512
PyObject* Series_dt_format(PyObject* self, PyObject* args) {
62 ✔
513
    Series* a = as_series(self);
62 !
514
    if (!a) return nullptr;
62 ✔
515
    PyObject* fmt_obj = nullptr;
62 ✔
516
    int unit = DFTU_TIME_UNIT_MICRO;
62 ✔
517
    if (!PyArg_ParseTuple(args, "O|i", &fmt_obj, &unit)) return nullptr;
62 !
518
    std::string_view fmt;
62 ✔
519
    if (!as_str_view(fmt_obj, &fmt)) return nullptr;
62 !
520
    if (unit < DFTU_TIME_UNIT_SECOND || unit > DFTU_TIME_UNIT_NANO) {
62 !
521
        PyErr_SetString(PyExc_ValueError, "dt_format: unit must be 0..3");
2 !
522
        return nullptr;
2 ✔
523
    }
524
    Series out = a->dt_format(fmt, static_cast<dataframe::TimeUnit>(unit));
60 !
525
    if (!out.valid()) {
60 ✔
526
        std::string msg = "dt_format: invalid format '" + std::string(fmt) +
6 !
527
                          "' or not a Timestamp, Date or Int64 column";
2 !
528
        PyErr_SetString(PyExc_ValueError, msg.c_str());
4 !
529
        return nullptr;
4 ✔
530
    }
4 ✔
531
    return make_series(std::move(out));
56 !
532
}
61 ✔
533
PyObject* Series_dt_round(PyObject* self, PyObject* args) {
48 ✔
534
    Series* a = as_series(self);
48 !
535
    if (!a) return nullptr;
48 ✔
536
    long long every = 0;
48 ✔
537
    int mode = 0;
48 ✔
538
    if (!PyArg_ParseTuple(args, "Li", &every, &mode)) return nullptr;
48 !
539
    if (every <= 0) {
48 !
540
        PyErr_SetString(PyExc_ValueError, "dt_round: every must be positive");
×
541
        return nullptr;
×
542
    }
543
    if (mode < DFTU_DT_FLOOR || mode > DFTU_DT_ROUND) {
48 !
544
        PyErr_SetString(PyExc_ValueError,
×
545
                        "dt_round: mode must be 0 (floor), 1 (ceil) or 2 "
546
                        "(round)");
547
        return nullptr;
×
548
    }
549
    Series out = a->dt_round(static_cast<std::int64_t>(every), mode);
48 !
550
    if (!out.valid()) {
48 ✔
551
        PyErr_SetString(PyExc_TypeError,
2 !
552
                        "dt_round: not a Timestamp, Duration or Int64 column");
553
        return nullptr;
2 ✔
554
    }
555
    return make_series(std::move(out));
46 !
556
}
48 ✔
557

558
PyObject* Series_with_timezone(PyObject* self, PyObject* arg) {
18 ✔
559
    Series* a = as_series(self);
18 !
560
    if (!a) return nullptr;
18 ✔
561
    std::string_view tz;
18 ✔
562
    if (!as_str_view(arg, &tz)) return nullptr;
18 !
563
    Series out = a->with_timezone(tz);
18 !
564
    if (!out.valid()) {
18 ✔
565
        PyErr_SetString(PyExc_TypeError,
2 !
566
                        "with_timezone: not a Timestamp column");
567
        return nullptr;
2 ✔
568
    }
569
    return make_series(std::move(out));
16 !
570
}
18 ✔
571

572
}  // namespace dftracer::utils::python::series_detail
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