pitrou commented on code in PR #46618:
URL: https://github.com/apache/arrow/pull/46618#discussion_r2120647616
##########
python/pyarrow/src/arrow/python/helpers.cc:
##########
@@ -73,21 +75,22 @@ std::shared_ptr<DataType> GetPrimitiveType(Type::type type)
{
}
}
-PyObject* PyHalf_FromHalf(npy_half value) {
- PyObject* result = PyArrayScalar_New(Half);
- if (result != NULL) {
- PyArrayScalar_ASSIGN(result, Half, value);
- }
- return result;
+PyObject* PyFloat_FromHalf(uint16_t value) {
+ // Convert the uint16_t Float16 value to a PyFloat object
+ arrow::util::Float16 half_val = arrow::util::Float16::FromBits(value);
+ return PyFloat_FromDouble(half_val.ToDouble());
}
-Status PyFloat_AsHalf(PyObject* obj, npy_half* out) {
- if (PyArray_IsScalar(obj, Half)) {
- *out = PyArrayScalar_VAL(obj, Half);
- return Status::OK();
+Result<uint16_t> PyFloat_AsHalf(PyObject* obj) {
+ if (PyFloat_Check(obj)) {
+ double float_val = static_cast<float>(PyFloat_AsDouble(obj));
Review Comment:
What is this casting to `float`?
--
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]