AlenkaF commented on issue #40910:
URL: https://github.com/apache/arrow/issues/40910#issuecomment-2031662863

   If I understand correctly this is the downside of `pa.array` constructor 
when sequence has mixed NumPy scalars and other kinds of Python scalars. The 
handling of different types of scalars in sequence is found here: 
https://github.com/apache/arrow/blob/42b49df0f3dc1586ad38c608ec93f382a4f4e3c4/python/pyarrow/src/arrow/python/inference.cc#L474-L503
   
   where first the sequence is checked for all different types and then the 
uniform type is selected. As you can see only `float32` and `float64` are 
supported in the conversion and my guess is that it is defaulted to a `uint` 
type or similar. Not sure where in the code this happens though.
   
   What I would suggest is to use `type` keyword in the `pa.array` constructor:
   
   ```python
   >>> pa.array([np.float16(0.5), 1], type=pa.float64())
   <pyarrow.lib.DoubleArray object at 0x127e5f1c0>
   [
     0.5,
     1
   ]
   >>> pa.array([np.float16(0.5), 1], type=pa.float32())
   <pyarrow.lib.FloatArray object at 0x103138460>
   [
     0.5,
     1
   ]
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to