Skip to content

Fix #1153: return a view instead of setting ndarray.dtype (NumPy 2.5) - #1154

Open
panchangllc wants to merge 1 commit into
skyfielders:masterfrom
panchangllc:fix-numpy-2.5-dtype-setter
Open

panchangllc wants to merge 1 commit into
skyfielders:masterfrom
panchangllc:fix-numpy-2.5-dtype-setter

Conversation

@panchangllc

Copy link
Copy Markdown

Fixes #1153.

NumPy 2.5 deprecates setting ndarray.dtype. _fix_numpy_deprecation() in searchlib.py did y.dtype = int8, so every find_discrete() call with a Boolean-valued function, like the one almanac.sunrise_sunset() returns, now emits a DeprecationWarning. Under PYTHONWARNINGS=error, as test-code.sh sets, that warning becomes an error.

Change: y = y.view(int8) replaces the assignment. It gives the same int8 values on old and new NumPy. y is 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 checks find_discrete() with a Boolean function.

Checked locally, by running assay --batch skyfield.tests from ci/ with PYTHONWARNINGS=error on Python 3.13 (assay does not import on Python 3.14):

NumPy master this branch
2.5.1 44 of 586 fail 38 of 586 fail
2.4.6 2 of 586 fail 2 of 586 fail (same two tests)

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_time and test_satellite_events::test_satellite_events_on_several_satellites. No test fails on this branch that passes on master. pyflakes is 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:189 and :194 (_reconcile)
  • skyfield/planetarylib.py:113 and :120
  • skyfield/keplerlib.py:613 and :614

I can send a separate PR for those if you'd like. CHANGELOG.rst is not touched.

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

find_discrete(): searchlib._fix_numpy_deprecation() sets ndarray.dtype, deprecated in NumPy 2.5

1 participant