diff --git a/strax/utils.py b/strax/utils.py index f84d078e..d345db81 100644 --- a/strax/utils.py +++ b/strax/utils.py @@ -124,6 +124,17 @@ def accumulate_numba_result(*args, **kwargs): return _growing_result +@export +def set_nan_defaults(buffer): + """When constructing the dtype, take extra care to set values to np.Nan / -1 (for ints) as 0 + might have a meaning.""" + for field in buffer.dtype.names: + if np.issubdtype(buffer.dtype[field], np.integer): + buffer[field][:] = -1 + else: + buffer[field][:] = np.nan + + @export def unpack_dtype(dtype): """Return list of tuples needed to construct the dtype.