Skip to content

Closes #5424: argsort to Series accessor - #5425

Merged
ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:5424_argsort_to_Series_accessor
Feb 23, 2026
Merged

ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:5424_argsort_to_Series_accessor

Conversation

@ajpotts

@ajpotts ajpotts commented Feb 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR introduces a new Series.ak.argsort() method that computes a
distributed permutation on the Arkouda server and returns the result as
an ArkoudaArray.

Unlike pandas.Series.argsort(), which returns a NumPy array and
materializes data locally, this accessor-based implementation preserves
Arkouda's distributed execution model and avoids unnecessary client-side
conversion.


Motivation

pandas.Series.argsort() returns a NumPy ndarray, even when the
Series is backed by an ArkoudaExtensionArray. This behavior is
consistent with pandas' ExtensionArray contract but forces
materialization of the permutation indices on the client.

For distributed workflows, this is undesirable. Users need a way to:

  • Compute sort permutations server-side
  • Avoid to_ndarray() materialization
  • Chain distributed operations such as take without leaving Arkouda

This PR provides that capability via the .ak accessor.


Changes

1. ArkoudaSeriesAccessor.argsort

Added:

Series.ak.argsort(
    *,
    ascending: bool = True,
    na_position: {"first", "last"} = "last",
) -> ArkoudaArray

Behavior:

  • Executes ak.argsort server-side
  • Supports ascending
  • Supports na_position for float pdarray
  • Returns a distributed ArkoudaArray
  • Raises:
    • TypeError for non-Arkouda-backed Series
    • ValueError for invalid na_position

2. Unit Tests

Added comprehensive tests covering:

  • Correct return type (ArkoudaArray)
  • Ascending and descending behavior
  • Float NaN handling (first / last)
  • String sorting
  • Invalid na_position
  • Non-Arkouda-backed Series error

Example

>>> import arkouda as ak
>>> import pandas as pd

>>> s = pd.Series([3.0, float("nan"), 1.0]).ak.to_ak()

>>> perm = s.ak.argsort()
>>> perm
ArkoudaArray([...])

>>> s.take(perm)   # stays distributed

Design Notes

This PR intentionally does not modify Series.argsort().

Maintaining pandas compatibility requires that the base method return a
NumPy indexer. The distributed behavior is therefore exposed explicitly
via the .ak accessor.

This separation keeps:

  • pandas behavior predictable
  • Arkouda fully distributed
  • The API explicit and unambiguous

Performance Impact

  • No client-side materialization
  • No additional memory pressure
  • Fully server-side permutation computation

Backwards Compatibility

  • No breaking API changes
  • New functionality exposed only via .ak accessor
  • Existing pandas semantics unchanged

Closes #5424: argsort to Series accessor

@ajpotts
ajpotts force-pushed the 5424_argsort_to_Series_accessor branch from d03ae3a to 0eed992 Compare February 20, 2026 22:30
@ajpotts
ajpotts requested a review from jaketrookman February 20, 2026 22:31
@ajpotts
ajpotts marked this pull request as ready for review February 20, 2026 23:50
@ajpotts
ajpotts marked this pull request as draft February 23, 2026 14:40
@ajpotts
ajpotts force-pushed the 5424_argsort_to_Series_accessor branch from 0eed992 to a657be3 Compare February 23, 2026 15:38
@ajpotts
ajpotts force-pushed the 5424_argsort_to_Series_accessor branch from a657be3 to bb0003d Compare February 23, 2026 15:47
@ajpotts
ajpotts marked this pull request as ready for review February 23, 2026 21:14

@jaketrookman jaketrookman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@ajpotts
ajpotts added this pull request to the merge queue Feb 23, 2026
Merged via the queue into Bears-R-Us:main with commit 3e81f02 Feb 23, 2026
19 checks passed
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.

argsort to Series accessor

2 participants