Skip to content

BUG: Fix interaction between warnings and the promotion cache - #31617

Merged
ngoldbaum merged 4 commits into
numpy:mainfrom
ngoldbaum:fix-warn-twice
Jun 30, 2026
Merged

ngoldbaum merged 4 commits into
numpy:mainfrom
ngoldbaum:fix-warn-twice

Conversation

@ngoldbaum

@ngoldbaum ngoldbaum commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #31758

This fixes an issue that was introduced recently that causes duplicate warnings to be emitted for the integer/timedelta deprecation.

If accessing the promotion cache leads to a miss, the deprecation is emitted to fill the cache and then emitted again during type resolution.

This means warnings would sometimes be emitted twice.

The fix is to disable warnings when the promotion cache is filled. This happens using a new context variable. This is all happening outside the hot path for these operations so I'm not worried about performance.

I used Claude Fable to help investigate and fix this issue.

Ping @riku-sakamoto and @may12day since you were both involved in the PR that added these warnings.

@seberg seberg left a comment •

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.

The code looks fine and since we only fetch the context var when we would warn (and it is otherwise changed in promotion) it should also be fine.

That said, while I did think that a helper function would be far better, is it really worth to go through this trouble to avoid one duplicate warning here?
I guess some test order changes made them appear more in the test run?

NPY_NO_EXPORT int
npy_end_legacy_resolver_promotion(PyObject *token)
{
int result = PyContextVar_Reset(

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.

Ah, seems this works with an error in progress in practice (since I think we have debug python in CI).

This comment was marked as spam.

@charris

charris commented Jun 20, 2026

Copy link
Copy Markdown
Member

Doesn't look like a blocker, so pushing off to 2.5.1

@ngoldbaum

Copy link
Copy Markdown
Member Author

I'm going to merge with main, re-run CI, and merge this. While it does add quite a bit of complexity just to fix a flaky duplicate warning, I have a feeling that it may be useful in the future to have a context variable tracking whether or not the promotion cache is getting filled, so IMO it's worth it for that.

@ngoldbaum

Copy link
Copy Markdown
Member Author

Error: fatal: remote error: GitLab is currently unable to handle this request due to load (ID a13e8d9029e26c64-DFW).
Error: fatal: clone of 'https://gitlab.com/libeigen/eigen.git' into submodule path '/home/runner/work/numpy/numpy/ml_dtypes/third_party/eigen' failed

Well that's fun.

@ngoldbaum
ngoldbaum merged commit c06657a into numpy:main Jun 30, 2026
101 of 103 checks passed
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 2, 2026
@charris

charris commented Jul 2, 2026

Copy link
Copy Markdown
Member

@ngoldbaum I think there was something missing for this backport. It was a fairly complicated backport, I wonder if the problem was actually present in 2.5.0?

@seberg

seberg commented Jul 2, 2026

Copy link
Copy Markdown
Member

Yeah, you are right. It seems that this path had missed 2.5 (which doesn't seem like a big issue to me, probably have to take this a bit slow anyway).

@ngoldbaum

Copy link
Copy Markdown
Member Author

Oops, I'm sorry, I thought this had landed in 2.5!

MaanasArora pushed a commit to MaanasArora/numpy that referenced this pull request Jul 7, 2026
@charris charris added 09 - Backport-Candidate PRs tagged should be backported and removed 09 - Backport-Candidate PRs tagged should be backported labels Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TST: deprecation test failure because an operation raises two warnings, test expects one

4 participants