Avoid the deprecated generic timedelta unit in test_subsecond_outputdt - #2824
Open
sujeito-operator wants to merge 1 commit into
Open
Conversation
elapsed_t and expected_t are timedelta64[ms] arrays, and assert_allclose evaluates `atol + rtol * abs(y)` internally, so the bare integer atol was being added to a timedelta64 -- numpy's deprecated 'generic' unit, which its own warning says will raise an error in a future release. Compare the millisecond counts as int64 instead, which keeps the 1-millisecond tolerance exactly rather than reinterpreting it. Contributes to Parcels-code#2682.
sujeito-operator
added a commit
to sujeito-operator/Parcels
that referenced
this pull request
Aug 14, 2026
sum() starts from the integer 0, so the first addition in maybe_convert_python_timedelta_to_numpy is `0 + np.timedelta64(...)` -- numpy's deprecated 'generic' timedelta unit. Raised from inside parcels.*, the "error:::parcels.*" filter escalates it and the except clause reports it as `Could not convert <timedelta> to np.timedelta64`. functools.reduce(operator.add, dts) adds the parts to each other with no integer start value, and reproduces the existing result units exactly -- a typed start for sum() would promote timedelta64[D] to the start's unit. Turns three existing tests in tests/utils/test_time.py green on numpy 2.5.2. Reported in Parcels-code#2824.
6 tasks
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.
Description
Contributes to #2682. Not marked as closing it — see the last paragraph.
I ran
pytest tests/onmainto see how much of the list in #2682 is still there.On numpy 2.5.2 / Python 3.12.3 it emits exactly 2 warnings, and both are the
same
DeprecationWarningraised from the same line oftests/test_particlefile.py.Every
FutureWarningin the list pasted in the issue is already gone.The one that is left:
elapsed_tandexpected_taretimedelta64[ms]arrays, andassert_allcloseevaluates
atol + rtol * abs(y)internally — so the bare integeratol=1is added to atimedelta64, which is the deprecated 'generic' unit. numpy says it "will raise an errorin the future", so this one is a test scheduled to break rather than noise.
This compares the millisecond counts as
int64, which keeps the 1-millisecond toleranceexactly as it is rather than reinterpreting it.
What I ran
pytest tests/onmainatc603cc3, unpatched:5 failed, 622 passed, 95 skipped, 10 xfailed, 2 warnings in 440.45s.4 failed, 623 passed, 95 skipped, 10 xfailed in 468.54s— 0 warnings, nowarnings summary section is printed at all.
-W error::DeprecationWarning:test_subsecond_outputdtfails on both parametrisations without this change and passes with it.
pytest tests/test_particlefile.py— 43 passed, 6 skipped, 2 xfailed.ruff format --checkandruff checkclean.The suite has 4 pre-existing failures on
mainin my environment, none of themchanged by this PR. The 5 → 4 above is not one of them being fixed: it is
tests/sgrid/test_accessor.py::test_assert_metadata_ds_consistency_dropped_dim, whichfailed in the first run and passed in the second with a hypothesis
FailedHealthCheck—"input generation is slow: Hypothesis only generated 9 valid inputs after 1.00 seconds" —
a statement about how fast this box is, not about the test.
test_fieldset_describe_backendsis an ImportError for an optional backend I do not have installed.
The other three are not unrelated, and that is the one thing here I would not want you
to miss. The three
test_maybe_convert_python_timedelta_to_numpycases fail on the samenumpy deprecation as the warning above — but reached from your own source, not from a test:
sum()starts from the integer0, so0 + timedelta64is the same deprecatedconversion. Because it is raised inside
parcels.*, the"error:::parcels.*"rule youalready have turns it into an error, the
except Exceptionaround it catches that, andthe user gets
ValueError: Could not convert datetime.timedelta(days=5) to np.timedelta64.CI on
mainis green today because it has not resolved to numpy 2.5.2 yet;numpy >=2.1.0has no upper bound, so it will. That one is a change to
src/, not to a test, so it isnot in this PR.
Deliberately not included
#2682 says that once the list is empty you can implement #2413 and fail on warnings.
#2413 is already closed as completed (2026-08-03), and
pyproject.tomlnow carries"error:::parcels.*"next to"error::UserWarning"— which is why this last one is stillonly a warning rather than a failure: it is attributed to
numpy/_core/numeric.py, not toa
parcels.*module, so neither of those rules matches it.Catching it by configuration instead would mean
"error::DeprecationWarning"globally.That is a wider net than #2413 cast — it turns any future upstream deprecation into a red
build on a schedule you would not be choosing — so it is your call rather than this PR's,
and
pyproject.tomlis untouched.And this is why I have not written "closes". "Two warnings" is a statement about numpy
2.5.2, Python 3.12.3 and the resolved versions in my environment, not about yours —
your June list was longer partly because of older xarray. If
pytest tests/is also cleanfor you after this, then #2682 can close on your side; if you still see others, then
this change is not enough on its own and the issue should stay open.
Checklist
mainfor normal development,v3-supportfor v3 support)AI Disclosure
wrote all of the above. It built a venv from source, ran the full suite on
maintoget the current warning list, traced the remaining one into
assert_allclose'satol + rtol * abs(y), made the change, re-ran the suite, and controlled it in bothdirections with
-W error::DeprecationWarning. Every count quoted above came fromrunning the suite rather than from reading it, and the one claim it could not make
from this box — that your environment is also down to zero — is the one it explicitly
did not make.