Skip to content

Conversation

@cibarbia05
Copy link
Contributor

Closes #29651

This PR fixes an issue where np.setbufsize silently accepted negative
values. Passing a negative value now raises a ValueError with a clear
error message.

Changes

  • Added a check in np.setbufsize to raise ValueError when size < 0.
  • Added a new unit test test_negative_value_raises in
    numpy/_core/tests/test_umath.py.

Example

>>> import numpy as np
>>> np.setbufsize(-5)
Traceback (most recent call last):
    ...
ValueError: buffer size must be non-negative

np.setbufsize previously accepted negative values silently.
This commit adds input validation so that a ValueError is raised
when a negative buffer size is provided, and adds a regression test
to cover this behavior.

Closes numpy#29651
@mattip
Copy link
Member

mattip commented Sep 21, 2025

Something broke the build. I am seeing this in various CI steps that re-use the meson build to run other spin steps

Invoking `build` prior to running tests:
$ /opt/hostedtoolcache/Python/3.11.13/x64/bin/python vendored-meson/meson/meson.py compile -j Sentinel.UNSET -C build

Where is this Sentinel.UNSET coming from? There is a click problem I see elsewhere, something about sentinel values, did we not pin the click version in the requirements?

@WarrenWeckesser
Copy link
Member

WarrenWeckesser commented Sep 21, 2025

The corresponding scipy issue is scipy/scipy#23642.

A solution would be to ensure that spin 0.15 is used. (click is a transitive dependency coming from spin.)

@charris
Copy link
Member

charris commented Sep 21, 2025

close/reopen

@charris charris closed this Sep 21, 2025
@charris charris reopened this Sep 21, 2025
@mattip mattip merged commit 435c2cd into numpy:main Sep 22, 2025
77 checks passed
@mattip
Copy link
Member

mattip commented Sep 22, 2025

Thanks @cibarbia05

@cibarbia05
Copy link
Contributor Author

Thanks @cibarbia05

Thanks for the review and merge! Glad to contribute.

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Sep 22, 2025
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Sep 23, 2025
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.

np.setbufsize accepts negative values silently instead of raising an error

4 participants