File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,8 @@ def setbufsize(size):
187187 8192
188188
189189 """
190+ if size < 0 :
191+ raise ValueError ("buffer size must be non-negative" )
190192 old = _get_extobj_dict ()["bufsize" ]
191193 extobj = _make_extobj (bufsize = size )
192194 _extobj_contextvar .set (extobj )
Original file line number Diff line number Diff line change @@ -4708,6 +4708,18 @@ def test_reduceat():
47084708 np .setbufsize (ncu .UFUNC_BUFSIZE_DEFAULT )
47094709 assert_array_almost_equal (h1 , h2 )
47104710
4711+ def test_negative_value_raises ():
4712+ with pytest .raises (ValueError , match = "buffer size must be non-negative" ):
4713+ np .setbufsize (- 5 )
4714+
4715+ old = np .getbufsize ()
4716+ try :
4717+ prev = np .setbufsize (4096 )
4718+ assert prev == old
4719+ assert np .getbufsize () == 4096
4720+ finally :
4721+ np .setbufsize (old )
4722+
47114723def test_reduceat_empty ():
47124724 """Reduceat should work with empty arrays"""
47134725 indices = np .array ([], 'i4' )
You can’t perform that action at this time.
0 commit comments