SArray of lists of int() converts to lists of floats()

User 2568 | 5/3/2016, 7:48:52 AM

Create an SArray of integers sa = gl.SArray([5, 36, 36, 95])

Use apply to create an SArray where each element is now a list with one element. sa.apply(lambda i: [i])

The integers are converted to floats. However if I do sa.apply(lambda i: i)

the elements aren't converted. This is causing me a lot of pain at the moment. Is this a bug?

This is related to a similar issue I had with dicts here

I also noted that

sa = gl.SArray([[5, 36],[36, 95]])

is an array of floats. However if I make one element in a list a string, this does not happen. Clearly I'm not understanding something here

Comments

User 1189 | 5/3/2016, 5:37:10 PM

Hi,

This is an unfortunate issue with how type conversion from Python was specced out a while back and is difficult to fix without breaking compatibility issues. Essentially, it tries to find the "most specific" type that can contain the values; which in the case of the numeric arrays, is the array type.

We do plan to fix this all at once in the future along with a collection of potentially compatibility breaking changes which fix some inconsistencies.

In the meantime, the work around is to bypass the type inference

sa = gl.SArray([5, 36, 36, 95]) sa.apply(lambda i: [i], list) # forces result to list sa = gl.SArray([[5, 36],[36, 95]], list) # forces it to list

Yucheng


User 2568 | 5/4/2016, 12:49:16 AM

Thanks for this explanation. I was not aware of the option to override the dtype which is a simple solution to my problem.