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 553cae3c02 GH-48511: [GLib][Ruby] Add WinsorizeOptions (#48532)
553cae3c02 is described below
commit 553cae3c02ee56e0f3f7b5829424bcdf6e5130fe
Author: Sten Larsson <[email protected]>
AuthorDate: Thu Jan 1 21:32:01 2026 +0100
GH-48511: [GLib][Ruby] Add WinsorizeOptions (#48532)
### Rationale for this change
The `WinsorizeOptions` class is not available in GLib/Ruby, and it is used
together with the `winsorize` compute function.
### What changes are included in this PR?
This adds the `WinsorizeOptions` class to GLib.
### Are these changes tested?
Yes, with Ruby unit tests.
### Are there any user-facing changes?
Yes, a new class.
* GitHub Issue: #48511
Authored-by: Sten Larsson <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
c_glib/arrow-glib/compute.cpp | 156 ++++++++++++++++++++++++++++++++++
c_glib/arrow-glib/compute.h | 16 ++++
c_glib/arrow-glib/compute.hpp | 5 ++
c_glib/test/test-winsorize-options.rb | 49 +++++++++++
4 files changed, 226 insertions(+)
diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp
index 6951ba480b..d292503d4d 100644
--- a/c_glib/arrow-glib/compute.cpp
+++ b/c_glib/arrow-glib/compute.cpp
@@ -334,6 +334,8 @@ G_BEGIN_DECLS
*
* #GArrowWeekOptions is a class to customize the `week` function.
*
+ * #GArrowWinsorizeOptions is a class to customize the `winsorize` function.
+ *
* There are many functions to compute data on an array.
*/
@@ -10232,6 +10234,136 @@ garrow_week_options_new(void)
return GARROW_WEEK_OPTIONS(g_object_new(GARROW_TYPE_WEEK_OPTIONS, nullptr));
}
+enum {
+ PROP_WINSORIZE_OPTIONS_LOWER_LIMIT = 1,
+ PROP_WINSORIZE_OPTIONS_UPPER_LIMIT,
+};
+
+G_DEFINE_TYPE(GArrowWinsorizeOptions,
+ garrow_winsorize_options,
+ GARROW_TYPE_FUNCTION_OPTIONS)
+
+static void
+garrow_winsorize_options_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ auto options =
garrow_winsorize_options_get_raw(GARROW_WINSORIZE_OPTIONS(object));
+
+ switch (prop_id) {
+ case PROP_WINSORIZE_OPTIONS_LOWER_LIMIT:
+ options->lower_limit = g_value_get_double(value);
+ break;
+ case PROP_WINSORIZE_OPTIONS_UPPER_LIMIT:
+ options->upper_limit = g_value_get_double(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_winsorize_options_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ auto options =
garrow_winsorize_options_get_raw(GARROW_WINSORIZE_OPTIONS(object));
+
+ switch (prop_id) {
+ case PROP_WINSORIZE_OPTIONS_LOWER_LIMIT:
+ g_value_set_double(value, options->lower_limit);
+ break;
+ case PROP_WINSORIZE_OPTIONS_UPPER_LIMIT:
+ g_value_set_double(value, options->upper_limit);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_winsorize_options_init(GArrowWinsorizeOptions *object)
+{
+ auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
+ priv->options = static_cast<arrow::compute::FunctionOptions *>(
+ new arrow::compute::WinsorizeOptions());
+}
+
+static void
+garrow_winsorize_options_class_init(GArrowWinsorizeOptionsClass *klass)
+{
+ auto gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->set_property = garrow_winsorize_options_set_property;
+ gobject_class->get_property = garrow_winsorize_options_get_property;
+
+ auto options = arrow::compute::WinsorizeOptions();
+
+ GParamSpec *spec;
+ /**
+ * GArrowWinsorizeOptions:lower-limit:
+ *
+ * The quantile below which all values are replaced with the quantile's
value.
+ * For example, if lower_limit = 0.05, then all values in the lower 5%
percentile
+ * will be replaced with the 5% percentile value.
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_double(
+ "lower-limit",
+ "Lower limit",
+ "The quantile below which all values are replaced with the quantile's
value. For "
+ "example, if lower_limit = 0.05, then all values in the lower 5%
percentile will be "
+ "replaced with the 5% percentile value",
+ 0.0,
+ 1.0,
+ options.lower_limit,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_WINSORIZE_OPTIONS_LOWER_LIMIT,
+ spec);
+
+ /**
+ * GArrowWinsorizeOptions:upper-limit:
+ *
+ * The quantile above which all values are replaced with the quantile's
value.
+ * For example, if upper_limit = 0.95, then all values in the upper 95%
percentile
+ * will be replaced with the 95% percentile value.
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_double(
+ "upper-limit",
+ "Upper limit",
+ "The quantile above which all values are replaced with the quantile's
value. For "
+ "example, if upper_limit = 0.95, then all values in the upper 95%
percentile will be "
+ "replaced with the 95% percentile value",
+ 0.0,
+ 1.0,
+ options.upper_limit,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_WINSORIZE_OPTIONS_UPPER_LIMIT,
+ spec);
+}
+
+/**
+ * garrow_winsorize_options_new:
+ *
+ * Returns: A newly created #GArrowWinsorizeOptions.
+ *
+ * Since: 23.0.0
+ */
+GArrowWinsorizeOptions *
+garrow_winsorize_options_new(void)
+{
+ return GARROW_WINSORIZE_OPTIONS(g_object_new(GARROW_TYPE_WINSORIZE_OPTIONS,
nullptr));
+}
+
G_END_DECLS
arrow::Result<arrow::FieldRef>
@@ -10502,6 +10634,11 @@ garrow_function_options_new_raw(const
arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::WeekOptions *>(arrow_options);
auto options = garrow_week_options_new_raw(arrow_week_options);
return GARROW_FUNCTION_OPTIONS(options);
+ } else if (arrow_type_name == "WinsorizeOptions") {
+ const auto arrow_winsorize_options =
+ static_cast<const arrow::compute::WinsorizeOptions *>(arrow_options);
+ auto options = garrow_winsorize_options_new_raw(arrow_winsorize_options);
+ return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
return GARROW_FUNCTION_OPTIONS(options);
@@ -11600,3 +11737,22 @@ garrow_week_options_get_raw(GArrowWeekOptions *options)
return static_cast<arrow::compute::WeekOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
+
+GArrowWinsorizeOptions *
+garrow_winsorize_options_new_raw(const arrow::compute::WinsorizeOptions
*arrow_options)
+{
+ auto options = g_object_new(GARROW_TYPE_WINSORIZE_OPTIONS,
+ "lower-limit",
+ arrow_options->lower_limit,
+ "upper-limit",
+ arrow_options->upper_limit,
+ nullptr);
+ return GARROW_WINSORIZE_OPTIONS(options);
+}
+
+arrow::compute::WinsorizeOptions *
+garrow_winsorize_options_get_raw(GArrowWinsorizeOptions *options)
+{
+ return static_cast<arrow::compute::WinsorizeOptions *>(
+ garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
+}
diff --git a/c_glib/arrow-glib/compute.h b/c_glib/arrow-glib/compute.h
index 78eba1de9a..2dff9eb509 100644
--- a/c_glib/arrow-glib/compute.h
+++ b/c_glib/arrow-glib/compute.h
@@ -1755,4 +1755,20 @@ GARROW_AVAILABLE_IN_23_0
GArrowWeekOptions *
garrow_week_options_new(void);
+#define GARROW_TYPE_WINSORIZE_OPTIONS (garrow_winsorize_options_get_type())
+GARROW_AVAILABLE_IN_23_0
+G_DECLARE_DERIVABLE_TYPE(GArrowWinsorizeOptions,
+ garrow_winsorize_options,
+ GARROW,
+ WINSORIZE_OPTIONS,
+ GArrowFunctionOptions)
+struct _GArrowWinsorizeOptionsClass
+{
+ GArrowFunctionOptionsClass parent_class;
+};
+
+GARROW_AVAILABLE_IN_23_0
+GArrowWinsorizeOptions *
+garrow_winsorize_options_new(void);
+
G_END_DECLS
diff --git a/c_glib/arrow-glib/compute.hpp b/c_glib/arrow-glib/compute.hpp
index 093449c130..a9acc529dc 100644
--- a/c_glib/arrow-glib/compute.hpp
+++ b/c_glib/arrow-glib/compute.hpp
@@ -328,3 +328,8 @@ GArrowWeekOptions *
garrow_week_options_new_raw(const arrow::compute::WeekOptions *arrow_options);
arrow::compute::WeekOptions *
garrow_week_options_get_raw(GArrowWeekOptions *options);
+
+GArrowWinsorizeOptions *
+garrow_winsorize_options_new_raw(const arrow::compute::WinsorizeOptions
*arrow_options);
+arrow::compute::WinsorizeOptions *
+garrow_winsorize_options_get_raw(GArrowWinsorizeOptions *options);
diff --git a/c_glib/test/test-winsorize-options.rb
b/c_glib/test/test-winsorize-options.rb
new file mode 100644
index 0000000000..3aa58f8683
--- /dev/null
+++ b/c_glib/test/test-winsorize-options.rb
@@ -0,0 +1,49 @@
+# 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 TestWinsorizeOptions < Test::Unit::TestCase
+ include Helper::Buildable
+
+ def setup
+ @options = Arrow::WinsorizeOptions.new
+ end
+
+ def test_lower_limit_property
+ assert_equal(0.0, @options.lower_limit)
+ @options.lower_limit = 0.05
+ assert_equal(0.05, @options.lower_limit)
+ end
+
+ def test_upper_limit_property
+ assert_equal(1.0, @options.upper_limit)
+ @options.upper_limit = 0.95
+ assert_equal(0.95, @options.upper_limit)
+ end
+
+ def test_winsorize_function
+ args = [
+ Arrow::ArrayDatum.new(build_double_array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
+10.0])),
+ ]
+ @options.lower_limit = 0.1
+ @options.upper_limit = 0.9
+ winsorize_function = Arrow::Function.find("winsorize")
+ result = winsorize_function.execute(args, @options).value
+ expected = build_double_array([2.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,
9.0, 9.0])
+ assert_equal(expected, result)
+ end
+end