Businessday make np.busday_count return negative values when the start date is after end date by gandalf013 · Pull Request #117 · numpy/numpy

Expand Up @@ -365,6 +365,7 @@ apply_business_day_count(npy_datetime date_begin, npy_datetime date_end, { npy_int64 count, whole_weeks; int day_of_week = 0; int swapped = 0;
/* If we get a NaT, raise an error */ if (date_begin == NPY_DATETIME_NAT || date_end == NPY_DATETIME_NAT) { Expand All @@ -375,10 +376,16 @@ apply_business_day_count(npy_datetime date_begin, npy_datetime date_end, }
/* Trivial empty date range */ if (date_begin >= date_end) { if (date_begin == date_end) { *out = 0; return 0; } else if (date_begin > date_end) { npy_datetime tmp = date_begin; date_begin = date_end; date_end = tmp; swapped = 1; }
/* Remove any earlier holidays */ holidays_begin = find_earliest_holiday_on_or_after(date_begin, Expand Down Expand Up @@ -411,6 +418,10 @@ apply_business_day_count(npy_datetime date_begin, npy_datetime date_end, } }
if (swapped) { count = -count; }
*out = count; return 0; } Expand Down Expand Up @@ -563,6 +574,9 @@ business_day_offset(PyArrayObject *dates, PyArrayObject *offsets, * the end date. This is the low-level function which requires already * cleaned input data. * * If dates_begin is before dates_end, the result is positive. If * dates_begin is after dates_end, it is negative. * * dates_begin: An array of dates with 'datetime64[D]' data type. * dates_end: An array of dates with 'datetime64[D]' data type. * out: Either NULL, or an array with 'int64' data type Expand Down