numpy / numpy/numpy

squeeze on memmap returns numpy.ndarray instead of memmap

Open
#11,437 3 comments 0 reactions 0 assignees View on GitHub

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

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.