Skip to content

Conversation

@charris
Copy link
Member

@charris charris commented Sep 23, 2025

Backport of #29774 .

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

<!--         ----------------------------------------------------------------
                MAKE SURE YOUR PR GETS THE ATTENTION IT DESERVES!
                ----------------------------------------------------------------

*  FORMAT IT RIGHT:
      https://www.numpy.org/devdocs/dev/development_workflow.html#writing-the-commit-message

*  IF IT'S A NEW FEATURE OR API CHANGE, TEST THE WATERS:
      https://www.numpy.org/devdocs/dev/development_workflow.html#get-the-mailing-list-s-opinion

*  HIT ALL THE GUIDELINES:
      https://numpy.org/devdocs/dev/index.html#guidelines

*  WHAT TO DO IF WE HAVEN'T GOTTEN BACK TO YOU:
      https://www.numpy.org/devdocs/dev/development_workflow.html#getting-your-pr-reviewed
-->

cibarbia05 and others added 2 commits September 23, 2025 15:33
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
@charris charris added this to the 2.3.4 release milestone Sep 23, 2025
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Sep 23, 2025
@charris charris merged commit fbf0826 into numpy:maintenance/2.3.x Sep 23, 2025
75 checks passed
@charris charris deleted the backport-29774 branch September 23, 2025 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants