From 0bec6724617ef7bc96c0e0867dcaa2153d23a254 Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Thu, 9 Jul 2026 14:34:51 +0100 Subject: [PATCH 1/2] Add float16 logic --- r/src/array_to_vector.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/r/src/array_to_vector.cpp b/r/src/array_to_vector.cpp index dc02c711d1e..8b617e6709d 100644 --- a/r/src/array_to_vector.cpp +++ b/r/src/array_to_vector.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -224,7 +225,11 @@ class Converter_Double : public Converter { } auto p_data = REAL(data) + start; auto ingest_one = [&](R_xlen_t i) { - p_data[i] = static_cast(p_values[i]); + if constexpr (std::is_same_v) { + p_data[i] = arrow::util::Float16::FromBits(p_values[i]).ToDouble(); + } else { + p_data[i] = static_cast(p_values[i]); + } return Status::OK(); }; auto null_one = [&](R_xlen_t i) { From defb6d1269e6bdc0cf0000872c2bd79d7bbe442d Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Thu, 9 Jul 2026 15:22:40 +0000 Subject: [PATCH 2/2] add float16 into tests --- r/src/r_to_arrow.cpp | 5 +++-- r/tests/testthat/test-chunked-array.R | 2 +- r/tests/testthat/test-dplyr-funcs-type.R | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/r/src/r_to_arrow.cpp b/r/src/r_to_arrow.cpp index cbe404aba96..9a26a2c3df7 100644 --- a/r/src/r_to_arrow.cpp +++ b/r/src/r_to_arrow.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include "./r_task_group.h" @@ -390,12 +391,12 @@ struct RConvert { return static_cast(from); } - // ---- convert to half float: not implemented + // ---- convert to half float template static enable_if_t::value, Result> Convert(Type*, From from) { - return Status::Invalid("Cannot convert to Half Float"); + return arrow::util::Float16(static_cast(from)).bits(); } }; diff --git a/r/tests/testthat/test-chunked-array.R b/r/tests/testthat/test-chunked-array.R index bcadaa889f9..74bc3f61d2a 100644 --- a/r/tests/testthat/test-chunked-array.R +++ b/r/tests/testthat/test-chunked-array.R @@ -17,7 +17,7 @@ int_types <- c(int8(), int16(), int32(), int64()) uint_types <- c(uint8(), uint16(), uint32(), uint64()) -float_types <- c(float32(), float64()) # float16() not really supported in C++ yet +float_types <- c(float16(), float32(), float64()) all_numeric_types <- c(int_types, uint_types, float_types) expect_chunked_roundtrip <- function(x, type) { diff --git a/r/tests/testthat/test-dplyr-funcs-type.R b/r/tests/testthat/test-dplyr-funcs-type.R index e2adf1de3ef..81e6f74ddba 100644 --- a/r/tests/testthat/test-dplyr-funcs-type.R +++ b/r/tests/testthat/test-dplyr-funcs-type.R @@ -31,7 +31,7 @@ test_that("explicit type conversions with cast()", { int_types <- c(int8(), int16(), int32(), int64()) uint_types <- c(uint8(), uint16(), uint32(), uint64()) - float_types <- c(float32(), float64()) + float_types <- c(float16(), float32(), float64()) types <- c( int_types,