ronantakizawa/codereview-bench huggingface dataset:
Repository: apache/arrow
File: ruby/red-arrow-format/test/test-file-reader.rb (Ruby)

Code before:
    end

    def test_read
      assert_equal([{"value" => [0, nil, 4294967295]}],
                   read)
    end
  end

  sub_test_case("Int64") do
    def build_array
      Arrow::Int64Array.new([
                              -9223372036854775808,
                              nil,
                              9223372036854775807
                            ])
    end

    def test_read
      assert_equal([{"value" => 
                      [
                        -9223372036854775808,
                        nil,
                        9223372036854775807
                      ]
                    }
                   ],
                   read)
    end
  end

  sub_test_case("UInt64") do
    def build_array
      Arrow::UInt64Array.new([0, nil, 18446744073709551615])
    end

    def test_read
      assert_equal([{"value" => [0, nil, 18446744073709551615]}],
                   read)
    end
  end

  sub_test_case("Float32") do
    def build_array
      Arrow::FloatArray.new([-0.5, nil, 0.5])
    end

    def test_read
      assert_equal([{"value" => [-0.5, nil, 0.5]}],
                   read)
    end
  end

Review comment (suggestion):
```suggestion
      assert_equal([
                     {
                       "value" => [
                         -9223372036854775808,
                         nil,
                         9223372036854775807
                       ]
                     }
                   ],
```

Code after:
    end

    def test_read
      assert_equal([{"value" => [0, nil, 4294967295]}],
                   read)
    end
  end

  sub_test_case("Int64") do
    def build_array
      Arrow::Int64Array.new([
                              -9223372036854775808,
                              nil,
                              9223372036854775807
                            ])
    end

    def test_read
      assert_equal([
                     {
                       "value" => [
                         -9223372036854775808,
                         nil,
                         9223372036854775807
                       ]
                     }
                   ],
                   read)
    end
  end

  sub_test_case("UInt64") do
    def build_array
      Arrow::UInt64Array.new([0, nil, 18446744073709551615])
    end

    def test_read
      assert_equal([{"value" => [0, nil, 18446744073709551615]}],
                   read)
    end
  end

  sub_test_case("Float32") do
    def build_array
      Arrow::FloatArray.new([-0.5, nil, 0.5])
    end

    def test_read
      assert_equal([{"value" => [-0.5, nil, 0.5]}],
                   read)
    end
Repository: apache/arrow
File: c_glib/test/test-list-flatten-options.rb (Ruby)

Code before:
    @options.recursive = true
    assert do
      @options.recursive?
    end
  end

  def test_list_flatten_function_recursive
    list_data_type = Arrow::ListDataType.new(Arrow::Field.new("value", Arrow::Int8DataType.new))
    nested_list = build_list_array(list_data_type, [[[1, 2], [3]], [[4, 5]]])

    args = [
      Arrow::ArrayDatum.new(nested_list),
    ]
    list_flatten_function = Arrow::Function.find("list_flatten")

    @options.recursive = false
    result = list_flatten_function.execute(args, @options).value
    assert_equal(list_data_type,
                 result.value_data_type)
    assert_equal(build_list_array(Arrow::Int8DataType.new, [[1, 2], [3], [4, 5]]),
                 result)

    @options.recursive = true
    result = list_flatten_function.execute(args, @options).value
    assert_equal(Arrow::Int8DataType.new,
                 result.value_data_type)
    assert_equal(build_int8_array([1, 2, 3, 4, 5]),
                 result)
  end
end


Review comment (suggestion):
This is redundant. `assert_equal(build_int8_array, result)` checks data type too.

```suggestion
```

Code after:
    @options.recursive = true
    assert do
      @options.recursive?
    end
  end

  def test_list_flatten_function_recursive
    list_data_type = Arrow::ListDataType.new(Arrow::Field.new("value", Arrow::Int8DataType.new))
    nested_list = build_list_array(list_data_type, [[[1, 2], [3]], [[4, 5]]])

    args = [
      Arrow::ArrayDatum.new(nested_list),
    ]
    list_flatten_function = Arrow::Function.find("list_flatten")

    @options.recursive = false
    result = list_flatten_function.execute(args, @options).value
    assert_equal(build_list_array(Arrow::Int8DataType.new, [[1, 2], [3], [4, 5]]),
                 result)

    @options.recursive = true
    result = list_flatten_function.execute(args, @options).value
    assert_equal(build_int8_array([1, 2, 3, 4, 5]),
                 result)
  end
end
Repository: apache/arrow
File: c_glib/arrow-glib/compute.cpp (C++)

Code before:
   * String to replace the slice with.
   *
   * Since: 23.0.0
   */
  spec = g_param_spec_string("replacement",
                             "Replacement",
                             "String to replace the slice with",
                             options.replacement.c_str(),
                             static_cast<GParamFlags>(G_PARAM_READWRITE));
  g_object_class_install_property(gobject_class,
                                  PROP_REPLACE_SLICE_OPTIONS_REPLACEMENT,
                                  spec);
}

/**
 * garrow_replace_slice_options_new:
 *
 * Returns: A newly created #GArrowReplaceSliceOptions.
 *
 * Since: 23.0.0
 */
GArrowReplaceSliceOptions *
garrow_replace_slice_options_new(void)
{
  return GARROW_REPLACE_SLICE_OPTIONS(
    g_object_new(GARROW_TYPE_REPLACE_SLICE_OPTIONS, NULL));
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
garrow_field_reference_resolve_raw(const gchar *reference)
{
  if (reference && (reference[0] == '.' || reference[0] == '[')) {
    return arrow::FieldRef::FromDotPath(reference);
  } else {
    arrow::FieldRef arrow_reference(reference);
    return arrow_reference;
  }
}

arrow::compute::ExecContext *
garrow_execute_context_get_raw(GArrowExecuteContext *context)
{
  auto priv = GARROW_EXECUTE_CONTEXT_GET_PRIVATE(context);
  return priv->context.get();
}

GArrowFunctionOptions *
garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_options)
{

Review comment (bug):
```suggestion
    g_object_new(GARROW_TYPE_REPLACE_SLICE_OPTIONS, nullptr));
```

Code after:
   * String to replace the slice with.
   *
   * Since: 23.0.0
   */
  spec = g_param_spec_string("replacement",
                             "Replacement",
                             "String to replace the slice with",
                             options.replacement.c_str(),
                             static_cast<GParamFlags>(G_PARAM_READWRITE));
  g_object_class_install_property(gobject_class,
                                  PROP_REPLACE_SLICE_OPTIONS_REPLACEMENT,
                                  spec);
}

/**
 * garrow_replace_slice_options_new:
 *
 * Returns: A newly created #GArrowReplaceSliceOptions.
 *
 * Since: 23.0.0
 */
GArrowReplaceSliceOptions *
garrow_replace_slice_options_new(void)
{
  return GARROW_REPLACE_SLICE_OPTIONS(
    g_object_new(GARROW_TYPE_REPLACE_SLICE_OPTIONS, nullptr));
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
garrow_field_reference_resolve_raw(const gchar *reference)
{
  if (reference && (reference[0] == '.' || reference[0] == '[')) {
    return arrow::FieldRef::FromDotPath(reference);
  } else {
    arrow::FieldRef arrow_reference(reference);
    return arrow_reference;
  }
}

arrow::compute::ExecContext *
garrow_execute_context_get_raw(GArrowExecuteContext *context)
{
  auto priv = GARROW_EXECUTE_CONTEXT_GET_PRIVATE(context);
  return priv->context.get();
}

GArrowFunctionOptions *
garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_options)
{
Repository: apache/arrow
File: c_glib/arrow-glib/compute.cpp (C++)

Code before:
GArrowPairwiseOptions *
garrow_pairwise_options_new_raw(const arrow::compute::PairwiseOptions *arrow_options)
{
  return GARROW_PAIRWISE_OPTIONS(
    g_object_new(GARROW_TYPE_PAIRWISE_OPTIONS, "periods", arrow_options->periods, NULL));
}

arrow::compute::PairwiseOptions *
garrow_pairwise_options_get_raw(GArrowPairwiseOptions *options)
{
  return static_cast<arrow::compute::PairwiseOptions *>(
    garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowReplaceSliceOptions *
garrow_replace_slice_options_new_raw(
  const arrow::compute::ReplaceSliceOptions *arrow_options)
{
  return GARROW_REPLACE_SLICE_OPTIONS(g_object_new(GARROW_TYPE_REPLACE_SLICE_OPTIONS,
                                                   "start",
                                                   arrow_options->start,
                                                   "stop",
                                                   arrow_options->stop,
                                                   "replacement",
                                                   arrow_options->replacement.c_str(),
                                                   NULL));
}

arrow::compute::ReplaceSliceOptions *
garrow_replace_slice_options_get_raw(GArrowReplaceSliceOptions *options)
{
  return static_cast<arrow::compute::ReplaceSliceOptions *>(
    garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}


Review comment (bug):
```suggestion
                                                   nullptr));
```

Code after:
GArrowPairwiseOptions *
garrow_pairwise_options_new_raw(const arrow::compute::PairwiseOptions *arrow_options)
{
  return GARROW_PAIRWISE_OPTIONS(
    g_object_new(GARROW_TYPE_PAIRWISE_OPTIONS, "periods", arrow_options->periods, NULL));
}

arrow::compute::PairwiseOptions *
garrow_pairwise_options_get_raw(GArrowPairwiseOptions *options)
{
  return static_cast<arrow::compute::PairwiseOptions *>(
    garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowReplaceSliceOptions *
garrow_replace_slice_options_new_raw(
  const arrow::compute::ReplaceSliceOptions *arrow_options)
{
  return GARROW_REPLACE_SLICE_OPTIONS(g_object_new(GARROW_TYPE_REPLACE_SLICE_OPTIONS,
                                                   "start",
                                                   arrow_options->start,
                                                   "stop",
                                                   arrow_options->stop,
                                                   "replacement",
                                                   arrow_options->replacement.c_str(),
                                                   nullptr));
}

arrow::compute::ReplaceSliceOptions *
garrow_replace_slice_options_get_raw(GArrowReplaceSliceOptions *options)
{
  return static_cast<arrow::compute::ReplaceSliceOptions *>(
    garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
Repository: apache/arrow
File: ruby/red-arrow-format/test/test-file-reader.rb (Ruby)

Code before:
                                ])
    end

    def test_read
      assert_equal([
                     {
                       "value" => [
                         @timestamp_2019_11_18_00_09_11,
                         nil,
                         @timestamp_2025_12_16_05_33_58,
                       ],
                     },
                   ],
                   read)
    end
  end

  sub_test_case("Timestamp(:microsecond)") do
    def setup(&block)
      @timestamp_2019_11_18_00_09_11 = 1574003351 * 1_000_000
      @timestamp_2025_12_16_05_33_58 = 1765863238 * 1_000_000
      super(&block)
    end

    def build_array
      Arrow::TimestampArray.new(:second,
                                [
                                  @timestamp_2019_11_18_00_09_11,
                                  nil,
                                  @timestamp_2025_12_16_05_33_58,
                                ])
    end

    def test_read
      assert_equal([
                     {
                       "value" => [
                         @timestamp_2019_11_18_00_09_11,
                         nil,
                         @timestamp_2025_12_16_05_33_58,
                       ],
                     },
                   ],
                   read)
    end
  end

  sub_test_case("Timestamp(:nanosecond)") do
    def setup(&block)
      @timestamp_2019_11_18_00_09_11 = 1574003351 * 1_000_000_000
      @timestamp_2025_12_16_05_33_58 = 1765863238 * 1_000_000_000

Review comment (suggestion):
```suggestion
      Arrow::TimestampArray.new(:micro,
```

Code after:
                                ])
    end

    def test_read
      assert_equal([
                     {
                       "value" => [
                         @timestamp_2019_11_18_00_09_11,
                         nil,
                         @timestamp_2025_12_16_05_33_58,
                       ],
                     },
                   ],
                   read)
    end
  end

  sub_test_case("Timestamp(:microsecond)") do
    def setup(&block)
      @timestamp_2019_11_18_00_09_11 = 1574003351 * 1_000_000
      @timestamp_2025_12_16_05_33_58 = 1765863238 * 1_000_000
      super(&block)
    end

    def build_array
      Arrow::TimestampArray.new(:micro,
                                [
                                  @timestamp_2019_11_18_00_09_11,
                                  nil,
                                  @timestamp_2025_12_16_05_33_58,
                                ])
    end

    def test_read
      assert_equal([
                     {
                       "value" => [
                         @timestamp_2019_11_18_00_09_11,
                         nil,
                         @timestamp_2025_12_16_05_33_58,
                       ],
                     },
                   ],
                   read)
    end
  end

  sub_test_case("Timestamp(:nanosecond)") do
    def setup(&block)
      @timestamp_2019_11_18_00_09_11 = 1574003351 * 1_000_000_000
      @timestamp_2025_12_16_05_33_58 = 1765863238 * 1_000_000_000
Repository: apache/arrow
File: ruby/red-arrow-format/test/test-file-reader.rb (Ruby)

Code before:
                                ])
    end

    def test_read
      assert_equal([
                     {
                       "value" => [
                         @timestamp_2019_11_18_00_09_11,
                         nil,
                         @timestamp_2025_12_16_05_33_58,
                       ],
                     },
                   ],
                   read)
    end
  end

  sub_test_case("Timestamp(:nanosecond)") do
    def setup(&block)
      @timestamp_2019_11_18_00_09_11 = 1574003351 * 1_000_000_000
      @timestamp_2025_12_16_05_33_58 = 1765863238 * 1_000_000_000
      super(&block)
    end

    def build_array
      Arrow::TimestampArray.new(:second,
                                [
                                  @timestamp_2019_11_18_00_09_11,
                                  nil,
                                  @timestamp_2025_12_16_05_33_58,
                                ])
    end

    def test_read
      assert_equal([
                     {
                       "value" => [
                         @timestamp_2019_11_18_00_09_11,
                         nil,
                         @timestamp_2025_12_16_05_33_58,
                       ],
                     },
                   ],
                   read)
    end
  end

  sub_test_case("Timestamp(timezone)") do
    def setup(&block)
      @timezone = "UTC"
      @timestamp_2019_11_18_00_09_11 = 1574003351

Review comment (suggestion):
```suggestion
      Arrow::TimestampArray.new(:nano,
```

Code after:
                                ])
    end

    def test_read
      assert_equal([
                     {
                       "value" => [
                         @timestamp_2019_11_18_00_09_11,
                         nil,
                         @timestamp_2025_12_16_05_33_58,
                       ],
                     },
                   ],
                   read)
    end
  end

  sub_test_case("Timestamp(:nanosecond)") do
    def setup(&block)
      @timestamp_2019_11_18_00_09_11 = 1574003351 * 1_000_000_000
      @timestamp_2025_12_16_05_33_58 = 1765863238 * 1_000_000_000
      super(&block)
    end

    def build_array
      Arrow::TimestampArray.new(:nano,
                                [
                                  @timestamp_2019_11_18_00_09_11,
                                  nil,
                                  @timestamp_2025_12_16_05_33_58,
                                ])
    end

    def test_read
      assert_equal([
                     {
                       "value" => [
                         @timestamp_2019_11_18_00_09_11,
                         nil,
                         @timestamp_2025_12_16_05_33_58,
                       ],
                     },
                   ],
                   read)
    end
  end

  sub_test_case("Timestamp(timezone)") do
    def setup(&block)
      @timezone = "UTC"
      @timestamp_2019_11_18_00_09_11 = 1574003351
Repository: apache/arrow
File: cpp/src/arrow/flight/sql/odbc/odbc_impl/type_fwd.h (C/C++)

Code before:
// 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.

#pragma once

namespace arrow::flight::sql::odbc {
class Statement;
class ResultSet;
class ResultSetMetadata;
}

// TODO: Replace ODBC namespace with namespace arrow::flight::sql::odbc #48083
namespace ODBC {
class ODBCEnvironment;
class ODBCDescriptor;
class ODBCStatement;
class ODBCConnection;
}


Review comment (suggestion):
```suggestion
// GH-48083 TODO: Replace ODBC namespace with namespace arrow::flight::sql::odbc
```
nit, we generally use `GH-xxxxx` for todo comments

Code after:
// 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.

#pragma once

namespace arrow::flight::sql::odbc {
class Statement;
class ResultSet;
class ResultSetMetadata;
}  // namespace arrow::flight::sql::odbc

// GH-48083 TODO: Replace ODBC namespace with namespace arrow::flight::sql::odbc
namespace ODBC {
class ODBCEnvironment;
class ODBCDescriptor;
class ODBCStatement;
class ODBCConnection;
}  // namespace ODBC
Repository: apache/arrow
File: ci/scripts/python_test_type_annotations.sh (Shell)

Code before:
#!/usr/bin/env bash
#
# 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.

set -ex
pyarrow_dir=${1}

if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then
  # Install library stubs
  pip install pandas-stubs scipy-stubs sphinx types-cffi types-psutil types-requests types-python-dateutil

  # Install type checkers
  pip install mypy pyright ty

  # Install other dependencies for type checking
  pip install fsspec

  # Run type checkers
  pushd ${pyarrow_dir}
  mypy
  pyright
  ty check;
else
  echo "Skipping type annotation tests";
fi


Review comment (performance):
I think I understand why pandas stubs (and some others) are needed for testing. But am not sure about scipy and sphinx, for example. Could you help me understand? Thanks!

(in any case, stubs are probably not "expensive" dependencies?)

Code after:
#!/usr/bin/env bash
#
# 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.

set -ex
pyarrow_dir=${1}

if [ -n "${ARROW_PYTHON_VENV:-}" ]; then
  # shellcheck source=/dev/null
  . "${ARROW_PYTHON_VENV}/bin/activate"
fi

# Install library stubs. Note some libraries contain their own type hints so they need to be installed.
pip install fsspec pandas-stubs scipy-stubs types-cffi types-psutil types-requests types-python-dateutil

# Install type checkers
pip install mypy pyright ty

# Run type checkers
cd "${pyarrow_dir}"
mypy
pyright
ty check