NDCube does not support arithmetic via numpy ufuncs
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
Research direction
Start with NDCube's existing add and related arithmetic methods, then read the NumPy NEP 13 recommendations linked in the issue. Implementing array_ufunc should cover the listed ufunc cases, route Python operators through NumPy ufuncs, and preserve NotImplemented behavior for operands with array_ufunc = None.
Written by the indexing model from the issue text.
Description
Describe the bug
Numpy ufuncs are things like np.add and np.equal, currently we support arithmetic methods via the standard Python operands like + (through __add__) but not the equivalent ufunc.
I discovered this issue because the following doesn't work:
cube = NDCube(...)
arr = np.array([cube], dtype=object)
np.equal(arr, cube)
In addition some things like np.maximum and np.isinf might be quite nice to have working without having to access .data, also if we implement __array_ufunc__ we can have those things return quantities.
See Recommendations for implementing binary operations in the NEP for how I think we need to go about this.
The overview is:
- Implement all the arithmetic methods in
__array_ufunc__. - Have the Python operator methods
__add__etc, call the numpy ufunc, i.e.__add__callsnp.add. - Ensure that our operator methods return
NotImplementedif the other operand has__array_ufunc__ = None.
- Dominant language
- Python
- Stars
- 49
- Forks
- 56
- Avg merge
- 5h 54m
- Merged PRs (30d)
- 9
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.
More from sunpy/ndcube
-
Bug
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
Bug
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Feature Request
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Feature Request
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
use-agent-os/agent-os#3314 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
BasedHardware/omi#15662 · 1 comment ·
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AiursoftWeb/AnduinOS-2#19 ·