Align typing of dimension inputs
Open
Nobody has claimed this yet.
enhancement
needs discussion
topic-typing
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What is your issue?
Currently the input type for "one or more dims" is changing from function to function.
There are some open PRs that move to str | Iterable[Hashable] which allows the use of tuples as dimensions.
Some changes are still required:
- Accept None in all functions that accept dims as default, this would simplify typing alot (see https://github.com/pydata/xarray/pull/7048#discussion_r973813607)
- Check if we can always include ellipsis "..." in dim arguments (see https://github.com/pydata/xarray/pull/7048#pullrequestreview-1111498309)
-
Iterable[Hashable]includes sets, which do not preserve the ordering (see https://github.com/pydata/xarray/pull/6971#discussion_r981166670).
This means we need to distinguish between the cases where the order matters (constructor, transpose etc.) and where it does not (drop_dims, reductions etc.).
Probably this needs to be typed as astr | Sequence[Hashable](a numpy.ndarray is not a Sequence, but who uses this for dimensions anyway?).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the dim-accepting functions and the discussions linked from PRs 7048 and 6971 first. Determine where None and ellipsis should be accepted, and distinguish order-sensitive inputs from cases where sets are valid. Done means the typing and behavior are consistent across the affected functions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100