JuliaPy / PyCall.jl

Package to call Python functions from the Julia language
MIT License
1.47k stars 187 forks source link

Numpy arrays of `str` dtype are not converted to Arrays #901

Open sethaxen opened 3 years ago

sethaxen commented 3 years ago

A np.array with dtype=str, when passed to Julia remains a PyObject, instead of becoming some useful Array{String}. Here's a minimal example:

julia> using PyCall

julia> py"""
       import numpy as np
       """

julia> py"""np.array(["a"], dtype=str)"""
PyObject array(['a'], dtype='<U1')
PhilipVinc commented 3 years ago

This wouldn't be too hard to implement but requires an additional dependency:

Numpy string arrays are encoded as fixed-length Char arrays. A Vector{String} in Julia would be a vector of pointers.

We'd need something like ShortStrings.jl

barrettp commented 2 years ago

Wouldn't it be preferable to interpret the Numpy string array as an Array{Vector{UInt8}} and then access it using the bytes interface?

I could really use this functionality. What would be the best way to implement a patch?