pydata / pydata/xarray

DataArray.argsort should be deleted

Open
#1,635 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

design question
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

Originally posted to https://groups.google.com/forum/#!topic/xarray/wsxeiIPLhgM

DataArray.argsort() appears to simply wrap the result of DataArray.values.argsort() in a same-shape DataArray. This is semantically nonsensical. If anything the index on the resulting argsort() values should simply be range(len(da)), but that adds little to the underlying numpy structure. And there's not much reason to have da.argsort() simply return the (raw) result of da.values.argsort(). So really DataArray.argsort() should simply be deleted.

On the other hand a new function DataArray.rank() that wraps da.values.argsort().argsort() (note repeated call to ndarray.argsort()) in the structure of the original DataArray would make sense, and perhaps even be useful... (Note that I'm not claiming that .argsort().argsort() is the fastest way to calculate this, but it's probably good enough, at least for an initial implementation.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the DataArray.argsort implementation and its tests, then read the issue discussion linked from the original report. Confirm whether the requested removal is still appropriate and whether the proposed DataArray.rank addition is in scope; done means the agreed API behavior is reflected in the implementation and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.