Closed stevengj closed 3 months ago
It's not just empty arrays:
julia> np.isfinite(pylist([1,2,3]))
Python: array([ True, True, True])
julia> np.isfinite(Any[1,2,3])
ERROR: Python: 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''
julia> np.isfinite(np.asarray(pylist([1,2,3]), dtype=pybuiltins.object))
ERROR: Python: 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''
Basically, NumPy seems to treat Python lists fundamentally differently from numpy arrays of objects, and Py([])
acts like the latter. Seems like an upstream issue.
I posted a question on https://mail.python.org/archives/list/numpy-discussion@python.org/ … we'll see what they say.
A problem reported in https://github.com/JuliaPy/PythonPlot.jl/issues/36 — Numpy functions work for empty Python lists, and for empty numeric-typed Julia arrays, but don't work for empty
Any[]
arrays:Ideally,
Py([])
should behave much like a python emptylist
. I'm not sure if this is something that can be fixed on the PythonCall side or if it's some broken special-casing in numpy?The error message stems from
linear_search_type_resolver
in numpyThe basic issue seems to be that numpy treats an empty list as an array of
float64
, butPy([])
as an array ofobject
:The latter seems more correct, but I'm guessing that Numpy implemented the former rule for convenience. I can't find where the former rule is implemented in the numpy source, however, to tell if we can hook into it.
Not sure if this is something that can/should be changed, but I thought I should make a record of the problem for future reference.