This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 9f5a5c7d09 GH-48942: [Ruby] Add support for writing float32/64 arrays
(#48944)
9f5a5c7d09 is described below
commit 9f5a5c7d09974514881529c19e0c0d24e3e7717a
Author: Sutou Kouhei <[email protected]>
AuthorDate: Fri Jan 23 11:52:36 2026 +0900
GH-48942: [Ruby] Add support for writing float32/64 arrays (#48944)
### Rationale for this change
They are floating point array variants.
### What changes are included in this PR?
Add `ArrowFormat::FloatingPointType#to_flatbuffers`.
### Are these changes tested?
Yes.
### Are there any user-facing changes?
Yes.
* GitHub Issue: #48942
Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
ruby/red-arrow-format/lib/arrow-format/type.rb | 6 ++++++
ruby/red-arrow-format/test/test-writer.rb | 26 ++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/ruby/red-arrow-format/lib/arrow-format/type.rb
b/ruby/red-arrow-format/lib/arrow-format/type.rb
index 05f714edfa..7e863b0517 100644
--- a/ruby/red-arrow-format/lib/arrow-format/type.rb
+++ b/ruby/red-arrow-format/lib/arrow-format/type.rb
@@ -282,6 +282,12 @@ module ArrowFormat
super()
@precision = precision
end
+
+ def to_flatbuffers
+ fb_type = FB::FloatingPoint::Data.new
+ fb_type.precision = FB::Precision.try_convert(@precision.to_s.upcase)
+ fb_type
+ end
end
class Float32Type < FloatingPointType
diff --git a/ruby/red-arrow-format/test/test-writer.rb
b/ruby/red-arrow-format/test/test-writer.rb
index ad9efcef50..183329336e 100644
--- a/ruby/red-arrow-format/test/test-writer.rb
+++ b/ruby/red-arrow-format/test/test-writer.rb
@@ -38,6 +38,10 @@ module WriterTests
ArrowFormat::Int64Type.singleton
when Arrow::UInt64DataType
ArrowFormat::UInt64Type.singleton
+ when Arrow::FloatDataType
+ ArrowFormat::Float32Type.singleton
+ when Arrow::DoubleDataType
+ ArrowFormat::Float64Type.singleton
when Arrow::BinaryDataType
ArrowFormat::BinaryType.singleton
when Arrow::StringDataType
@@ -192,6 +196,28 @@ module WriterTests
end
end
+ sub_test_case("Float32") do
+ def build_array
+ Arrow::FloatArray.new([-0.5, nil, 0.5])
+ end
+
+ def test_write
+ assert_equal([-0.5, nil, 0.5],
+ @values)
+ end
+ end
+
+ sub_test_case("Float64") do
+ def build_array
+ Arrow::DoubleArray.new([-0.5, nil, 0.5])
+ end
+
+ def test_write
+ assert_equal([-0.5, nil, 0.5],
+ @values)
+ end
+ end
+
sub_test_case("Binary") do
def build_array
Arrow::BinaryArray.new(["Hello".b, nil, "World".b])