GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: cast error during buffered fancy-index assignment is swallowed (SystemError or silently leaked exception) · Issue #31974 · numpy/numpy

BUG: cast error during buffered fancy-index assignment is swallowed (SystemError or silently leaked exception) #31974

New issue
Copy link
New issue
Copy link
Closed
#31975
Closed
BUG: cast error during buffered fancy-index assignment is swallowed (SystemError or silently leaked exception)#31974
#31975
Copy link
Labels
00 - Bug

Description

@Ijtihed
Ijtihed
opened on Jul 12, 2026
Issue body actions

Describe the issue:

If arr[idx] = values needs a buffered cast and the cast fails in a buffer chunk after the first one (array > 8192 elements), the error is set but the assignment reports success. Result: the statement silently "succeeds", dst is partially written, and the leaked exception surfaces at a later unrelated call (or as SystemError: ... returned a result with an exception set when it crosses a function-call boundary, e.g. inside np.put_along_axis).

Small arrays raise a clean TypeError for the same assignment, so behavior is size-dependent. Not object-specific: a failing string cast (svals[9000] = "xx" into an int array) leaks the same way.

Root cause: a cast failure during buffer refill makes npyiter_buffered_iternext return 0, indistinguishable from normal end of iteration (nditer_templ.c.src ~line 248). mapiter_set loops do {...} while (mit->outer_next(...)) and only checks PyErr_Occurred() at the top of the loop body, so the error set by the final iternext is never seen; the function returns 0 (lowlevel_strided_loops.c.src:2010-2157), and array_assign_subscript (mapping.c:2175) reports success.

Reproduce the code example:

import numpy as np

N = 20000  # > 8192 (one buffer chunk)
dst = np.zeros(N, dtype=int)
vals = np.arange(N, dtype=object)
vals[9000] = None  # in the second chunk

dst[np.arange(N)] = vals   # does NOT raise
print("got here")          # leaked TypeError detonates here or later

Error message:

got here
Traceback (most recent call last):
  File "repro.py", line 9, in <module>
    print("got here")
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

Same assignment via np.put_along_axis raises immediately instead, but as:
SystemError: <function put_along_axis at 0x...> returned a result with an exception set

dst has the first 8192 elements written, rest untouched. The partial write is
expected (see gh-31965 / gh-31940); this issue is only the swallowed exception.

Python and NumPy Versions:

NumPy 2.2.4, 2.5.1, and main @ 9ef40d3. Python 3.13.5, Linux x86_64 (Debian 13).

Runtime Environment:

No response

How does this issue affect you or how did you find it:

Found while auditing partial-write behavior for gh-31965.

Activity

  1. Ijtihed
    added
    00 - Bug
    on Jul 12, 2026
  2. ngoldbaum
    closed this as completedin #31975on Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.