diff options
author | Alok Singhal <gandalf013@gmail.com> | 2011-07-16 11:08:41 -0500 |
---|---|---|
committer | Mark Wiebe <mwiebe@enthought.com> | 2011-07-19 15:36:28 -0500 |
commit | bd77886d6ebab0939e1515b899fa0e0a174268b6 (patch) | |
tree | 35490ec85761ad4ca77db7694983d1d87e7c4bae /numpy | |
parent | d6c3b44b6645a02754c0acff70b35131a01353dd (diff) | |
download | numpy-bd77886d6ebab0939e1515b899fa0e0a174268b6.tar.gz |
ENH: datetime: make np.busday_count return negative values when the start date is after end date
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/datetime_busday.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/datetime_busday.c b/numpy/core/src/multiarray/datetime_busday.c index 7ad033248..5a0078b76 100644 --- a/numpy/core/src/multiarray/datetime_busday.c +++ b/numpy/core/src/multiarray/datetime_busday.c @@ -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) { @@ -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, @@ -411,6 +418,10 @@ apply_business_day_count(npy_datetime date_begin, npy_datetime date_end, } } + if (swapped) { + count = -count; + } + *out = count; return 0; } @@ -563,6 +574,9 @@ finish: * 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 |