Question
Convert '3' to numpy.dtypes.Int64DType
I have strings containing str representations of numpy values. I also have a list of the original dtypes, such as numpy.dtypes.Int64DType. I do not know all possible dtypes in advance. I can for the life of me not figure out how to convert the string back to a scalar of the correct dtype.
dt = numpy.dtypes.Int64DType
dt('3') # I was somewhat hoping this would work but the dtype is not callable
np.fromstring('3', dtype=dt) # ValueError: string size must be a multiple of element size
np.fromstring('3', dtype=dt, count=1) # ValueError: string is smaller than requested size
np.fromstring('[3]', dtype=dt, count=1) # ValueError: Cannot create an object array from a string
For the latter three calls, I also get a
:1: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead`
Which I don't understand, because '3' is not a binary string?