Skip to content

[Repo Assist] Add Series.rank, Series.rankWith, Series.ntile and Frame.rankRowsBy#636

Merged
dsyme merged 3 commits intomasterfrom
repo-assist/feature-issue-372-rank-ntile-d6260d8addf1d344
Mar 18, 2026
Merged

[Repo Assist] Add Series.rank, Series.rankWith, Series.ntile and Frame.rankRowsBy#636
dsyme merged 3 commits intomasterfrom
repo-assist/feature-issue-372-rank-ntile-d6260d8addf1d344

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Repo Assist — automated PR implementing the feature requested in issue #372.

Closes #372


What this adds

API Description
Series.rank 1-based dense rank (SQL-style). Smallest value → rank 1; ties share the same rank.
Series.rankWith Dense rank with a custom comparison function.
Series.ntile n Divides values into n equal-sized buckets numbered 0 … n-1. Earlier buckets get one extra element when not evenly divisible.
Frame.rankRowsBy colKey Ranks frame rows by the values in the named column; returns a Series(rowKey, int).

C# extension methods (Rank, RankWith, Ntile, RankRowsBy) are provided in the corresponding *Extensions.fs files.

Usage examples

// Dense rank
let ages = series ["alice" => 30.0; "bob" => 25.0; "carol" => 30.0; "dave" => 20.0]
ages |> Series.rank
// dave→1, bob→2, alice→3, carol→3

// Ntile into 3 equal buckets
ages |> Series.ntile 3
// dave→0, bob→0, alice→1, carol→2  (or similar, by sorted position)

// Add a rank column to a frame
let df = frame [ "age" => ages ]
df.AddColumn("rank", df |> Frame.rankRowsBy "age")

Design notes

  • Missing values are propagated as missing in the output (not ranked).
  • Series.rank uses Map<'V, int> for O(n log n) lookup.
  • Series.rankWith walks a sorted array; lookup is O(n) per element (acceptable for typical series sizes; the common numeric use-case should use Series.rank).
  • Series.ntile sorts by value via Seq.sortBy snd on observations, so only present values are bucketed.

Test status

All 616 existing tests pass. Eight new tests were added:

  • Series.fs: rank basic, rank with ties, rank with missing values, rank with custom comparator, ntile equal buckets, ntile uneven buckets
  • Frame.fs: rank rows by column, rank and add as column

Generated by Repo Assist for issue #372 ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@30f2254f2a7a944da1224df45d181a3f8faefd0d

Implements the feature requested in issue #372 (dense rank / ntile).

- Series.rank: 1-based dense rank using default comparison; ties share same rank
- Series.rankWith: dense rank with a custom comparison function
- Series.ntile: divides values into N equal-sized buckets (0-based)
- Frame.rankRowsBy: rank frame rows by a named column (returns a Series)
- C# extension methods for all three Series operations and Frame.RankRowsBy
- Tests covering basic rank, ties, missing values, custom comparator, ntile
  with even and uneven bucket sizes, and adding a rank column to a frame

Co-authored-by: Copilot <[email protected]>
@dsyme dsyme marked this pull request as ready for review March 18, 2026 15:14
@dsyme dsyme merged commit 72e34e3 into master Mar 18, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/feature-issue-372-rank-ntile-d6260d8addf1d344 branch March 18, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement dense rank a la SQL or SAS

1 participant