Scalar compared with an obj implementing __array_ufunc__ becomes 0d-array
Open
Nobody has claimed this yet.
00 - Bug
component: numpy._core
- Dominant language
- Python
- Stars
- 32.8k
- Forks
- 12.8k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 197
Description
Behaviors for comparison operators and for arithmetic operators are different.
Reproducing code example:
import numpy as np
class C(object):
def __array_ufunc__(self, *args, **kwargs): print(args); print(kwargs)
np.float32(1) + C()
np.float32(1) < C()
output:
(<ufunc 'add'>, '__call__', 1.0, <__main__.C object at 0x114d54048>)
{}
(<ufunc 'less'>, '__call__', array(1., dtype=float32), <__main__.C object at 0x1145d5d30>)
{}
Numpy/Python version information:
1.16.0.dev0+2ed08ba 3.7.0 (default, Aug 16 2018, 11:04:41)
[Clang 10.0.0 (clang-1000.10.25.5)]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Python reproducer and compare the arguments passed to array_ufunc for addition and comparison. Trace the scalar arithmetic and comparison dispatch paths to determine where the comparison operand becomes a 0d array. Done means the two operator families have consistent, tested dispatch behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100