Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork11.9k
Closed
Labels
Description
Describe the issue:
Calling .squeeze() on a slice of a memmap that has shape(1,) raises
RuntimeError: ndarray subclass __array_wrap__ method returned an object which was not an instance of an ndarray subclassReproduce the code example:
importnumpyasnpimportstruct# set up filefilename='ex.bin'withopen(filename,'wb')asf:f.write(bytearray(struct.pack('d',3.14)))f.write(bytearray(struct.pack('d',6.28)))# mmap filearr=np.memmap(filename,dtype=np.float64,mode='r',shape=(2,1))print(arr)print(arr.squeeze())# worksprint(arr[1:2,0])print(np.array(arr)[1:2,0].squeeze())# worksprint(arr[1:2,0].squeeze())# fails
Error message:
Traceback (most recent call last): File"/home/brian/Dev/cpp/ffistan/repr.py", line 18,in<module>print(arr[1:2,0].squeeze())# failsRuntimeError: ndarray subclass __array_wrap__ method returned an object which was not an instance of an ndarray subclass
Runtime information:
>>> import sys, numpy; print(numpy.__version__); print(sys.version)1.26.23.9.13 | packaged by conda-forge | (main, May 27 2022, 16:56:21) [GCC 10.3.0]>>> print(numpy.show_runtime())WARNING: `threadpoolctl` not found in system! Install it by `pip install threadpoolctl`. Once installed, try `np.show_runtime` again for more detailed build information[{'numpy_version': '1.26.2', 'python': '3.9.13 | packaged by conda-forge | (main, May 27 2022, ' '16:56:21) \n' '[GCC 10.3.0]', 'uname': uname_result(system='Linux', node='FlatTop', release='6.2.0-37-generic', version='#38~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 2 18:01:13 UTC 2', machine='x86_64')}, {'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'], 'found': ['SSSE3', 'SSE41', 'POPCNT', 'SSE42', 'AVX', 'F16C', 'FMA3', 'AVX2', 'AVX512F', 'AVX512CD', 'AVX512_SKX', 'AVX512_CLX', 'AVX512_CNL', 'AVX512_ICL'], 'not_found': ['AVX512_KNL', 'AVX512_KNM']}}]NoneContext for the issue:
This operation seems well-defined for normal arrays but fails for memmaps. This violates the sentenceThe memmap object can be used anywhere an ndarray is accepted. in the documentation, and makes it difficult to write a library which relies onsqueeze in a generic way which is ambivalent to whether the user provided an array or memmap