a use case for __array_interface__ "scalar" path?

[email protected]
Newsgroups gmane.comp.python.numeric.general
Message-ID <[email protected]>
Hi,

I was trying to prevent array creation from iterating over instances of classes implementing __iter__, __getitem__, __len__ etc. 
An effective way (at least with a UserDict subclass) seem setting 

__array_interface__ = {"shape": (), "typestr": "O"}  # with data field omitted (!)

According to the docs https://numpy.org/devdocs/reference/arrays.interface.html#object.__array_interface__ 
"Not specifying this field uses a “scalar” path that we may remove in the future as we are not aware of any users." 
I am new to __array_interface__, so this might be a bad approach (*). If not, this seems to be a good reason for *not* removing.

Note there is demand for avoiding coercion of custom types into new dimensions:
https://stackoverflow.com/q/43722023
https://stackoverflow.com/q/70460738
https://stackoverflow.com/q/22290204
https://github.com/numpy/numpy/issues/27212
https://github.com/numpy/numpy/issues/27382

(*) Still, other attempts partially messed up with class functionality (e.g., __len__ = None) or did not work at all:
__iter__ = None (TypeError: Could not convert object to sequence)
implementing __array__ (RecursionError: maximum recursion depth exceeded)

Cheers,
Marco
_______________________________________________
NumPy-Discussion mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/numpy-discussion.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.