squeeze on memmap returns numpy.ndarray instead of memmap
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 32.8k
- Forks
- 12.8k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 197
Description
When performing squeeze operation on a memmap, it is converted to a normal in-memory array. Other array operation functions, such as reshape or expand_dims preserve the memmap type. Therefore the conversion upon squeeze is somewhat unexpected behavior in my point of view.
import numpy as np
from tempfile import mkdtemp
import os.path as path
filename = path.join(mkdtemp(), 'newfile.dat')
fp = np.memmap(filename, dtype='float32', mode='w+', shape=(3,4,1))
print('type before squeeze')
print(type(fp))
print(fp.shape)
print('type after squeeze')
squeezed = fp.squeeze()
print(type(squeezed))
print(squeezed.shape)
my output with numpy version 1.14.3
type before squeeze
<class 'numpy.core.memmap.memmap'>
(3, 4, 1)
type after squeeze
<class 'numpy.ndarray'>
(3, 4)
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 memmap and squeeze reproduction with the current NumPy test suite, then compare its behavior with reshape and expand_dims. Trace the squeeze entry point and existing memmap coverage; done means the intended behavior is established by a regression test and is consistent with the project’s expectations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100