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

Function busdaycalendar_init

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

Source from the content-addressed store, hash-verified

370}
371
372static int
373busdaycalendar_init(NpyBusDayCalendar *self, PyObject *args, PyObject *kwds)
374{
375 static char *kwlist[] = {"weekmask", "holidays", NULL};
376 int i, busdays_in_weekmask;
377
378 /* Clear the holidays if necessary */
379 if (self->holidays.begin != NULL) {
380 PyArray_free(self->holidays.begin);
381 self->holidays.begin = NULL;
382 self->holidays.end = NULL;
383 }
384
385 /* Reset the weekmask to the default */
386 self->busdays_in_weekmask = 5;
387 self->weekmask[0] = 1;
388 self->weekmask[1] = 1;
389 self->weekmask[2] = 1;
390 self->weekmask[3] = 1;
391 self->weekmask[4] = 1;
392 self->weekmask[5] = 0;
393 self->weekmask[6] = 0;
394
395 /* Parse the parameters */
396 if (!PyArg_ParseTupleAndKeywords(args, kwds,
397 "|O&O&:busdaycal", kwlist,
398 &PyArray_WeekMaskConverter, &self->weekmask[0],
399 &PyArray_HolidaysConverter, &self->holidays)) {
400 return -1;
401 }
402
403 /* Count the number of business days in a week */
404 busdays_in_weekmask = 0;
405 for (i = 0; i < 7; ++i) {
406 busdays_in_weekmask += self->weekmask[i];
407 }
408 self->busdays_in_weekmask = busdays_in_weekmask;
409
410 /* Normalize the holidays list */
411 normalize_holidays_list(&self->holidays, self->weekmask);
412
413 if (self->busdays_in_weekmask == 0) {
414 PyErr_SetString(PyExc_ValueError,
415 "Cannot construct a numpy.busdaycal with a weekmask of "
416 "all zeros");
417 return -1;
418 }
419
420 return 0;
421}
422
423static void
424busdaycalendar_dealloc(NpyBusDayCalendar *self)

Callers

nothing calls this directly

Calls 1

normalize_holidays_listFunction · 0.85

Tested by

no test coverage detected