* This is the 'is_busday' function exposed for calling * from Python. */
| 1212 | * from Python. |
| 1213 | */ |
| 1214 | NPY_NO_EXPORT PyObject * |
| 1215 | array_is_busday(PyObject *NPY_UNUSED(self), |
| 1216 | PyObject *args, PyObject *kwds) |
| 1217 | { |
| 1218 | static char *kwlist[] = {"dates", |
| 1219 | "weekmask", "holidays", "busdaycal", "out", NULL}; |
| 1220 | |
| 1221 | PyObject *dates_in = NULL, *out_in = NULL; |
| 1222 | |
| 1223 | PyArrayObject *dates = NULL,*out = NULL, *ret; |
| 1224 | npy_bool weekmask[7] = {2, 1, 1, 1, 1, 0, 0}; |
| 1225 | NpyBusDayCalendar *busdaycal = NULL; |
| 1226 | int i, busdays_in_weekmask; |
| 1227 | npy_holidayslist holidays = {NULL, NULL}; |
| 1228 | int allocated_holidays = 1; |
| 1229 | |
| 1230 | if (!PyArg_ParseTupleAndKeywords(args, kwds, |
| 1231 | "O|O&O&O!O:is_busday", kwlist, |
| 1232 | &dates_in, |
| 1233 | &PyArray_WeekMaskConverter, &weekmask[0], |
| 1234 | &PyArray_HolidaysConverter, &holidays, |
| 1235 | &NpyBusDayCalendar_Type, &busdaycal, |
| 1236 | &out_in)) { |
| 1237 | goto fail; |
| 1238 | } |
| 1239 | |
| 1240 | /* Make sure only one of the weekmask/holidays and busdaycal is supplied */ |
| 1241 | if (busdaycal != NULL) { |
| 1242 | if (weekmask[0] != 2 || holidays.begin != NULL) { |
| 1243 | PyErr_SetString(PyExc_ValueError, |
| 1244 | "Cannot supply both the weekmask/holidays and the " |
| 1245 | "busdaycal parameters to is_busday()"); |
| 1246 | goto fail; |
| 1247 | } |
| 1248 | |
| 1249 | /* Indicate that the holidays weren't allocated by us */ |
| 1250 | allocated_holidays = 0; |
| 1251 | |
| 1252 | /* Copy the private normalized weekmask/holidays data */ |
| 1253 | holidays = busdaycal->holidays; |
| 1254 | busdays_in_weekmask = busdaycal->busdays_in_weekmask; |
| 1255 | memcpy(weekmask, busdaycal->weekmask, 7); |
| 1256 | } |
| 1257 | else { |
| 1258 | /* |
| 1259 | * Fix up the weekmask from the uninitialized |
| 1260 | * signal value to a proper default. |
| 1261 | */ |
| 1262 | if (weekmask[0] == 2) { |
| 1263 | weekmask[0] = 1; |
| 1264 | } |
| 1265 | |
| 1266 | /* Count the number of business days in a week */ |
| 1267 | busdays_in_weekmask = 0; |
| 1268 | for (i = 0; i < 7; ++i) { |
| 1269 | busdays_in_weekmask += weekmask[i]; |
| 1270 | } |
| 1271 |
nothing calls this directly
no test coverage detected