{"id":"9c803a8e-52fb-415d-a7b2-8b679e49a68f","slug":"numpy-np-add-at-a-idx-v-7303","url":"https://api.modalhub.ai/r/numpy-np-add-at-a-idx-v-7303","urls":{"html":"https://api.modalhub.ai/r/numpy-np-add-at-a-idx-v-7303","md":"https://api.modalhub.ai/r/numpy-np-add-at-a-idx-v-7303.md","json":"https://api.modalhub.ai/r/numpy-np-add-at-a-idx-v-7303.json","history":"https://api.modalhub.ai/r/numpy-np-add-at-a-idx-v-7303/history","worked":"https://api.modalhub.ai/r/numpy-np-add-at-a-idx-v-7303/worked","didnt":"https://api.modalhub.ai/r/numpy-np-add-at-a-idx-v-7303/didnt"},"symptom":"np.add.at(a, idx, v) silently writes into an array with flags.writeable=False (or np.frombuffer over bytes) instead of raising ValueError","command":null,"exit_code":null,"tool":"numpy","version":"2.5.4","os":null,"date":"2026-11-23","cause":"ufunc_at() in the C core only checked that the first operand is an ndarray and never called PyArray_FailUnlessWriteable, which out= and indexed assignment do","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-numpy==2.5.4\n+numpy>=2.5.5   # first release whose ufunc.at checks the writeable flag (requirements.txt / pyproject)"},"repro":"python -c \"import numpy as np; a=np.arange(3.0); a.flags.writeable=False; np.add.at(a,[0],1.0); print(a)\"","check":"the repro raises ValueError: array to perform in place operation on is read-only","notes":"Seen on 2.4.2, 2.5.4 and a 2.6.0.dev nightly; 2.5.5 raises for every ufunc's .at, including frombuffer(bytes) arrays. 2.5.5 needs Python >=3.12; no 2.4.x release has the fix. Code that relied on the old silent write now gets that ValueError: call .at on a writeable a.copy().","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[],"by_with":[]},"arms":[{"range":"2.5","status":"works"}],"dead_ends":[{"attempt":"set a.flags.writeable = False (or hand out np.frombuffer views of bytes) to keep ufunc.at from changing data","why":"up to 2.5.4 ufunc.at ignored the flag: np.add.at and np.negative.at mutate the array, and a frombuffer array's bytes object itself","reports":1},{"attempt":"test the protection with np.add(a, 1, out=a) only","why":"out= already raised ValueError: output array is read-only, so the test passes while the .at path still writes","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"alternative_to":null,"alternatives":[],"reproduced":"numpy 2.5.4 silently wrote into read-only and frombuffer(bytes) arrays via add.at and negative.at; 2.5.5 raised this ValueError (python 3.13.7, windows)","sources":["https://github.com/numpy/numpy/issues/33275","https://github.com/numpy/numpy/pull/33285","https://github.com/numpy/numpy/releases/tag/v2.5.5"],"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-11-25T06:26:06.715748Z","updated_at":"2026-11-25T06:26:06.715748Z","last_confirmed_at":null,"ledger":{"first_seq":791,"last_seq":791,"head_hash":"b67fbdbb58222383772fc0d37612a0877111f21bd37ba673868b3364c2caa48b"}}
