Skip to content

Drop support for numpy 1.x - #18986

Merged
mhvk merged 10 commits into
astropy:mainfrom
mhvk:drop-numpy-1.x
Jan 2, 2026
Merged

mhvk merged 10 commits into
astropy:mainfrom
mhvk:drop-numpy-1.x

Conversation

@mhvk

@mhvk mhvk commented Nov 24, 2025 •

Copy link
Copy Markdown
Contributor

This drops support for numpy < 2.0. It is in a few commits:

  1. Oversight from a long time ago.
  2. Drop numpy 1.25 (very few changes).
  3. Drop numpy 1.26 (lots of changes).
  4. Also remove COPY_IF_NEEDED, since it is now always just None (lots of changes).

EDIT: further commits
5. Bump other dependencies to the minimum needed for numpy >=2.0 support (inferred from numpy/numpy#26191)
6. Silence a weird RuntimeError (happens on main too with same python/numpy combo; see #18989.

In total ~500 lines changed and ~600 lines deleted, i.e., lots of compatibility work-arounds simplified.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@pllim

pllim commented Nov 24, 2025

Copy link
Copy Markdown
Member

@neutrinoceros neutrinoceros 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.

Here a complete review with a handful of nits, but overall nothing major to report.

Comment thread astropy/io/fits/hdu/hdulist.py Outdated
warnings.simplefilter("ignore", category=DeprecationWarning)
arr.data = self[idx].data.data
elif sys.getrefcount(arr) > 2:
if sys.getrefcount(arr) > 2:

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.

minor: we could now save one indentation level in what follows by using a single guard clause (if mmap is None or sys.getrefcount(arr) <= 2)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread astropy/table/tests/test_masked.py Outdated
Comment on lines +198 to +204
DTYPES_TEST_INIT = ["?", "b", "i2", "f4", "c8", "S", "U", "O"] + (
[ # new in numpy 2
np.dtypes.StrDType, # same as "U"
np.dtypes.BytesDType, # same as "S"
np.dtypes.StringDType,
]
)

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.

the extra parens are somewhat distracting and can be removed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done


if NUMPY_LT_2_4:
# np.in1d deprecated in not NUMPY_LT_2_0, removed in not NUMPY_LT_24
# np.in1d removed in not NUMPY_LT_24

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.

whoops

Suggested change
# np.in1d removed in not NUMPY_LT_24
# np.in1d removed in not NUMPY_LT_2_4

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rephrased as text, since it is now a simple if statement so no need for being greppable.

Comment thread astropy/units/quantity.py Outdated
obj = self.view(np.ndarray)
else:
obj = np.array(obj, copy=COPY_IF_NEEDED, subok=True)
obj = np.array(obj, copy=None, subok=True)

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.

for my own culture, is this any different than the following ?

Suggested change
obj = np.array(obj, copy=None, subok=True)
obj = np.asanyarray(obj, copy=None)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It it the same, but the np.array call used to be faster, since np.asanyarray would call np.array... But in trying to proof that, I found it has actually changed: np.asanyarray now is faster: with a plain array as input, which is most likely here, it is 75 vs 85 ns on my laptop, and down to 39 ns after removing copy=None (which is the default for np.asanyarray). So, I'm changing it!

Comment thread astropy/utils/masked/core.py Outdated
) = np.lib._function_base_impl._parse_gufunc_signature(
ufunc.signature.replace(" ", "")
)
(in_sig, out_sig) = np.lib._function_base_impl._parse_gufunc_signature(

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.

parens serve no purpose now

Suggested change
(in_sig, out_sig) = np.lib._function_base_impl._parse_gufunc_signature(
in_sig, out_sig = np.lib._function_base_impl._parse_gufunc_signature(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread pyproject.toml Outdated
# a direct dependency in order to set a lower bound for oldest-deps testing
"jupyter-core>=4.11.2",
"pandas>=2.0.2",
"pandas>=2.2.2", # minimum that supports numpy 2.0

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.

same here

Suggested change
"pandas>=2.2.2", # minimum that supports numpy 2.0
"pandas>=2.2.2",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, also done.

Comment thread pyproject.toml Outdated
"pyarrow>=14.0.2",
"beautifulsoup4>=4.9.3", # imposed by pandas==2.0
"h5py>=3.11.0", # older versions are not compatible with numpy 2.0
"pyarrow>=16.0", # older versions are not compatible with numpy 2.0

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.

Suggested change
"pyarrow>=16.0", # older versions are not compatible with numpy 2.0
"h5py>=3.11.0",
"pyarrow>=16.0",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK

Comment thread pyproject.toml Outdated
"mpmath>=1.2.1",
"asdf-astropy>=0.7.0",
"bottleneck>=1.3.3",
"bottleneck>=1.4.0", # minimum for numpy 2.0 compatibility

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.

Suggested change
"bottleneck>=1.4.0", # minimum for numpy 2.0 compatibility
"bottleneck>=1.4.0",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, those are indeed all in one commit, so easy enough to find if needed.

Comment thread pyproject.toml Outdated
Comment on lines +186 to +187
"pyarrow>=16.0", # minimum for numpy 2.0 support
"pandas>=2.2.2", # minimum for numpy 2.0 support

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.

Suggested change
"pyarrow>=16.0", # minimum for numpy 2.0 support
"pandas>=2.2.2", # minimum for numpy 2.0 support
"pyarrow>=16.0",
"pandas>=2.2.2",

Comment thread tox.ini Outdated

deps =
numpy125: numpy==1.25.*
numpy20: numpy==2.0.*

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.

I would actually suggest dropping this tox env now; I don't think it's used anywhere and it's not providing much value beyond oldestdeps

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, done -- there defintely are more than enough environments as is, and this one has outlived its purpose.

@neutrinoceros

Copy link
Copy Markdown
Contributor

Before I reviewed I also pushed a commit to change mpl380 to mpl384, but seeing that it makes for a more painful merge, I moved the commit to #19115

@pllim

pllim commented Jan 1, 2026

Copy link
Copy Markdown
Member

Would it help if I do the mpl384 bump as a standalone PR when I return?

@neutrinoceros

Copy link
Copy Markdown
Contributor

That's already the content of #19115, and yes, it can wait for you :)

1 similar comment
@neutrinoceros

This comment was marked as duplicate.

@pllim

pllim commented Jan 2, 2026 •

Copy link
Copy Markdown
Member

@neutrinoceros , is it possible to take this PR out commits out of #19115 then? mpl upgrade on CircleCI should be completely separable from numpy upgrade.

@neutrinoceros

Copy link
Copy Markdown
Contributor

Indeed. It'll create a couple trivial merge conflict but as long as it helps review, that's fine with me. Done.

@mhvk

mhvk commented Jan 2, 2026

Copy link
Copy Markdown
Contributor Author

@neutrinoceros - I implemented all your suggestions (all clear improvements), thanks!

@neutrinoceros neutrinoceros 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.

Thank you ! I trust you did go through all of them and I don't think I need a second full scan. Approving now !

@github-project-automation github-project-automation Bot moved this from Review in progress to Reviewer approved in Cosmology, the Expansion Jan 2, 2026
@mhvk

mhvk commented Jan 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, merging this...

@mhvk
mhvk merged commit 7f29b3e into astropy:main Jan 2, 2026
39 of 40 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewer approved to Done in Cosmology, the Expansion Jan 2, 2026
@mhvk
mhvk deleted the drop-numpy-1.x branch January 2, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

9 participants