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

Function is_business_day

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

* Returns a boolean array with True for input dates which are valid * business days, and False for dates which are not. This is the * low-level function which requires already cleaned input data. * * dates: An array of dates with 'datetime64[D]' data type. * out: Either NULL, or an array with 'bool' data type * in which to place the resulting dates. * weekmask: A 7-elemen

Source from the content-addressed store, hash-verified

726 * week without weekmask[i] == 1 already filtered out.
727 */
728NPY_NO_EXPORT PyArrayObject *
729is_business_day(PyArrayObject *dates, PyArrayObject *out,
730 const npy_bool *weekmask, int busdays_in_weekmask,
731 npy_datetime *holidays_begin, npy_datetime *holidays_end)
732{
733 PyArray_DatetimeMetaData temp_meta;
734 PyArray_Descr *dtypes[2] = {NULL, NULL};
735
736 NpyIter *iter = NULL;
737 PyArrayObject *op[2] = {NULL, NULL};
738 npy_uint32 op_flags[2], flags;
739
740 PyArrayObject *ret = NULL;
741
742 if (busdays_in_weekmask == 0) {
743 PyErr_SetString(PyExc_ValueError,
744 "the business day weekmask must have at least one "
745 "valid business day");
746 return NULL;
747 }
748
749 /* First create the data types for the dates and the bool output */
750 temp_meta.base = NPY_FR_D;
751 temp_meta.num = 1;
752 dtypes[0] = create_datetime_dtype(NPY_DATETIME, &temp_meta);
753 if (dtypes[0] == NULL) {
754 goto fail;
755 }
756 dtypes[1] = PyArray_DescrFromType(NPY_BOOL);
757 if (dtypes[1] == NULL) {
758 goto fail;
759 }
760
761 /* Set up the iterator parameters */
762 flags = NPY_ITER_EXTERNAL_LOOP|
763 NPY_ITER_BUFFERED|
764 NPY_ITER_ZEROSIZE_OK;
765 op[0] = dates;
766 op_flags[0] = NPY_ITER_READONLY | NPY_ITER_ALIGNED;
767 op[1] = out;
768 op_flags[1] = NPY_ITER_WRITEONLY | NPY_ITER_ALLOCATE | NPY_ITER_ALIGNED;
769
770 /* Allocate the iterator */
771 iter = NpyIter_MultiNew(2, op, flags, NPY_KEEPORDER, NPY_SAFE_CASTING,
772 op_flags, dtypes);
773 if (iter == NULL) {
774 goto fail;
775 }
776
777 /* Loop over all elements */
778 if (NpyIter_GetIterSize(iter) > 0) {
779 NpyIter_IterNextFunc *iternext;
780 char **dataptr;
781 npy_intp *strideptr, *innersizeptr;
782
783 iternext = NpyIter_GetIterNext(iter, NULL);
784 if (iternext == NULL) {
785 goto fail;

Callers 1

array_is_busdayFunction · 0.85

Calls 10

create_datetime_dtypeFunction · 0.85
NpyIter_MultiNewFunction · 0.85
NpyIter_GetIterSizeFunction · 0.85
NpyIter_GetDataPtrArrayFunction · 0.85
get_day_of_weekFunction · 0.85
is_holidayFunction · 0.85
NpyIter_GetOperandArrayFunction · 0.85
NpyIter_DeallocateFunction · 0.85

Tested by

no test coverage detected