Repository navigation
Closes #4993: ArkoudaArray.argsort - #4999
Merged
Merged
Conversation
ajpotts
force-pushed
the
4993_ArkoudaArray.argsort
branch
from
October 15, 2025 16:25
6b356b2 to
35832f0
Compare
ajpotts
marked this pull request as ready for review
October 15, 2025 17:51
Contributor
|
Does it matter if Categorical adjusts for NA values? import arkouda as ak
from arkouda.pandas.categorical import Categorical
from arkouda.pandas.extension._arkouda_base_array import ArkoudaBaseArray
# ak.connect(server="localhost", port=5555) # if not already connected
# Step 1: build a categorical with valid codes
vals = ak.array(["b", "a", "c", "b"])
cat = Categorical(vals)
# Step 2: mutate a couple of codes to NA (use categories.size as the NA sentinel)
print("original codes:", cat.codes)
cat.codes[0] = cat.categories.size - 1 # first element -> NA
cat.codes[2] = cat.categories.size - 1 # third element -> NA
print("with NAs codes:", cat.codes)
# Optional: verify NA mask if available
if hasattr(cat, "isna"):
print("NA mask:", cat.isna())
# Step 3: wrap in extension array
ea = ArkoudaBaseArray(cat)
# Step 4: compare argsort permutations
perm_last = ea.argsort(ascending=True, na_position="last")
perm_first = ea.argsort(ascending=True, na_position="first")
print("perm_last :", perm_last)
print("perm_first:", perm_first)
print("identical?:", ak.all(perm_last == perm_first))
# Step 5: see the sorted values for reference
print("values (asc, last): ", cat[perm_last])
print("values (asc, first):", cat[perm_first])I feel like the docstring should mention that |
ajpotts
force-pushed
the
4993_ArkoudaArray.argsort
branch
from
October 16, 2025 18:10
35832f0 to
8db6b73
Compare
Contributor
Author
|
That's fair. Pandas has it's own way |
1RyanK
approved these changes
Oct 16, 2025
ajpotts
force-pushed
the
4993_ArkoudaArray.argsort
branch
2 times, most recently
from
October 17, 2025 18:31
30f7268 to
3ef014b
Compare
ajpotts
force-pushed
the
4993_ArkoudaArray.argsort
branch
from
October 17, 2025 19:00
3ef014b to
9ea74c3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add argsort to ArkoudaExtensionArray
Implements the ExtensionArray.argsort
API for Arkouda-backed arrays.
Summary
argsortimplementation toArkoudaBaseArray.pdarray,Strings, andCategoricaltypes.pdarray, and uses a# type: ignore[override]to ignorepandasandmypytype expectations. Pandas expects a NumPyndarrayto be returned.ascending,na_position, andkindarguments for API compatibility.Implementation Details
argsortto compute the permutation remotely.na_position("first" or "last").ValueErrorfor invalidna_positionvalues.TypeErrorfor unsupported underlying dtypes.pdarray, contrary to pandas expectation to return a NumPyndarray.Tests Added
test_argsort_extensionarray.py includes:
pdarraywith NaN handling (ascending / descending, first / last).StringsandCategoricalsorting correctness.na_positionand unsupported dtypes.kindand extrakwargsare accepted but ignored.Example
Why This Matters
This addition brings Arkouda’s pandas integration closer to parity with native
ExtensionArraybehavior.It enables pandas operations such as sorting and reindexing to function correctly on Arkouda-backed columns,
while keeping heavy data resident on the server for performance and scalability.
Closes #4993: ArkoudaArray.argsort