astropy / astropy/astropy

Replace `np.rollaxis()` with `np.moveaxis()` but it is not drop-in replacement

Open
#15,721 14 comments 0 reactions 0 assignees View on GitHub
Feature Request modeling Refactoring stats time
Dominant language
Python
Stars
5.3k
Forks
2.2k
Avg merge
1d 19h
Merged PRs (30d)
75

Description

NumPy documentation [recommends](https://numpy.org/doc/stable/reference/generated/numpy.rollaxis.html#numpy.rollaxis) using [`np.moveaxis()`](https://numpy.org/doc/stable/reference/generated/numpy.moveaxis.html) instead of [`np.rollaxis()`](https://numpy.org/doc/stable/reference/generated/numpy.rollaxis.html). Currently `astropy` uses `np.rollaxis()` more than `np.moveaxis()`, but there is no reason we should not follow NumPy's recommendation. The lines of code that call `np.rollaxis()` can be found with `git grep 'rollaxis('`. The following sub-packages need to be updated:

- [ ] `modeling` – some work completed, but [needs review](https://github.com/astropy/astropy/pull/15727#issuecomment-1855094364)
- [ ] `stats` – #15727
- [ ] `time` – #15727

Pull requests can replace `np.rollaxis()` with `np.moveaxis()` in one or more sub-packages.

Contributor guide

Open the contributing guide

Research direction

Start with `git grep 'rollaxis('` and inspect the remaining calls in the `modeling`, `stats`, and `time` sub-packages, along with the work and review discussion in PR #15727. Check each use against NumPy's `moveaxis` documentation and the relevant package tests; done means the targeted calls are updated without regressions.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.