Global numpy.seterr vs local numpy.errstate for controlling floating-point alert noise
0 reputation · 05 May 2023, 01:16 UTC
Goal is to configure NumPy floating-point error handling so critical issues are surfaced while routine operations do not produce notification noise.
numpy.seterr defines process-wide behavior for divide by zero, overflow, invalid and underflow with modes ignore, warn, raise, call or print. numpy.errstate temporarily overrides those settings inside a block and restores them on exit. A global change can affect all NumPy operations in the process, including libraries that rely on default warnings. Local overrides limit scope but require explicit wrapping of each risky segment and the manager is not thread-safe.
Defaults for the four categories have varied across versions and platforms, and the interaction of nested errstate contexts with custom call handlers is not fully clear for a design that must stay quiet by default yet alert on specific conditions.
What conditions make a global seterr configuration safe when third-party code expects default warnings? How do nested errstate contexts combine when different exception categories need different modes? Is there a documented way to audit coverage of errstate overrides without instrumenting each call site?