Repository navigation
Description
Feature Request: Implement pdarray.__pos__ (Unary Plus) in Arkouda
Summary
Arkouda currently implements several unary operators for pdarray, but does not implement __pos__ (the unary plus operator, +a).
In Python and NumPy, unary plus is supported for array-like objects and acts as a no-op that preserves type and structure.
Adding pdarray.__pos__ improves API completeness, NumPy compatibility, and prevents surprising TypeError failures when user code or libraries apply unary plus.
Motivation
1. NumPy Compatibility
NumPy defines:
>>> import numpy as np
>>> a = np.array([1, -2, 3])
>>> +a
array([ 1, -2, 3])Unary plus returns the same array with the same dtype.
Arkouda should match this behavior for interoperability and test consistency.
2. API Completeness
Arkouda supports:
__neg__→ unary-a- various binary operators
Missing:
__pos__→ unary+a
Unary plus is occasionally used in:
- generic numeric code
- broadcasting expressions
- frameworks that validate or normalize operators
- auto-generated symbolic expressions
Lack of __pos__ currently results in errors such as:
TypeError: bad operand type for unary +: 'pdarray'
3. Zero-cost implementation
Unary plus is semantically trivial:
- No transformation needed
- No backend operation required
- Should simply return
self
Proposed Behavior
Implement pdarray.__pos__ such that:
def __pos__(self):
return selfThis matches NumPy:
- preserves dtype
- preserves shape
- performs no computation
- returns a
pdarray, not a copy
Example (expected behavior):
>>> import arkouda as ak
>>> a = ak.arange(5) * -1
>>> a
array([ 0, -1, -2, -3, -4])
>>> +a
array([ 0, -1, -2, -3, -4])
>>> (+a) is a
True # unary plus should return the same objectImplementation Notes
File to modify:
arkouda/numpy/pdarrayclass.py
Add implementation to class pdarray:
def __pos__(self):
return selfNo server message required.
Tests
New unit tests should verify:
def test_unary_plus_pdarray():
import arkouda as ak
a = ak.arange(5)
assert (+a is a)
assert (+a).to_list() == [0, 1, 2, 3, 4]NumPy alignment
Add unary-plus checks to the NumPy compatibility tests:
assert_arkouda_array_equivalent(+a_ak, +a_np)Acceptance Criteria
+pdarrayreturns the samepdarrayinstance- Behavior matches NumPy unary plus semantics
- No backend communication involved
- No performance penalty
- All NumPy-alignment tests pass after update
- No regressions in negation / abs / binary operator behavior
Conclusion
Implementing pdarray.__pos__ is a simple, zero-cost enhancement that improves:
- API completeness
- NumPy interoperability
- Predictability for users and libraries
This operator should be added for consistency and correctness.
Activity
Closes Bears-R-Us#5116: Feature Request: Implement pdarray.__pos__ (U…
Closes Bears-R-Us#5116: Feature Request: Implement pdarray.__pos__ (U…
Closes Bears-R-Us#5116: Feature Request: Implement pdarray.__pos__ (U…
Closes Bears-R-Us#5116: Feature Request: Implement pdarray.__pos__ (U…
Closes #5116: Feature Request: Implement pdarray.__pos__ (Unary Plus)…