Skip to content

BUG: Avoid NumPy 2 deprecation warning in __array_wrap__ #180657

Closed

Description

@seberg

🐛 Describe the bug

In NumPy 2, NumPy added a DeprecationWarning on __array_wrap__ to extend the information passed in and avoid an indefinite try/except chain.

This means that the e.g. the following gives a warning:

import warnings

import numpy as np
import torch

warnings.filterwarnings("error")  # with this an error

np.delete(torch.arange(10), 0)

Now, the solution is straight forward: Just add the two new arguments and ignore them.
(torch has no scalars, and the context is info that was always there and you don't need). That is __array_wrap__(obj, context=None, return_scalar=None).

I'll guess end-users use this path but because of how DeprecationWarnings work they won't actually see them normally, so it makes sense it wasn't spotted.
It would be nice to escalate the warning to something visible, but I would prefer if by that time torch has the fix.

Versions

current main.

cc @mruberry @rgommers

Activity

  1. added
    triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
    enhancementNot as big of a feature, but technically not a bug. Should be easy to fix
    module: numpyRelated to numpy support, and also numpy compatibility of our operators
    bot-triagedThis is a label only to be used by the auto triage bot
    on Apr 17, 2026
  2. ogulcanaydogan commented on Apr 28, 2026

    @ogulcanaydogan

    I'd like to work on this. The fix is straightforward: update __array_wrap__ in torch/_tensor.py to accept context=None, return_scalar=None and ignore them, suppressing the NumPy 2 deprecation warning.

  3. added
    bot-mislabeledIf you notice that the claude-bot mislabeled an issue
    and removed
    triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
    on Apr 28, 2026
  4. added
    triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
    on May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bot-mislabeledIf you notice that the claude-bot mislabeled an issuebot-triagedThis is a label only to be used by the auto triage botenhancementNot as big of a feature, but technically not a bug. Should be easy to fixmodule: deprecationmodule: numpyRelated to numpy support, and also numpy compatibility of our operatorstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions