Should a dtype=object array be treated more like Python lists for type 
detection/coercion reasons?   Currently, they are treated quite differently:

>>> import numpy as np
>>> np.isfinite([1,2,3])
array([ True,  True,  True])
>>> np.isfinite(np.asarray([1,2,3], dtype=object))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs 
could not be safely coerced to any supported types according to the casting 
rule ''safe''

The reason I ask is that we ran into something similar when trying to pass 
wrappers around Julia arrays to Python.  A Julia `Any[]` array is much like a 
Python list or a Numpy `object` array, and exposed in Python as a subtype of 
MutableSequence, but we found that it was treated by NumPy as more like a Numpy 
`object` array than a Python list 
(https://github.com/JuliaPy/PythonCall.jl/issues/486).

Would it be desirable to treat a 1d Numpy `object` array more like a Python 
`list`?   Or is there a way for externally defined types to opt-in to the 
`list` behavior?  (I couldn't figure out in the numpy source code where `list` 
is being special-cased?)
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to