BUG: calling np.sqrt on an array containing only floats, but of dtype object, will crash
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 32.8k
- Forks
- 12.8k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 197
Description
Describe the issue:
np.sqrt is one of the only operation that crashes on a nd array of dtype object containing only floats.
Furthermore, the error yielded is very unclear, mentioning that floats does not support sqrt (which is not true).
The example speak for itself.
Reproduce the code example:
import numpy as np
feature = np.array([1.2], dtype="object")
print(np.sum(feature))
# 1.2
print(np.sqrt(feature))
Error message:
AttributeError: 'float' object has no attribute 'sqrt'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: loop of ufunc does not support argument 0 of type float which has no callable sqrt method
Python and NumPy Versions:
2.1.3
3.12.2 (main, Feb 6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]
Runtime Environment:
[{'numpy_version': '2.1.3',
'python': '3.12.2 (main, Feb 6 2024, 20:19:44) [Clang 15.0.0 '
'(clang-1500.1.0.2.5)]',
'uname': uname_result(system='Darwin', node='Marcos-Macbook-air.local', release='23.4.0', version='Darwin Kernel Version 23.4.0: Fri Mar 15 00:19:22 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8112', machine='arm64')},
{'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
'found': ['ASIMDHP'],
'not_found': ['ASIMDFHM']}}]
Context for the issue:
No response
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 with the supplied reproducer using np.sqrt on a float-valued object-dtype array, then trace the object-dtype ufunc handling. No files or tests are named in the issue, so locate the relevant ufunc implementation and existing tests first. Done means the example no longer crashes and the resulting behavior and error handling are covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100