Skip to content

Segmentation fault for np.empty_like(a).astype(bool) for an object array a #19373

@Horstage

Description

@Horstage

Using Python 3.8.9 on linux with numpy 1.21.0 I get an Segmentation fault when typecasting an object array to bool which was created by np.empty_like.

Minimal working example:

import numpy as np

class Foo:
    pass

a = np.array([Foo(), Foo()], dtype=Foo)
b = np.empty_like(a)
b.astype(bool)

To replicate environment use docker container python:3.8-slim and pip install numpy.
e.g.

docker run -it --entrypoint=/bin/bash python:3.8-slim
pip install numpy==1.21.0

Workaround for those who still have to work with this:

b = np.copy(a)
b[:] = None
b.astype(bool)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions