arkouda.numpy.err¶
Floating-point error state management for Arkouda.
This module provides a NumPy-like API for controlling how Arkouda handles floating-point errors such as divide-by-zero, overflow, underflow, and invalid operations. The design mirrors numpy.errstate, numpy.seterr, and related functions, so users familiar with NumPy can expect similar semantics.
Unlike NumPy, Arkouda computations occur in a distributed backend, so this module currently acts as a lightweight scaffold: it records user preferences and dispatches to Python-side handlers when explicitly invoked by front-end code. By default, there is no performance cost, since core numerical kernels do not consult this state unless explicitly wired to do so.
Available error modes¶
Each error category (‘divide’, ‘over’, ‘under’, ‘invalid’) may be set to one of the following modes:
"ignore": silently ignore the error (default)."warn": issue a PythonRuntimeWarning."raise": raise aFloatingPointErrorexception."call": invoke a user-supplied callable (seeseterrcall())."print": write a message to standard output."log": log a message via Arkouda’s logger.
API¶
geterr(): return the current error handling settings.seterr(): set global error handling, returning the old settings.geterrcall(): get the callable used for"call"mode.seterrcall(): set the callable used for"call"mode.errstate(): context manager to temporarily change settings.handle(): route an error condition through the current policy.
Example
>>> import arkouda as ak
>>> ak.geterr()
{'divide': 'ignore', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'}
>>> with ak.errstate(divide="warn"):
... out = ak.array([1.0]) / 0
>>> def myhandler(kind, msg): print(f"[ak] {kind}: {msg}")
>>> ak.seterr(divide="call")
{'divide': 'ignore', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'}
>>> ak.seterrcall(myhandler)
>>> out = ak.array([1.0]) / 0
[ak] divide: divide by zero encountered
[ak] divide: divide by zero encountered in divide
Functions¶
|
Context manager to temporarily set floating-point error handling. |
|
Get the current Arkouda floating-point error handling settings. |
|
Get the current callable used when error mode is 'call'. |
|
Set how Arkouda handles floating-point errors. |
|
Set the callable invoked when an error category is set to 'call'. |
Module Contents¶
- arkouda.numpy.err.errstate(*, divide: _ErrorMode | None = None, over: _ErrorMode | None = None, under: _ErrorMode | None = None, invalid: _ErrorMode | None = None, call: Callable[[str, str], None] | None = None) Iterator[None][source]¶
Context manager to temporarily set floating-point error handling.
- Parameters:
divide ({'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional) – Temporary behavior within the context.
over ({'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional) – Temporary behavior within the context.
under ({'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional) – Temporary behavior within the context.
invalid ({'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional) – Temporary behavior within the context.
call (callable or None, optional) – Temporary callable used if any category is set to ‘call’. Signature: (errtype: str, message: str) -> None.
- Yields:
None – This context manager does not return a value. Code inside the
withblock will be executed with the temporary error handling settings.
Examples
>>> import arkouda as ak >>> ak.geterr() {'divide': 'call', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'} >>> with ak.errstate(divide='warn'): ... _ = ak.array([1.0]) / 0 # gives a warning >>> ak.geterr()['divide'] 'ignore'
Notes
This affects only stored policy; it does not add runtime checks by itself.
- arkouda.numpy.err.geterr() Dict[str, _ErrorMode][source]¶
Get the current Arkouda floating-point error handling settings.
- Returns:
Mapping of {‘divide’, ‘over’, ‘under’, ‘invalid’} to one of {‘ignore’, ‘warn’, ‘raise’, ‘call’, ‘print’, ‘log’}.
- Return type:
dict
- arkouda.numpy.err.geterrcall() Callable[[str, str], None] | None[source]¶
Get the current callable used when error mode is ‘call’.
- Returns:
A function of signature (errtype: str, message: str) -> None, or None.
- Return type:
callable or None
- arkouda.numpy.err.seterr(**kwargs: _ErrorMode) Dict[str, _ErrorMode][source]¶
Set how Arkouda handles floating-point errors.
- Parameters:
divide ({'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional) – Behavior for the corresponding error category.
over ({'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional) – Behavior for the corresponding error category.
under ({'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional) – Behavior for the corresponding error category.
invalid ({'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional) – Behavior for the corresponding error category.
- Returns:
The previous settings.
- Return type:
dict
Notes
This is a scaffold API. It does not change backend behavior yet; it only records the desired policy so future operations can consult it.
- arkouda.numpy.err.seterrcall(func: Callable[[str, str], None] | None) Callable[[str, str], None] | None[source]¶
Set the callable invoked when an error category is set to ‘call’.
- Parameters:
func (callable or None) – Function of signature (errtype: str, message: str) -> None. Pass None to clear.
- Returns:
The previous callable.
- Return type:
callable or None
Notes
This is a stub for API compatibility. Arkouda does not currently invoke this callable; it is stored for future use.