ronantakizawa/codereview-bench huggingface dataset:
Repository: apache/arrow
File: cpp/src/arrow/type_traits.h (C/C++)

Code before:
struct TypeTraits<DictionaryType> {
  using ArrayType = DictionaryArray;
  using ScalarType = DictionaryScalar;
  constexpr static bool is_parameter_free = false;
};

template <>
struct TypeTraits<ExtensionType> {
  using ArrayType = ExtensionArray;
  using ScalarType = ExtensionScalar;
  constexpr static bool is_parameter_free = false;
};
/// @}

/// \brief Create a data type instance from a type ID for parameter-free types
///
/// This function creates a data type instance for types that don't require
/// additional parameters (where TypeTraits<T>::is_parameter_free is true).
/// For types that require parameters (like TimestampType or ListType),
/// this function will return an error.
///
/// \param[in] id The type ID to create a type instance for
/// \return Result with a shared pointer to the created DataType instance,
///         or an error if the type requires parameters
ARROW_EXPORT
Result<std::shared_ptr<DataType>> type_singleton(Type::type id);

namespace internal {

template <typename... Ts>
struct make_void {
  using type = void;
};

template <typename... Ts>
using void_t = typename make_void<Ts...>::type;

}  // namespace internal

//
// Useful type predicates
//

/// \addtogroup type-predicates
/// @{

// only in C++14
template <bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;

template <typename T>

Review comment (suggestion):
I would put this in `type.h` since that's where data types constructors live.

Code after:
  using ScalarType = DictionaryScalar;
  constexpr static bool is_parameter_free = false;
};

template <>
struct TypeTraits<ExtensionType> {
  using ArrayType = ExtensionArray;
  using ScalarType = ExtensionScalar;
  constexpr static bool is_parameter_free = false;
};
/// @}

namespace internal {

template <typename... Ts>
struct make_void {
  using type = void;
};

template <typename... Ts>
using void_t = typename make_void<Ts...>::type;

}  // namespace internal

//
// Useful type predicates
//

/// \addtogroup type-predicates
/// @{

// only in C++14
template <bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;

template <typename T>
using is_null_type = std::is_same<NullType, T>;

template <typename T, typename R = void>
using enable_if_null = enable_if_t<is_null_type<T>::value, R>;

template <typename T>
using is_boolean_type = std::is_same<BooleanType, T>;

template <typename T, typename R = void>
using enable_if_boolean = enable_if_t<is_boolean_type<T>::value, R>;

template <typename T>
using is_number_type = std::is_base_of<NumberType, T>;

template <typename T, typename R = void>
Repository: apache/arrow
File: cpp/src/arrow/type.h (C/C++)

Code before:
ARROW_EXPORT
const std::vector<std::shared_ptr<DataType>>& TemporalTypes();
/// \brief Interval types
ARROW_EXPORT
const std::vector<std::shared_ptr<DataType>>& IntervalTypes();
/// \brief Duration types for each unit
ARROW_EXPORT
const std::vector<std::shared_ptr<DataType>>& DurationTypes();
/// \brief Numeric, base binary, date, boolean and null types
ARROW_EXPORT
const std::vector<std::shared_ptr<DataType>>& PrimitiveTypes();

/// \brief Decimal type ids
ARROW_EXPORT
const std::vector<Type::type>& DecimalTypeIds();

/// \brief Create a data type instance from a type ID for parameter-free types
///
/// This function creates a data type instance for types that don't require
/// additional parameters (where TypeTraits<T>::is_parameter_free is true).
/// For types that require parameters (like TimestampType or ListType),
/// this function will return an error.
///
/// \param[in] id The type ID to create a type instance for
/// \return Result with a shared pointer to the created DataType instance,
///         or an error if the type requires parameters
ARROW_EXPORT
Result<std::shared_ptr<DataType>> type_singleton(Type::type id);

}  // namespace arrow


Review comment (suggestion):
```suggestion
/// \param[in] id The type ID to create a type instance for
/// \return The type instance for the given type ID,
///         or a TypeError if the type requires parameters
```

Code after:
ARROW_EXPORT
const std::vector<std::shared_ptr<DataType>>& TemporalTypes();
/// \brief Interval types
ARROW_EXPORT
const std::vector<std::shared_ptr<DataType>>& IntervalTypes();
/// \brief Duration types for each unit
ARROW_EXPORT
const std::vector<std::shared_ptr<DataType>>& DurationTypes();
/// \brief Numeric, base binary, date, boolean and null types
ARROW_EXPORT
const std::vector<std::shared_ptr<DataType>>& PrimitiveTypes();

/// \brief Decimal type ids
ARROW_EXPORT
const std::vector<Type::type>& DecimalTypeIds();

/// \brief Create a data type instance from a type ID for parameter-free types
///
/// This function creates a data type instance for types that don't require
/// additional parameters (where TypeTraits<T>::is_parameter_free is true).
/// For types that require parameters (like TimestampType or ListType),
/// this function will return an error.
///
/// \param[in] id The type ID to create a type instance for
/// \return The type instance for the given type ID,
///         or a TypeError if the type requires parameters
ARROW_EXPORT
Result<std::shared_ptr<DataType>> type_singleton(Type::type id);

}  // namespace arrow
Repository: apache/arrow
File: cpp/src/arrow/type.cc (C++)

Code before:
  return g_primitive_types;
}

const std::vector<TimeUnit::type>& TimeUnit::values() {
  static std::vector<TimeUnit::type> units = {TimeUnit::SECOND, TimeUnit::MILLI,
                                              TimeUnit::MICRO, TimeUnit::NANO};
  return units;
}

const std::vector<Type::type>& DecimalTypeIds() {
  static std::vector<Type::type> type_ids = {Type::DECIMAL32, Type::DECIMAL64,
                                             Type::DECIMAL128, Type::DECIMAL256};
  return type_ids;
}

Result<std::shared_ptr<DataType>> type_singleton(Type::type id) {
  struct Visitor {
    Result<std::shared_ptr<DataType>> result;

    template <typename T>
    Status Visit(const T* type) {
      if constexpr (TypeTraits<T>::is_parameter_free) {
        result = TypeTraits<T>::type_singleton();
        return Status::OK();
      }
      return Status::TypeError("Type ", T::type_id, " is not a parameter-free singleton type.");
    }
  };

  Visitor visitor;
  RETURN_NOT_OK(VisitTypeIdInline(id, &visitor));
  return visitor.result;
}

}  // namespace arrow


Review comment (suggestion):
Small wording nit to make the error message more readable:
```suggestion
      return Status::TypeError("Type ", ToString(T::type_id), " is not a parameter-free type");
```

Code after:
  return g_primitive_types;
}

const std::vector<TimeUnit::type>& TimeUnit::values() {
  static std::vector<TimeUnit::type> units = {TimeUnit::SECOND, TimeUnit::MILLI,
                                              TimeUnit::MICRO, TimeUnit::NANO};
  return units;
}

const std::vector<Type::type>& DecimalTypeIds() {
  static std::vector<Type::type> type_ids = {Type::DECIMAL32, Type::DECIMAL64,
                                             Type::DECIMAL128, Type::DECIMAL256};
  return type_ids;
}

Result<std::shared_ptr<DataType>> type_singleton(Type::type id) {
  auto visit = [](auto type) -> Result<std::shared_ptr<DataType>> {
    using T = std::decay_t<decltype(*type)>;
    if constexpr (TypeTraits<T>::is_parameter_free) {
      return TypeTraits<T>::type_singleton();
    }
    return Status::TypeError("Type ", internal::ToString(T::type_id),
                             " is not a parameter-free type");
  };
  return VisitTypeId(id, visit);
}

}  // namespace arrow
Repository: apache/arrow
File: python/pyarrow/tests/parquet/test_basic.py (Python)

Code before:
    # Copy dataset dir (which should be just one file)
    corrupted_dir_path = tempdir / 'corrupted_dir'
    copytree(original_dir_path, corrupted_dir_path)
    # Corrupt just the one file with the dataset
    corrupted_file_path = corrupted_dir_path / original_path.name
    corrupted_file_path.write_bytes(bin_data)

    # Case 1: Reading the corrupted file with read_table() and without page
    # checksum verification succeeds but yields corrupted data
    table_corrupt = pq.read_table(corrupted_file_path,
                                  page_checksum_verification=False)
    # The read should complete without error, but the table has different
    # content than the original file!
    assert table_corrupt != table_orig
    assert table_corrupt == pa.table({'a': [1, 3, 2, 4]})

    # Case 2: Reading the corrupted file with read_table() and with page
    # checksum verification enabled raises an exception
    with pytest.raises(OSError, match="CRC checksum verification"):
        _ = pq.read_table(corrupted_file_path, page_checksum_verification=True)


@pytest.mark.parametrize(
    "source", ["/tmp/", ["/tmp/file1.parquet", "/tmp/file2.parquet"]])
def test_read_table_raises_value_error_when_ds_is_unavailable(
        monkeypatch, source):
    # GH-47728
    monkeypatch.setitem(sys.modules, "pyarrow.dataset", None)

    with pytest.raises(ValueError, match="the 'source' argument"):
        pq.read_table(source=source)


Review comment (suggestion):
```suggestion
def test_read_table_raises_value_error_when_ds_is_unavailable(monkeypatch, source):
```

Code after:
    # Copy dataset dir (which should be just one file)
    corrupted_dir_path = tempdir / 'corrupted_dir'
    copytree(original_dir_path, corrupted_dir_path)
    # Corrupt just the one file with the dataset
    corrupted_file_path = corrupted_dir_path / original_path.name
    corrupted_file_path.write_bytes(bin_data)

    # Case 1: Reading the corrupted file with read_table() and without page
    # checksum verification succeeds but yields corrupted data
    table_corrupt = pq.read_table(corrupted_file_path,
                                  page_checksum_verification=False)
    # The read should complete without error, but the table has different
    # content than the original file!
    assert table_corrupt != table_orig
    assert table_corrupt == pa.table({'a': [1, 3, 2, 4]})

    # Case 2: Reading the corrupted file with read_table() and with page
    # checksum verification enabled raises an exception
    with pytest.raises(OSError, match="CRC checksum verification"):
        _ = pq.read_table(corrupted_file_path, page_checksum_verification=True)


@pytest.mark.parametrize(
    "source", ["/tmp/", ["/tmp/file1.parquet", "/tmp/file2.parquet"]])
def test_read_table_raises_value_error_when_ds_is_unavailable(monkeypatch, source):
    # GH-47728
    monkeypatch.setitem(sys.modules, "pyarrow.dataset", None)

    with pytest.raises(ValueError, match="the 'source' argument"):
        pq.read_table(source=source)
Repository: apache/arrow
File: ruby/red-arrow-format/lib/arrow-format/array.rb (Ruby)

Code before:
  class UInt8Array < IntArray
    def to_a
      apply_validity(@values_buffer.values(:U8, 0, @size))
    end
  end

  class FloatingPointArray < Array
    def initialize(type, size, validity_buffer, values_buffer)
      super(type, size, validity_buffer)
      @values_buffer = values_buffer
    end
  end

  class Float32Array < FloatingPointArray
    def to_a
      apply_validity(@values_buffer.values(:f32, 0, @size))
    end
  end

  class Float64Array < FloatingPointArray
    def to_a
      apply_validity(@values_buffer.values(:f64, 0, @size))
    end
  end

  class TemporaryArray < Array
    def initialize(type, size, validity_buffer, values_buffer)
      super(type, size, validity_buffer)
      @values_buffer = values_buffer
    end
  end

  class DateArray < TemporaryArray
  end

  class Date32Array < DateArray
    def to_a
      apply_validity(@values_buffer.values(:s32, 0, @size))
    end
  end

  class Date64Array < DateArray
    def to_a
      apply_validity(@values_buffer.values(:s64, 0, @size))
    end
  end

  class TimeArray < TemporaryArray
  end

  class Time32Array < TimeArray

Review comment (suggestion):
Just interest. `Temporary` means temorary? (It mean this class name will change later)

Code after:
  class UInt8Array < IntArray
    def to_a
      apply_validity(@values_buffer.values(:U8, 0, @size))
    end
  end

  class FloatingPointArray < Array
    def initialize(type, size, validity_buffer, values_buffer)
      super(type, size, validity_buffer)
      @values_buffer = values_buffer
    end
  end

  class Float32Array < FloatingPointArray
    def to_a
      apply_validity(@values_buffer.values(:f32, 0, @size))
    end
  end

  class Float64Array < FloatingPointArray
    def to_a
      apply_validity(@values_buffer.values(:f64, 0, @size))
    end
  end

  class TemporalArray < Array
    def initialize(type, size, validity_buffer, values_buffer)
      super(type, size, validity_buffer)
      @values_buffer = values_buffer
    end
  end

  class DateArray < TemporalArray
  end

  class Date32Array < DateArray
    def to_a
      apply_validity(@values_buffer.values(:s32, 0, @size))
    end
  end

  class Date64Array < DateArray
    def to_a
      apply_validity(@values_buffer.values(:s64, 0, @size))
    end
  end

  class TimeArray < TemporalArray
  end

  class Time32Array < TimeArray
Repository: apache/arrow
File: c_glib/arrow-glib/compute.cpp (C++)

Code before:
 * There are many functions to compute data on an array.
 */

/**
 * garrow_compute_initialize:
 * @error: (nullable): Return location for a #GError or %NULL.
 *
 * You must call this explicitly before you use computation related
 * features.
 *
 * Returns: %TRUE if initializing the compute module completed successfully,
 *   %FALSE otherwise.
 *
 * Since: 21.0.0
 */
gboolean
garrow_compute_initialize(GError **error)
{
  auto status = arrow::compute::Initialize();
  return garrow::check(error, status, "[compute][initialize]");
}

typedef struct GArrowExecuteContextPrivate_
{
  arrow::compute::ExecContext context;
  std::shared_ptr<arrow::internal::ThreadPool> thread_pool;
} GArrowExecuteContextPrivate;

G_DEFINE_TYPE_WITH_PRIVATE(GArrowExecuteContext, garrow_execute_context, G_TYPE_OBJECT)

#define GARROW_EXECUTE_CONTEXT_GET_PRIVATE(object)                                       \
  static_cast<GArrowExecuteContextPrivate *>(                                            \
    garrow_execute_context_get_instance_private(GARROW_EXECUTE_CONTEXT(object)))

enum {
  PROP_THREAD_POOL = 1,
};

static void
garrow_execute_context_finalize(GObject *object)
{
  auto priv = GARROW_EXECUTE_CONTEXT_GET_PRIVATE(object);
  priv->context.~ExecContext();
  priv->thread_pool.~shared_ptr();
  G_OBJECT_CLASS(garrow_execute_context_parent_class)->finalize(object);
}

static void
garrow_execute_context_set_property(GObject *object,
                                    guint prop_id,
                                    const GValue *value,

Review comment (suggestion):
Let's use `GArrowThreadPool` here:

```suggestion
  GArrowThreadPool *thread_pool;
```

Code after:
 * There are many functions to compute data on an array.
 */

/**
 * garrow_compute_initialize:
 * @error: (nullable): Return location for a #GError or %NULL.
 *
 * You must call this explicitly before you use computation related
 * features.
 *
 * Returns: %TRUE if initializing the compute module completed successfully,
 *   %FALSE otherwise.
 *
 * Since: 21.0.0
 */
gboolean
garrow_compute_initialize(GError **error)
{
  auto status = arrow::compute::Initialize();
  return garrow::check(error, status, "[compute][initialize]");
}

struct GArrowExecuteContextPrivate
{
  std::shared_ptr<arrow::compute::ExecContext> context;
  GArrowExecutor *executor;
};

G_DEFINE_TYPE_WITH_PRIVATE(GArrowExecuteContext, garrow_execute_context, G_TYPE_OBJECT)

#define GARROW_EXECUTE_CONTEXT_GET_PRIVATE(object)                                       \
  static_cast<GArrowExecuteContextPrivate *>(                                            \
    garrow_execute_context_get_instance_private(GARROW_EXECUTE_CONTEXT(object)))

enum {
  PROP_EXECUTOR = 1,
};

static void
garrow_execute_context_dispose(GObject *object)
{
  auto priv = GARROW_EXECUTE_CONTEXT_GET_PRIVATE(object);

  if (priv->executor) {
    g_object_unref(priv->executor);
    priv->executor = nullptr;
  }

  G_OBJECT_CLASS(garrow_execute_context_parent_class)->dispose(object);
}
Repository: apache/arrow
File: c_glib/arrow-glib/executor.cpp (C++)

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

#include <arrow-glib/error.hpp>
#include <arrow-glib/executor.hpp>

G_BEGIN_DECLS

/**
 * SECTION: executor
 * @section_id: executor-classes
 * @title: Executor classes
 * @include: arrow-glib/arrow-glib.h
 *
 * #GArrowExecutor is the base class for executor implementations.
 * #GArrowThreadPool is a class for thread pool management.
 */

typedef struct GArrowExecutorPrivate_
{
  arrow::internal::Executor *executor;
} GArrowExecutorPrivate;

G_DEFINE_TYPE_WITH_PRIVATE(GArrowExecutor, garrow_executor, G_TYPE_OBJECT)

#define GARROW_EXECUTOR_GET_PRIVATE(obj)                                                 \
  static_cast<GArrowExecutorPrivate *>(                                                  \
    garrow_executor_get_instance_private(GARROW_EXECUTOR(obj)))

static void
garrow_executor_init(GArrowExecutor *object)
{
  auto priv = GARROW_EXECUTOR_GET_PRIVATE(object);
  priv->executor = nullptr;
}

static void
garrow_executor_class_init(GArrowExecutorClass *klass)
{
}

typedef struct GArrowThreadPoolPrivate_

Review comment (suggestion):
```suggestion
 * #GArrowExecutor is the base class for executor implementations.
 * 
```

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

#include <arrow-glib/error.hpp>
#include <arrow-glib/executor.hpp>

#include <arrow/util/thread_pool.h>

G_BEGIN_DECLS

/**
 * SECTION: executor
 * @section_id: executor-classes
 * @title: Executor classes
 * @include: arrow-glib/arrow-glib.h
 *
 * #GArrowExecutor is the base class for executor implementations.
 *
 * #GArrowThreadPool is a class for thread pool management.
 */

struct GArrowExecutorPrivate
{
  std::shared_ptr<arrow::internal::Executor> executor;
};

G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowExecutor, garrow_executor, G_TYPE_OBJECT)

#define GARROW_EXECUTOR_GET_PRIVATE(obj)                                                 \
  static_cast<GArrowExecutorPrivate *>(                                                  \
    garrow_executor_get_instance_private(GARROW_EXECUTOR(obj)))

enum {
  PROP_EXECUTOR = 1,
};

static void
garrow_executor_init(GArrowExecutor *object)
{
  auto priv = GARROW_EXECUTOR_GET_PRIVATE(object);
  new (&priv->executor) std::shared_ptr<arrow::internal::Executor>;
}
Repository: apache/arrow
File: c_glib/arrow-glib/executor.cpp (C++)

Code before:
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

#include <arrow-glib/error.hpp>
#include <arrow-glib/executor.hpp>

G_BEGIN_DECLS

/**
 * SECTION: executor
 * @section_id: executor-classes
 * @title: Executor classes
 * @include: arrow-glib/arrow-glib.h
 *
 * #GArrowExecutor is the base class for executor implementations.
 * #GArrowThreadPool is a class for thread pool management.
 */

typedef struct GArrowExecutorPrivate_
{
  arrow::internal::Executor *executor;
} GArrowExecutorPrivate;

G_DEFINE_TYPE_WITH_PRIVATE(GArrowExecutor, garrow_executor, G_TYPE_OBJECT)

#define GARROW_EXECUTOR_GET_PRIVATE(obj)                                                 \
  static_cast<GArrowExecutorPrivate *>(                                                  \
    garrow_executor_get_instance_private(GARROW_EXECUTOR(obj)))

static void
garrow_executor_init(GArrowExecutor *object)
{
  auto priv = GARROW_EXECUTOR_GET_PRIVATE(object);
  priv->executor = nullptr;
}

static void
garrow_executor_class_init(GArrowExecutorClass *klass)
{
}

typedef struct GArrowThreadPoolPrivate_
{
  std::shared_ptr<arrow::internal::ThreadPool> thread_pool;
} GArrowThreadPoolPrivate;

G_DEFINE_TYPE_WITH_PRIVATE(GArrowThreadPool, garrow_thread_pool, GARROW_TYPE_EXECUTOR)

#define GARROW_THREAD_POOL_GET_PRIVATE(obj)                                              \

Review comment (refactor):
```suggestion
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowExecutor, garrow_executor, G_TYPE_OBJECT)
```

Code after:
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

#include <arrow-glib/error.hpp>
#include <arrow-glib/executor.hpp>

#include <arrow/util/thread_pool.h>

G_BEGIN_DECLS

/**
 * SECTION: executor
 * @section_id: executor-classes
 * @title: Executor classes
 * @include: arrow-glib/arrow-glib.h
 *
 * #GArrowExecutor is the base class for executor implementations.
 *
 * #GArrowThreadPool is a class for thread pool management.
 */

struct GArrowExecutorPrivate
{
  std::shared_ptr<arrow::internal::Executor> executor;
};

G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowExecutor, garrow_executor, G_TYPE_OBJECT)

#define GARROW_EXECUTOR_GET_PRIVATE(obj)                                                 \
  static_cast<GArrowExecutorPrivate *>(                                                  \
    garrow_executor_get_instance_private(GARROW_EXECUTOR(obj)))

enum {
  PROP_EXECUTOR = 1,
};

static void
garrow_executor_init(GArrowExecutor *object)
{
  auto priv = GARROW_EXECUTOR_GET_PRIVATE(object);
  new (&priv->executor) std::shared_ptr<arrow::internal::Executor>;
}

static void
garrow_executor_finalize(GObject *object)
{
  auto priv = GARROW_EXECUTOR_GET_PRIVATE(object);
  priv->executor.~shared_ptr();
  G_OBJECT_CLASS(garrow_executor_parent_class)->finalize(object);