-
Notifications
You must be signed in to change notification settings - Fork 97
Description
Bug: ak.square does not support bool dtype (NumPy mismatch)
Summary
arkouda.numpy.square raises a TypeError when called on boolean arrays,
while NumPy defines np.square for bool by treating values as integers
(False → 0, True → 1).
This mismatch was discovered via the NumPy-alignment test suite.
Expected Behavior (NumPy)
np.square(np.array([True, False, True], dtype=bool))
# array([1, 0, 1])NumPy supports square for boolean inputs by applying integer semantics.
Actual Behavior (Arkouda)
ak.square(ak.array([True, False, True]))
# TypeError: square only implements types [numpy.float64, numpy.int64, numpy.uint64]The error originates from client-side dtype validation.
Failing Test
tests/numpy/alignment_verification/numeric_alignment_numpy.py::
test_unary_alignment[False-square-square-square-kinds16]
Traceback excerpt:
TypeError: square only implements types [<class 'numpy.float64'>,
<class 'numpy.int64'>, <class 'numpy.uint64'>]
Root Cause
ak.square dispatches through _general_helper, which performs a strict
dtype check via _datatype_check and explicitly excludes bool.
This is a client-side restriction rather than a backend limitation.
Proposed Fix
Align with NumPy by supporting boolean inputs. Two viable approaches:
-
Client-side cast (recommended)
If input dtype isbool, cast toint64(oruint64) and applysquare. -
Relax dtype gate
Extend_datatype_checkto allowbooland ensure correct backend handling.
Both approaches preserve NumPy semantics (True → 1, False → 0).
Why This Matters
- Required for NumPy semantic alignment
- Prevents unnecessary
TypeErrorin vectorized pipelines - Improves compatibility with NumPy- and pandas-style code
- Allows alignment tests to run without
xfail
Environment
- Arkouda client: 2025.12.x
- Arkouda server: 2025.12.x
- Python: 3.13