MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_WeekMaskConverter

Function PyArray_WeekMaskConverter

numpy/core/src/multiarray/datetime_busdaycal.c:28–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26#include "datetime_busdaycal.h"
27
28NPY_NO_EXPORT int
29PyArray_WeekMaskConverter(PyObject *weekmask_in, npy_bool *weekmask)
30{
31 PyObject *obj = weekmask_in;
32
33 /* Make obj into an UTF8 string */
34 if (PyBytes_Check(obj)) {
35 /* accept bytes input */
36 PyObject *obj_str = PyUnicode_FromEncodedObject(obj, NULL, NULL);
37 if (obj_str == NULL) {
38 return 0;
39 }
40 obj = obj_str;
41 }
42 else {
43 Py_INCREF(obj);
44 }
45
46
47 if (PyUnicode_Check(obj)) {
48 Py_ssize_t len;
49 char const *str = PyUnicode_AsUTF8AndSize(obj, &len);
50 if (str == NULL) {
51 Py_DECREF(obj);
52 return 0;
53 }
54
55 /* Length 7 is a string like "1111100" */
56 if (len == 7) {
57 for (int i = 0; i < 7; ++i) {
58 switch(str[i]) {
59 case '0':
60 weekmask[i] = 0;
61 break;
62 case '1':
63 weekmask[i] = 1;
64 break;
65 default:
66 goto general_weekmask_string;
67 }
68 }
69
70 goto finish;
71 }
72
73general_weekmask_string:
74 /* a string like "SatSun" or "Mon Tue Wed" */
75 memset(weekmask, 0, 7);
76 for (Py_ssize_t i = 0; i < len; i += 3) {
77 while (isspace(str[i]))
78 ++i;
79
80 if (i == len) {
81 goto finish;
82 }
83 else if (i + 2 >= len) {
84 goto invalid_weekmask_string;
85 }

Callers

nothing calls this directly

Calls 2

isspaceFunction · 0.85
PyArray_NDIMFunction · 0.85

Tested by

no test coverage detected