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

Function array_busday_count

numpy/core/src/multiarray/datetime_busday.c:1069–1208  ·  view source on GitHub ↗

* This is the 'busday_count' function exposed for calling * from Python. */

Source from the content-addressed store, hash-verified

1067 * from Python.
1068 */
1069NPY_NO_EXPORT PyObject *
1070array_busday_count(PyObject *NPY_UNUSED(self),
1071 PyObject *args, PyObject *kwds)
1072{
1073 static char *kwlist[] = {"begindates", "enddates",
1074 "weekmask", "holidays", "busdaycal", "out", NULL};
1075
1076 PyObject *dates_begin_in = NULL, *dates_end_in = NULL, *out_in = NULL;
1077
1078 PyArrayObject *dates_begin = NULL, *dates_end = NULL, *out = NULL, *ret;
1079 npy_bool weekmask[7] = {2, 1, 1, 1, 1, 0, 0};
1080 NpyBusDayCalendar *busdaycal = NULL;
1081 int i, busdays_in_weekmask;
1082 npy_holidayslist holidays = {NULL, NULL};
1083 int allocated_holidays = 1;
1084
1085 if (!PyArg_ParseTupleAndKeywords(args, kwds,
1086 "OO|O&O&O!O:busday_count", kwlist,
1087 &dates_begin_in,
1088 &dates_end_in,
1089 &PyArray_WeekMaskConverter, &weekmask[0],
1090 &PyArray_HolidaysConverter, &holidays,
1091 &NpyBusDayCalendar_Type, &busdaycal,
1092 &out_in)) {
1093 goto fail;
1094 }
1095
1096 /* Make sure only one of the weekmask/holidays and busdaycal is supplied */
1097 if (busdaycal != NULL) {
1098 if (weekmask[0] != 2 || holidays.begin != NULL) {
1099 PyErr_SetString(PyExc_ValueError,
1100 "Cannot supply both the weekmask/holidays and the "
1101 "busdaycal parameters to busday_count()");
1102 goto fail;
1103 }
1104
1105 /* Indicate that the holidays weren't allocated by us */
1106 allocated_holidays = 0;
1107
1108 /* Copy the private normalized weekmask/holidays data */
1109 holidays = busdaycal->holidays;
1110 busdays_in_weekmask = busdaycal->busdays_in_weekmask;
1111 memcpy(weekmask, busdaycal->weekmask, 7);
1112 }
1113 else {
1114 /*
1115 * Fix up the weekmask from the uninitialized
1116 * signal value to a proper default.
1117 */
1118 if (weekmask[0] == 2) {
1119 weekmask[0] = 1;
1120 }
1121
1122 /* Count the number of business days in a week */
1123 busdays_in_weekmask = 0;
1124 for (i = 0; i < 7; ++i) {
1125 busdays_in_weekmask += weekmask[i];
1126 }

Callers

nothing calls this directly

Calls 4

normalize_holidays_listFunction · 0.85
PyArray_FromAnyFunction · 0.85
business_day_countFunction · 0.85
PyArray_ReturnFunction · 0.85

Tested by

no test coverage detected