Skip to content

Commit 2746013

Browse files
WarrenWeckessersabasiddique1
authored andcommitted
BUG: Fix busdaycalendar's handling of a bool array weekmask. (numpy#30885)
1 parent 342c9e8 commit 2746013

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

numpy/_core/src/multiarray/datetime_busdaycal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ PyArray_WeekMaskConverter(PyObject *weekmask_in, npy_bool *weekmask)
159159
int i;
160160

161161
for (i = 0; i < 7; ++i) {
162-
long val;
162+
int val;
163163
PyObject *f = PySequence_GetItem(obj, i);
164164
if (f == NULL) {
165165
Py_DECREF(obj);
166166
return 0;
167167
}
168168

169-
val = PyLong_AsLong(f);
170-
if (error_converting(val)) {
169+
val = PyObject_IsTrue(f);
170+
if (val == -1) {
171171
Py_DECREF(f);
172172
Py_DECREF(obj);
173173
return 0;

numpy/_core/tests/test_datetime.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,11 @@ def test_datetime_busdaycalendar(self):
22202220
bdd = np.busdaycalendar(weekmask="0011001")
22212221
assert_equal(bdd.weekmask, np.array([0, 0, 1, 1, 0, 0, 1], dtype='?'))
22222222

2223+
# Check length 7 bool array.
2224+
mask = np.array([False, True, True, True, True, False, False])
2225+
bdd = np.busdaycalendar(weekmask=mask)
2226+
assert_equal(bdd.weekmask, mask, strict=True)
2227+
22232228
# Check length 7 string weekmask.
22242229
bdd = np.busdaycalendar(weekmask="Mon Tue")
22252230
assert_equal(bdd.weekmask, np.array([1, 1, 0, 0, 0, 0, 0], dtype='?'))

0 commit comments

Comments
 (0)