Copilot commented on code in PR #50459:
URL: https://github.com/apache/arrow/pull/50459#discussion_r3555837885


##########
ruby/red-arrow-format/test/test-day-time-interval-array.rb:
##########
@@ -0,0 +1,74 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestDayTimeIntervalArray < Test::Unit::TestCase
+  sub_test_case("#initialize") do
+    def test_no_null
+      values = [
+        [1, 100],
+        [3, 300],
+      ]
+      assert_equal(values,
+                   ArrowFormat::DayTimeIntervalArray.new(values).to_a)
+    end
+
+    def test_mixed
+      values = [
+        [1, 100],
+        nil,
+        [3, 300],
+      ]
+      assert_equal(values,
+                   ArrowFormat::DayTimeIntervalArray.new(values).to_a)
+    end
+  end
+
+  sub_test_case("#==") do
+    def test_no_slice
+      values = [
+        [1, 100],
+        nil,
+        [3, 300],
+      ]
+      array1 = ArrowFormat::DayTimeIntervalArray.new(values)
+      array2 = ArrowFormat::DayTimeIntervalArray.new(values)
+      assert_equal(array1, array2)
+    end
+
+    def test_sliced
+      values = [
+        [1, 100],
+        nil,
+        [3, 300],
+      ]
+      array1 = ArrowFormat::DayTimeIntervalArray.new(values)
+      array2 = ArrowFormat::DayTimeIntervalArray.new([nil, *values, nil])
+      assert_equal(array1, array2.slice(1, 3))
+    end
+
+    def test_sliced_different_content
+      values = [
+        [1, 100],
+        nil,
+        [3, 300],
+      ]
+      array1 = ArrowFormat::DayTimeIntervalArray.new(values)
+      array2 = ArrowFormat::DayTimeIntervalArray.new([nil, nil, *values, nil])
+      assert_not_equal(array1, array2.slice(1, 3))
+    end
+  end
+end

Review Comment:
   New functionality in this PR adds `DayTimeIntervalArray#each` and also adds 
hash-based packing support (`{day:, millisecond:}`), but there are no tests 
asserting `#each` yields the expected sequence (including nils) or that hash 
input round-trips correctly. Adding a focused test here would prevent 
regressions in both enumeration and packing.



##########
ruby/red-arrow-format/lib/arrow-format/array.rb:
##########
@@ -282,6 +282,10 @@ def build_data(data, type)
       buffer.freeze
       return n, validity_buffer, IO::Buffer.for(buffer)
     end
+
+    def pack_value(value, template)
+      [value || 0].pack(template)
+    end

Review Comment:
   `PrimitiveArray#pack_value` uses `value || 0`, which coerces `false` into 
`0`. That can silently turn invalid inputs into valid numeric values instead of 
raising, and can lead to hard-to-debug data corruption. Use an explicit `nil` 
check so only `nil` is converted to `0`.



##########
ruby/red-arrow-format/test/test-month-day-nano-interval-array.rb:
##########
@@ -0,0 +1,79 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestMonthDayNanoIntervalArray < Test::Unit::TestCase
+  sub_test_case("#initialize") do
+    def test_no_null
+      values = [
+        [1, 1, 100],
+        [3, 3, 300],
+      ]
+      assert_equal(values,
+                   ArrowFormat::MonthDayNanoIntervalArray.new(values).to_a)
+    end
+
+    def test_mixed
+      values = [
+        [1, 1, 100],
+        nil,
+        [3, 3, 300],
+      ]
+      assert_equal(values,
+                   ArrowFormat::MonthDayNanoIntervalArray.new(values).to_a)
+    end
+  end
+
+  sub_test_case("#==") do
+    def test_no_slice
+      values = [
+        [1, 1, 100],
+        nil,
+        [3, 3, 300],
+      ]
+      array1 = ArrowFormat::MonthDayNanoIntervalArray.new(values)
+      array2 = ArrowFormat::MonthDayNanoIntervalArray.new(values)
+      assert_equal(array1, array2)
+    end
+
+    def test_sliced
+      values = [
+        [1, 1, 100],
+        nil,
+        [3, 3, 300],
+      ]
+      array1 = ArrowFormat::MonthDayNanoIntervalArray.new(values)
+      array2 = ArrowFormat::MonthDayNanoIntervalArray.new([nil, *values, nil])
+      assert_equal(array1, array2.slice(1, 3))
+    end
+
+    def test_sliced_different_content
+      values = [
+        [1, 1, 100],
+        nil,
+        [3, 3, 300],
+      ]
+      array1 = ArrowFormat::MonthDayNanoIntervalArray.new(values)
+      array2 = ArrowFormat::MonthDayNanoIntervalArray.new([
+                                                            nil,
+                                                            nil,
+                                                            *values,
+                                                            nil,
+                                                          ])
+      assert_not_equal(array1, array2.slice(1, 3))
+    end
+  end
+end

Review Comment:
   New functionality in this PR adds `MonthDayNanoIntervalArray#each` and also 
adds hash-based packing support (`{month:, day:, nanosecond:}`), but there are 
no tests asserting `#each` yields the expected sequence (including nils) or 
that hash input round-trips correctly. Adding a focused test here would prevent 
regressions in both enumeration and packing.



-- 
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