Repository navigation
Fix #1153: return a view instead of setting ndarray.dtype (NumPy 2.5) - #1154
Open
panchangllc wants to merge 1 commit into
Open
panchangllc wants to merge 1 commit into
panchangllc wants to merge 1 commit into
Conversation
NumPy 2.5 deprecates setting an array's `dtype` attribute, so every find_discrete() call with a Boolean-valued function, like the one almanac.sunrise_sunset() returns, emitted a DeprecationWarning from _fix_numpy_deprecation(). Return `y.view(int8)` instead, which gives the same int8 values on old and new NumPy versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #1153.
NumPy 2.5 deprecates setting
ndarray.dtype._fix_numpy_deprecation()insearchlib.pydidy.dtype = int8, so everyfind_discrete()call with a Boolean-valued function, like the onealmanac.sunrise_sunset()returns, now emits aDeprecationWarning. UnderPYTHONWARNINGS=error, astest-code.shsets, that warning becomes an error.Change:
y = y.view(int8)replaces the assignment. It gives the same int8 values on old and new NumPy.yis always a fresh array here (y[indices],y[indices + 1],-y), so nothing depended on the old in-place change.Tests: two tests added to
skyfield/tests/test_searchlib.py. One checks_fix_numpy_deprecation()directly; the other checksfind_discrete()with a Boolean function.Checked locally, by running
assay --batch skyfield.testsfromci/withPYTHONWARNINGS=erroron Python 3.13 (assay does not import on Python 3.14):On 2.5.1 the six fewer failures are the two new tests plus
test_almanac::test_moon_nodes,test_almanac::test_sunrise_sunset_old,test_satellite_events::test_earth_satellite_pass_very_close_to_start_timeandtest_satellite_events::test_satellite_events_on_several_satellites. No test fails on this branch that passes on master.pyflakesis clean on both files.Not in this PR: NumPy 2.5 also deprecates setting
ndarray.shape. Most of the 38 remaining failures on 2.5.1 come from these lines:skyfield/functions.py:189and:194(_reconcile)skyfield/planetarylib.py:113and:120skyfield/keplerlib.py:613and:614I can send a separate PR for those if you'd like.
CHANGELOG.rstis not touched.🤖 Generated with Claude Code