• 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

64.92
/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) {
211 ✔
13
    Py_ssize_t len = 0;
211 ✔
14
    const char* data = PyUnicode_AsUTF8AndSize(arg, &len);
211 !
15
    if (!data) return false;
211 !
16
    *out = std::string_view(data, static_cast<std::size_t>(len));
211 ✔
17
    return true;
211 ✔
18
}
19

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

32
}  // namespace
33

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

285
}  // namespace
286

287
PyObject* Series_str_case(PyObject* self, PyObject* arg) {
25 ✔
288
    Series* a = as_series(self);
25 !
289
    if (!a) return nullptr;
25 !
290
    const long code = PyLong_AsLong(arg);
25 !
291
    if (code == -1 && PyErr_Occurred()) return nullptr;
25 !
292
    if (code < DFTU_STR_CAPITALIZE || code > DFTU_STR_SWAPCASE) {
25 !
293
        PyErr_SetString(PyExc_ValueError,
1 !
294
                        "str_case: code must be 0 (capitalize), 1 (title) "
295
                        "or 2 (swapcase)");
296
        return nullptr;
1 ✔
297
    }
298
    Series out = a->str_case(static_cast<std::int32_t>(code));
24 !
299
    if (!out.valid()) {
24 !
300
        PyErr_SetString(PyExc_TypeError, "str_case: not a String column");
×
301
        return nullptr;
×
302
    }
303
    return make_series(std::move(out));
24 !
304
}
24 ✔
305
PyObject* Series_str_is(PyObject* self, PyObject* arg) {
22 ✔
306
    Series* a = as_series(self);
22 !
307
    if (!a) return nullptr;
22 !
308
    const long code = PyLong_AsLong(arg);
22 !
309
    if (code == -1 && PyErr_Occurred()) return nullptr;
22 !
310
    if (code < DFTU_STR_ALNUM || code > DFTU_STR_TITLE) {
22 !
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));
22 !
317
    if (!out.valid()) {
22 !
318
        PyErr_SetString(PyExc_TypeError, "str_is: not a String column");
×
319
        return nullptr;
×
320
    }
321
    return make_series(std::move(out));
22 !
322
}
22 ✔
323
PyObject* Series_str_count(PyObject* self, PyObject* arg) {
3 ✔
324
    return str_arg_op<&Series::str_count>(self, arg, "str_count");
3 ✔
325
}
326
PyObject* Series_str_rfind(PyObject* self, PyObject* arg) {
4 ✔
327
    return str_arg_op<&Series::str_rfind>(self, arg, "str_rfind");
4 ✔
328
}
329
PyObject* Series_str_remove_prefix(PyObject* self, PyObject* arg) {
2 ✔
330
    return str_arg_op<&Series::str_remove_prefix>(self, arg,
2 ✔
331
                                                  "str_remove_prefix");
2 ✔
332
}
333
PyObject* Series_str_remove_suffix(PyObject* self, PyObject* arg) {
2 ✔
334
    return str_arg_op<&Series::str_remove_suffix>(self, arg,
2 ✔
335
                                                  "str_remove_suffix");
2 ✔
336
}
337
PyObject* Series_str_findall(PyObject* self, PyObject* arg) {
3 ✔
338
    Series* a = as_series(self);
3 !
339
    if (!a) return nullptr;
3 !
340
    std::string_view pattern;
3 ✔
341
    if (!as_str_view(arg, &pattern)) return nullptr;
3 !
342
    Series out = a->str_findall(pattern);
3 !
343
    if (!out.valid()) {
3 ✔
344
        PyErr_SetString(PyExc_ValueError,
1 !
345
                        "str_findall: not a String column, or the pattern "
346
                        "does not compile");
347
        return nullptr;
1 ✔
348
    }
349
    return make_series(std::move(out));
2 !
350
}
3 ✔
351
PyObject* Series_list_join(PyObject* self, PyObject* arg) {
2 ✔
352
    Series* a = as_series(self);
2 !
353
    if (!a) return nullptr;
2 !
354
    std::string_view sep;
2 ✔
355
    if (!as_str_view(arg, &sep)) return nullptr;
2 !
356
    Series out = a->list_join(sep);
2 !
357
    if (!out.valid()) {
2 !
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));
2 !
363
}
2 ✔
364
PyObject* Series_str_repeat(PyObject* self, PyObject* arg) {
3 ✔
365
    Series* a = as_series(self);
3 !
366
    if (!a) return nullptr;
3 !
367
    const long long n = PyLong_AsLongLong(arg);
3 !
368
    if (n == -1 && PyErr_Occurred()) return nullptr;
3 !
369
    if (n < 0) {
3 !
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));
3 !
374
    if (!out.valid()) {
3 !
375
        PyErr_SetString(PyExc_TypeError, "str_repeat: not a String column");
×
376
        return nullptr;
×
377
    }
378
    return make_series(std::move(out));
3 !
379
}
3 ✔
380
PyObject* Series_str_center(PyObject* self, PyObject* args, PyObject* kwds) {
5 ✔
381
    Series* a = as_series(self);
5 !
382
    if (!a) return nullptr;
5 !
383
    long long width = 0;
5 ✔
384
    PyObject* fill = nullptr;
5 ✔
385
    static const char* kwlist[] = {"width", "fill", nullptr};
386
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "L|O",
5 !
387
                                     const_cast<char**>(kwlist), &width, &fill))
388
        return nullptr;
×
389
    char f = ' ';
5 ✔
390
    if (fill && !as_fill_char(fill, &f)) return nullptr;
5 !
391
    Series out = a->str_center(static_cast<std::int64_t>(width), f);
5 !
392
    if (!out.valid()) {
5 !
393
        PyErr_SetString(PyExc_TypeError, "str_center: not a String column");
×
394
        return nullptr;
×
395
    }
396
    return make_series(std::move(out));
5 !
397
}
5 ✔
398
PyObject* Series_str_cat(PyObject* self, PyObject* other) {
13 ✔
399
    Series* a = as_series(self);
13 !
400
    if (!a) return nullptr;
13 !
401
    Series* b = as_series(other);
13 !
402
    if (!b) return nullptr;
13 !
403
    Series out = a->str_cat(*b);
13 !
404
    if (!out.valid()) {
13 !
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));
13 !
410
}
13 ✔
411
PyObject* Series_str_partition(PyObject* self, PyObject* args, PyObject* kwds) {
9 ✔
412
    Series* a = as_series(self);
9 !
413
    if (!a) return nullptr;
9 !
414
    PyObject* sep_obj = nullptr;
9 ✔
415
    int from_right = 0;
9 ✔
416
    static const char* kwlist[] = {"sep", "from_right", nullptr};
417
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|p",
9 !
418
                                     const_cast<char**>(kwlist), &sep_obj,
419
                                     &from_right))
420
        return nullptr;
×
421
    std::string_view sep;
9 ✔
422
    if (!as_str_view(sep_obj, &sep)) return nullptr;
9 !
423
    if (sep.empty()) {
9 !
424
        PyErr_SetString(PyExc_ValueError, "str_partition: empty separator");
×
425
        return nullptr;
×
426
    }
427
    Series out = a->str_partition(sep, from_right != 0);
9 !
428
    if (!out.valid()) {
9 !
429
        PyErr_SetString(PyExc_TypeError, "str_partition: not a String column");
×
430
        return nullptr;
×
431
    }
432
    return make_series(std::move(out));
9 !
433
}
9 ✔
434

435
PyObject* Series_dt_part(PyObject* self, PyObject* args) {
78 ✔
436
    Series* a = as_series(self);
78 !
437
    if (!a) return nullptr;
78 !
438
    int part = 0;
78 ✔
439
    int unit = DFTU_TIME_UNIT_MICRO;
78 ✔
440
    if (!PyArg_ParseTuple(args, "i|i", &part, &unit)) return nullptr;
78 !
441
    if (part < DFTU_DT_YEAR || part > DFTU_DT_EPOCH_DAYS) {
78 !
442
        PyErr_SetString(PyExc_ValueError, "dt_part: code must be 0..16");
1 !
443
        return nullptr;
1 ✔
444
    }
445
    if (unit < DFTU_TIME_UNIT_SECOND || unit > DFTU_TIME_UNIT_NANO) {
77 !
446
        PyErr_SetString(PyExc_ValueError, "dt_part: unit must be 0..3");
×
447
        return nullptr;
×
448
    }
449
    Series out = a->dt_part(part, unit);
77 !
450
    if (!out.valid()) {
77 ✔
451
        PyErr_SetString(PyExc_TypeError,
1 !
452
                        "dt_part: not a Timestamp, Date, Duration or Int64 "
453
                        "column");
454
        return nullptr;
1 ✔
455
    }
456
    return make_series(std::move(out));
76 !
457
}
77 ✔
458
PyObject* Series_dt_format(PyObject* self, PyObject* args) {
31 ✔
459
    Series* a = as_series(self);
31 !
460
    if (!a) return nullptr;
31 !
461
    PyObject* fmt_obj = nullptr;
31 ✔
462
    int unit = DFTU_TIME_UNIT_MICRO;
31 ✔
463
    if (!PyArg_ParseTuple(args, "O|i", &fmt_obj, &unit)) return nullptr;
31 !
464
    std::string_view fmt;
31 ✔
465
    if (!as_str_view(fmt_obj, &fmt)) return nullptr;
31 !
466
    if (unit < DFTU_TIME_UNIT_SECOND || unit > DFTU_TIME_UNIT_NANO) {
31 !
467
        PyErr_SetString(PyExc_ValueError, "dt_format: unit must be 0..3");
1 !
468
        return nullptr;
1 ✔
469
    }
470
    Series out = a->dt_format(fmt, static_cast<dataframe::TimeUnit>(unit));
30 !
471
    if (!out.valid()) {
30 ✔
472
        std::string msg = "dt_format: invalid format '" + std::string(fmt) +
4 !
473
                          "' or not a Timestamp, Date or Int64 column";
2 !
474
        PyErr_SetString(PyExc_ValueError, msg.c_str());
2 !
475
        return nullptr;
2 ✔
476
    }
2 ✔
477
    return make_series(std::move(out));
28 !
478
}
30 ✔
479
PyObject* Series_dt_round(PyObject* self, PyObject* args) {
24 ✔
480
    Series* a = as_series(self);
24 !
481
    if (!a) return nullptr;
24 !
482
    long long every = 0;
24 ✔
483
    int mode = 0;
24 ✔
484
    if (!PyArg_ParseTuple(args, "Li", &every, &mode)) return nullptr;
24 !
485
    if (every <= 0) {
24 !
486
        PyErr_SetString(PyExc_ValueError, "dt_round: every must be positive");
×
487
        return nullptr;
×
488
    }
489
    if (mode < DFTU_DT_FLOOR || mode > DFTU_DT_ROUND) {
24 !
490
        PyErr_SetString(PyExc_ValueError,
×
491
                        "dt_round: mode must be 0 (floor), 1 (ceil) or 2 "
492
                        "(round)");
493
        return nullptr;
×
494
    }
495
    Series out = a->dt_round(static_cast<std::int64_t>(every), mode);
24 !
496
    if (!out.valid()) {
24 ✔
497
        PyErr_SetString(PyExc_TypeError,
1 !
498
                        "dt_round: not a Timestamp, Duration or Int64 column");
499
        return nullptr;
1 ✔
500
    }
501
    return make_series(std::move(out));
23 !
502
}
24 ✔
503

504
PyObject* Series_with_timezone(PyObject* self, PyObject* arg) {
9 ✔
505
    Series* a = as_series(self);
9 !
506
    if (!a) return nullptr;
9 !
507
    std::string_view tz;
9 ✔
508
    if (!as_str_view(arg, &tz)) return nullptr;
9 !
509
    Series out = a->with_timezone(tz);
9 !
510
    if (!out.valid()) {
9 ✔
511
        PyErr_SetString(PyExc_TypeError,
1 !
512
                        "with_timezone: not a Timestamp column");
513
        return nullptr;
1 ✔
514
    }
515
    return make_series(std::move(out));
8 !
516
}
9 ✔
517

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