Skip to content

np.array silently catching errors #18723

@radarhere

Description

@radarhere

I find that np.array silently catches an error raised by __array_interface__. This was confirmed to be a bug on Gitter - https://gitter.im/numpy/numpy?at=6067b4ef3153ce63a3b6dcad

Reproducing code example:

import numpy as np

class Sample:
    @property
    def __array_interface__(self):
        raise OSError

x = Sample()
try:
    x.__array_interface__
except OSError:
    print("OSError raised by __array_interface__")

np.array(x)
print("But not by np.array")

Error message:

No error. That's the problem.

The output of my code example is

OSError raised by __array_interface__
But not by np.array

NumPy/Python version information:

1.20.2 3.8.9 (default, Apr 3 2021, 19:49:13)
[Clang 12.0.0 (clang-1200.0.32.29)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions