Skip to content

empty_like not passing across attributes of memmap objects (Trac #1753) #2348

Open

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/1753 on 2011-03-03 by trac user bryancole, assigned to unknown.

If I create a memmap object:

>>> a = numpy.memmap("foo", mode="w+", shape=10)

then later I create a new array thus:

>>> b = numpy.empty_like(a)

then b is also a memmap object. However, even though the type of b is 'memmap', it has no _mmap attribute (as you'd expect, since empty_like cannot know what file object to use).

The broken memmap object b causes failures elsewhere in array_finalise as it tries to copy attributes from b (filename, offset, mode) which do not exist.

In summary there are TWO bugs here:

  1. empty_like (and friends) should not return objects of type memmap

  2. the memmap.array_finalise method is checking for the existence of the _mmap attribute. In non-memmap objects, this may exist but be set to None, therefore this method needs to check that both _mmap exists as an attribute and is not None.

Activity

  1. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @mwiebe wrote on 2011-03-15

    I just added a 'subok' parameter to empty_like. This allows

    >>> b = numpy.empty_like(a, subok=False)
    

    to create a regular array, not a memmap. While this doesn't fix the issue, it should help mitigate it in some circumstances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions