Skip to content

np.memmap throws OSError when size is zero #12653

@ghost

Description

...Which, in fairness, is an edge case I should have guarded against myself. On the other hand, perhaps we could do some checking and toss a descriptive ValueError instead? I'm willing to write up a PR if that's an acceptable change.

Reproducing code example:

The following works with any shape, so long as any one of the axes is length 0:

import numpy as np
mmap = np.memmap('test.npy', shape=(0,4), mode='w+')

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/numpy/core/memmap.py", line 250, in __new__
    fid.seek(bytes - 1, 0)
OSError: [Errno 22] Invalid argument

Numpy/Python version information:

1.15.2 / 3.5.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions