Skip to content

[DF] Add median support for RDataFrame - #23079

Open
ArjunXvarma wants to merge 6 commits into
root-project:masterfrom
ArjunXvarma:df-median
Open

[DF] Add median support for RDataFrame#23079
ArjunXvarma wants to merge 6 commits into
root-project:masterfrom
ArjunXvarma:df-median

Conversation

@ArjunXvarma

@ArjunXvarma ArjunXvarma commented Aug 15, 2026

Copy link
Copy Markdown

This Pull request:

Changes or fixes:

Adds a Median action to RDataFrame, computing the exact median of a column.

Draft - implementation is working; Google Test coverage and doxygen documentation still to come.

Implemented as a MedianHelper in ActionHelpers.hxx following the structure of MeanHelper:
values are buffered per slot in Exec (with an IsDataContainer overload for collection columns),
and Finalize merges the per-slot buffers and uses std::nth_element to select the middle
element. Even entry counts return the average of the two middle values.

Scope, per the discussion in the issue: exact mode only. GetMergeableValue is not implemented,
so distributed execution is not supported - a median cannot be merged from a summary the way
RMergeableMean merges (mean, count), so that deserves separate discussion. Memory cost is
O(N) doubles, which is inherent to an exact result.

Manually verified so far via the templated and jitted C++ paths, from Python, on RVec columns,
and with implicit multithreading enabled.

Checklist:

  • tested changes locally
  • updated the docs
  • added tests

This PR is part of #22794

Arjun Varma added 4 commits August 17, 2026 15:39
Cover the Median action in the existing action-API tests for scalar and
collection columns, and add dedicated cases for:

- odd and even numbers of entries, with distinct middle values to check
  that the two central values are averaged
- empty datasets for both scalar and collection columns, which return
NaN
- a skewed distribution in the multithreaded test fixture, verifying
that
  per-slot buffers are merged correctly
- cloning the action via MakeNew, checking that the original and the
clone
  both produce the correct result within a single event loop

Each case uses data where the mean and median differ, so a regression
cannot pass by coincidence.
@ArjunXvarma
ArjunXvarma marked this pull request as ready for review August 17, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants