lidavidm commented on a change in pull request #11204:
URL: https://github.com/apache/arrow/pull/11204#discussion_r714135713



##########
File path: cpp/src/arrow/compute/kernels/aggregate_test.cc
##########
@@ -3447,5 +3447,55 @@ TEST(TestTDigestKernel, Options) {
               ResultWith(ArrayFromJSON(ty, "[null]")));
 }
 
+TEST(TestTDigestKernel, ApproximateMedian) {
+  // This is a wrapper for TDigest
+  for (const auto& ty : {float64(), int64(), uint16()}) {
+    ScalarAggregateOptions keep_nulls(/*skip_nulls=*/false, /*min_count=*/0);
+    ScalarAggregateOptions min_count(/*skip_nulls=*/true, /*min_count=*/3);
+    ScalarAggregateOptions keep_nulls_min_count(/*skip_nulls=*/false, 
/*min_count=*/3);
+
+    EXPECT_THAT(
+        CallFunction("approximate_median", {ArrayFromJSON(ty, "[1, 2, 3]")}, 
&keep_nulls),
+        ResultWith(ScalarFromJSON(float64(), "2.0")));
+    EXPECT_THAT(CallFunction("approximate_median", {ArrayFromJSON(ty, "[1, 2, 
3, null]")},
+                             &keep_nulls),
+                ResultWith(ScalarFromJSON(float64(), "null")));
+    EXPECT_THAT(
+        CallFunction("approximate_median", {ScalarFromJSON(ty, "1")}, 
&keep_nulls),
+        ResultWith(ScalarFromJSON(float64(), "1.0")));
+    EXPECT_THAT(
+        CallFunction("approximate_median", {ScalarFromJSON(ty, "null")}, 
&keep_nulls),
+        ResultWith(ScalarFromJSON(float64(), "null")));
+
+    EXPECT_THAT(CallFunction("approximate_median", {ArrayFromJSON(ty, "[1, 2, 
3, null]")},
+                             &min_count),
+                ResultWith(ScalarFromJSON(float64(), "2.0")));
+    EXPECT_THAT(CallFunction("approximate_median", {ArrayFromJSON(ty, "[1, 2, 
null]")},
+                             &min_count),
+                ResultWith(ScalarFromJSON(float64(), "null")));
+    EXPECT_THAT(CallFunction("approximate_median", {ScalarFromJSON(ty, "1")}, 
&min_count),
+                ResultWith(ScalarFromJSON(float64(), "null")));
+    EXPECT_THAT(
+        CallFunction("approximate_median", {ScalarFromJSON(ty, "null")}, 
&min_count),
+        ResultWith(ScalarFromJSON(float64(), "null")));
+
+    EXPECT_THAT(CallFunction("approximate_median", {ArrayFromJSON(ty, "[1, 2, 
3]")},
+                             &keep_nulls_min_count),
+                ResultWith(ScalarFromJSON(float64(), "2.0")));
+    EXPECT_THAT(CallFunction("approximate_median", {ArrayFromJSON(ty, "[1, 
2]")},
+                             &keep_nulls_min_count),
+                ResultWith(ScalarFromJSON(float64(), "null")));
+    EXPECT_THAT(CallFunction("approximate_median", {ArrayFromJSON(ty, "[1, 2, 
3, null]")},
+                             &keep_nulls_min_count),
+                ResultWith(ScalarFromJSON(float64(), "null")));
+    EXPECT_THAT(CallFunction("approximate_median", {ScalarFromJSON(ty, "1")},
+                             &keep_nulls_min_count),
+                ResultWith(ScalarFromJSON(float64(), "null")));
+    EXPECT_THAT(CallFunction("approximate_median", {ScalarFromJSON(ty, 
"null")},
+                             &keep_nulls_min_count),
+                ResultWith(ScalarFromJSON(float64(), "null")));
+  }
+}

Review comment:
       Yes, I added a set of cases for that as well.

##########
File path: docs/source/cpp/compute.rst
##########
@@ -188,39 +188,41 @@ Aggregations
 Scalar aggregations operate on a (chunked) array or scalar value and reduce
 the input to a single output value.
 
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| Function name | Arity | Input types      | Output type            | Options 
class                    | Notes |
-+===============+=======+==================+========================+==================================+=======+
-| all           | Unary | Boolean          | Scalar Boolean         | 
:struct:`ScalarAggregateOptions` | \(1)  |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| any           | Unary | Boolean          | Scalar Boolean         | 
:struct:`ScalarAggregateOptions` | \(1)  |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| count         | Unary | Any              | Scalar Int64           | 
:struct:`CountOptions`           | \(2)  |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| index         | Unary | Any              | Scalar Int64           | 
:struct:`IndexOptions`           |       |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| max           | Unary | Non-nested types | Scalar Input type      | 
:struct:`ScalarAggregateOptions` |       |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| mean          | Unary | Numeric          | Scalar Decimal/Float64 | 
:struct:`ScalarAggregateOptions` |       |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| min           | Unary | Non-nested types | Scalar Input type      | 
:struct:`ScalarAggregateOptions` |       |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| min_max       | Unary | Non-nested types | Scalar Struct          | 
:struct:`ScalarAggregateOptions` | \(3)  |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| mode          | Unary | Numeric          | Struct                 | 
:struct:`ModeOptions`            | \(4)  |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| product       | Unary | Numeric          | Scalar Numeric         | 
:struct:`ScalarAggregateOptions` | \(5)  |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| quantile      | Unary | Numeric          | Scalar Numeric         | 
:struct:`QuantileOptions`        | \(6)  |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| stddev        | Unary | Numeric          | Scalar Float64         | 
:struct:`VarianceOptions`        |       |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| sum           | Unary | Numeric          | Scalar Numeric         | 
:struct:`ScalarAggregateOptions` | \(5)  |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| tdigest       | Unary | Numeric          | Scalar Float64         | 
:struct:`TDigestOptions`         | \(7)  |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
-| variance      | Unary | Numeric          | Scalar Float64         | 
:struct:`VarianceOptions`        |       |
-+---------------+-------+------------------+------------------------+----------------------------------+-------+
++--------------------+-------+------------------+------------------------+----------------------------------+-------+
+| Function name      | Arity | Input types      | Output type            | 
Options class                    | Notes |
++====================+=======+==================+========================+==================================+=======+
+| all                | Unary | Boolean          | Scalar Boolean         | 
:struct:`ScalarAggregateOptions` | \(1)  |
++--------------------+-------+------------------+------------------------+----------------------------------+-------+
+| any                | Unary | Boolean          | Scalar Boolean         | 
:struct:`ScalarAggregateOptions` | \(1)  |
++--------------------+-------+------------------+------------------------+----------------------------------+-------+
+| approximate_median | Unary | Numeric          | Scalar Float64         | 
:struct:`TDigestOptions`         |       |

Review comment:
       Thanks, fixed.




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