Copilot commented on code in PR #50433:
URL: https://github.com/apache/arrow/pull/50433#discussion_r3548995635
##########
ruby/red-arrow-format/lib/arrow-format/array.rb:
##########
@@ -64,18 +66,28 @@ def empty?
@size.zero?
end
+ def ==(other)
+ return false unless other.is_a?(self.class)
+ return false unless @size == other.size
+ return true if @validity_buffer.nil? and other.validity_buffer.nil?
+ if @offset == other.offset and @validity_buffer == other.validity_buffer
Review Comment:
`ArrowFormat::Array#==` currently only compares validity (and returns `true`
immediately when both `validity_buffer`s are `nil`). This makes many
non-primitive arrays compare equal even when their actual values differ (e.g.,
`VariableSizeBinaryArray`/`FixedSizeBinaryArray` store values in separate
buffers and do not override `==`; also `Readable#read_column` can pass
`validity=nil` when the IPC validity buffer length is zero). Consider
implementing `Array#each` and making `Array#==` compare element values
(subclasses like `PrimitiveArray`/`BooleanArray` already implement efficient
`each`).
##########
ruby/red-arrow-format/test/test-uint16-array.rb:
##########
@@ -0,0 +1,55 @@
+# 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 TestUInt16Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [0, (2 ** 16) - 1]
+ assert_equal(values,
+ ArrowFormat::UInt16Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [0, nil, (2 ** 16) - 1]
+ assert_equal(values,
+ ArrowFormat::UInt16Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [0, nil, (2 ** 16) - 1]
+ array1 = ArrowFormat::UInt16Array.new(values)
+ array2 = ArrowFormat::UInt16Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [0, nil, (2 ** 16) - 1]
+ array1 = ArrowFormat::UInt16Array.new(values)
+ array2 = ArrowFormat::UInt16Array.new([0] + values + [0])
+ assert_equal(array1, array2.slice(1, 3))
+ end
+
+ def test_sliced_diffrent_content
Review Comment:
Test name typo: `diffrent` → `different`.
--
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]