Skip to content

Bug: Generator.integers does not reject float dtypes #5298

Closed

Description

@ajpotts

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:

import numpy as np

rng = np.random.default_rng(123)
rng.integers(0, 10, size=10, dtype=np.float64)  # TypeError

Arkouda should match this behavior.

Actual Behavior

The following call succeeds without raising:

import arkouda as ak

rng = 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:

if dtype is akfloat64:
    raise TypeError(...)

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:

if dtype.kind == "f":
    raise TypeError(f"Unsupported dtype {dtype!r} for integers")

This correctly rejects all floating-point dtypes (float32, float64, etc.) and matches NumPy semantics.

Regression Test

def test_integers_rejects_float64_dtype():
    rng = ak.random.default_rng(123)
    with pytest.raises(TypeError):
        rng.integers(0, 10, size=10, dtype=ak.float64)

Impact

  • Brings Arkouda RNG API into alignment with NumPy
  • Prevents silent misuse of integers with invalid dtypes
  • Improves correctness and test coverage in alignment test suite

Activity

  1. added
    bug
    on Jan 10, 2026
  2. self-assigned this
    on Feb 2, 2026
  3. added a commit that references this issue on Feb 9, 2026
    ca27d94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions