Skip to content

Support integer inputs for ak.floor and ak.ceil (NumPy alignment) #5253

@ajpotts

Description

@ajpotts

Support integer inputs for ak.floor and ak.ceil (NumPy alignment)

Summary

ak.floor and ak.ceil currently raise TypeError for integer inputs, while NumPy defines these ufuncs for integer arrays as identity operations (i.e., no-op, returning the same values).

This discrepancy causes failures in NumPy alignment tests and represents a gap between Arkouda and NumPy semantics.

Current Behavior

>>> import arkouda as ak
>>> import numpy as np

>>> a = ak.array([1, 2, -3], dtype=ak.int64)
>>> ak.floor(a)
TypeError: floor only implements types [<class 'float'>]

In NumPy:

>>> np.floor(np.array([1, 2, -3], dtype=np.int64))
array([ 1.,  2., -3.])

Expected / Desired Behavior

Two reasonable alignment options:

Recommendation

  • Allow integer inputs for ak.floor and ak.ceil
  • Return an array equivalent to NumPy behavior:
    • Either identical integer values
    • Or float output matching NumPy’s casting rules

Rationale

  • NumPy defines floor and ceil for all real-valued dtypes, including integers
  • Alignment reduces surprise and simplifies user code paths
  • Integer support can be implemented cheaply as a fast-path / no-op

Suggested Implementation Sketch

In arkouda/numpy/numeric.py:

if pda.dtype.kind in "iu":
    return pda.astype(ak.float64)  # or return pda unchanged if int output is desired

(or equivalent logic consistent with Arkouda dtype policy)

Tests

  • Update NumPy alignment tests to expect:
    • Successful execution for integer inputs
    • Output matching NumPy semantics

Impact

  • Improves NumPy compatibility
  • Low risk change (no existing valid code relies on raising here)
  • Helps stabilize alignment verification suite

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions