Skip to content

BUG: Fix busdaycalendar's handling of a bool array weekmask.#30885

Merged
ngoldbaum merged 1 commit intonumpy:mainfrom
WarrenWeckesser:busdaycal-bool-weekmask
Feb 27, 2026
Merged

BUG: Fix busdaycalendar's handling of a bool array weekmask.#30885
ngoldbaum merged 1 commit intonumpy:mainfrom
WarrenWeckesser:busdaycal-bool-weekmask

Conversation

@WarrenWeckesser
Copy link
Copy Markdown
Member

Closes gh-30883.

This change is simple but it has implications beyond the problem observed in gh-30883. With this change, when weekmask is a sequence, the boolean array is created by evaluating the "truthiness" of the elements in the sequence. This might be more flexible than desired.

For example, with this PR, we have the following behavior:

In [1]: mask = ["x", "x", "x", "x", "", "", ""]

In [2]: cal = np.busdaycalendar(weekmask=mask)

In [3]: cal.weekmask
Out[3]: array([ True,  True,  True,  True, False, False, False])

Before this change, that sequence of strings would result in a TypeError:

In [13]: np.__version__
Out[13]: '2.4.2'

In [14]: mask = ["x", "x", "x", "x", "", "", ""]

In [15]: cal = np.busdaycalendar(weekmask=mask)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[15], line 1
----> 1 cal = np.busdaycalendar(weekmask=mask)

TypeError: 'str' object cannot be interpreted as an integer

Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Warren! I can't of a nice way to allow this but remove teh caveat so the caveat seems OK to me.
(Converting to a NumPy bool might work, but doesn't reall seem worth it here. Doesn't mean I have any confidence that this functionality should be used, hehe ;).)

(It's a tricky world, with our bools not being integer subclasses, unlike Python bools.)

@ngoldbaum
Copy link
Copy Markdown
Member

Thanks @WarrenWeckesser!

@ngoldbaum ngoldbaum merged commit de9a2be into numpy:main Feb 27, 2026
79 checks passed
@WarrenWeckesser WarrenWeckesser deleted the busdaycal-bool-weekmask branch February 27, 2026 19:38
@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Feb 28, 2026
charris pushed a commit to charris/numpy that referenced this pull request Mar 4, 2026
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Mar 4, 2026
charris added a commit that referenced this pull request Mar 4, 2026
BUG: Fix busdaycalendar's handling of a bool array weekmask. (#30885)
sabasiddique1 pushed a commit to sabasiddique1/numpy that referenced this pull request Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: weekmask parameter in busdaycalendar is not accepting array of booleans .

4 participants