You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Generator.integers does not reject float dtypes #5298
Bug: Generator.integers does not reject float dtypes
Summary
ak.random.Generator.integers fails to raise a TypeError when a floating-point dtype (e.g. ak.float64) is passed via the dtype argument. This diverges from NumPy behavior and allows invalid calls to proceed silently.
Expected Behavior
Passing a floating-point dtype to integers should raise a TypeError, consistent with NumPy:
importarkoudaasakrng=ak.random.default_rng(123)
rng.integers(0, 10, size=10, dtype=ak.float64) # no error
Root Cause
Inside Generator.integers, the dtype argument is normalized using to_numpy_dtype(dtype), producing a numpy.dtype object. The subsequent guard uses an identity check:
ifdtypeisakfloat64:
raiseTypeError(...)
After normalization, this identity check fails even when the dtype represents float64, so the error is never raised.
Proposed Fix
Replace the identity check with a semantic dtype check. For example:
ifdtype.kind=="f":
raiseTypeError(f"Unsupported dtype {dtype!r} for integers")
This correctly rejects all floating-point dtypes (float32, float64, etc.) and matches NumPy semantics.
Activity
Fixes bug 5298, so that generator.integers gives an error if asked fo…