[Numpy-discussion] Custom __array_interface__ error

Nathaniel Smith njs at pobox.com
Fri Mar 13 14:43:36 EDT 2015

On Mar 13, 2015 7:22 AM, "Daniel Smith" <dgasmith at icloud.com> wrote:
> Greetings everyone,
> I have a new project that deals with core and disk tensors wrapped into a
single object so that the expressions are transparent to the user after the
tensor is formed. I would like to add __array_interface__ to the core
tensor and provide a reasonable error message if someone tries to call the
__array_interface__ for a disk tensor. I may be missing something, but I do
not see an obvious way to do this in the python layer.

Just define your class so that attempting to access __array_interface__
raises an error directly:

class DiskTensor(object):
    def __array_interface__(self):
        raise TypeError(...)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150313/7e4a7272/attachment.html>

More information about the NumPy-Discussion mailing list