GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: np.vectorize appears to pass c types in numpy2.4 and 2.5 where previously it passed Python types · Issue #31770 · numpy/numpy

BUG: np.vectorize appears to pass c types in numpy2.4 and 2.5 where previously it passed Python types #31770

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
BUG: np.vectorize appears to pass c types in numpy2.4 and 2.5 where previously it passed Python types#31770
Copy link
Labels
00 - Bug

Description

@njr0
njr0
opened on Jun 26, 2026
Issue body actions

Describe the issue:

The test below passes under numpy 2.3 (and many previous versions of numpy) but fails under numpy 2.4 and 2.5. (I didn't use 2.4 till testing this.)

Previously, vectorize (in this case, at least), passed Python ints, whereas in 2.5 it is passing numpy raw values, (C types) that need .item() or whatever to convert to Python types. This broke my code.

There's nothing I can see in the 2.4 or 2.5 release notes, and this seems like a regression to me.

Here is the output under the three versions with the same Python 3.14 on MacOS 15.7.7 on an M1 Studio
(but also on ubuntu).

python3.14 test_np_24_25_vectorize.py
numpy version: 2.3.0
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK

Here it is on 2.4

$ python3.14 test_np_24_25_vectorize.py
numpy version: 2.4.0
FF
======================================================================
FAIL: testVectorizePassesPythonFloat (__main__.TestVectorizeTypes.testVectorizePassesPythonFloat)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/njr/python/artists/miro/test_np_24_25_vectorize.py", line 20, in testVectorizePassesPythonFloat
    self.assertEqual(seen[0], float,
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
                     'np.vectorize passed %s, expected float '
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     '(possible regression in numpy 2.4+)' % seen[0])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: <class 'numpy.float64'> != <class 'float'> : np.vectorize passed <class 'numpy.float64'>, expected float (possible regression in numpy 2.4+)

======================================================================
FAIL: testVectorizePassesPythonInt (__main__.TestVectorizeTypes.testVectorizePassesPythonInt)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/njr/python/artists/miro/test_np_24_25_vectorize.py", line 11, in testVectorizePassesPythonInt
    self.assertEqual(seen[0], int,
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
                     'np.vectorize passed %s, expected int '
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     '(possible regression in numpy 2.4+)' % seen[0])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: <class 'numpy.int32'> != <class 'int'> : np.vectorize passed <class 'numpy.int32'>, expected int (possible regression in numpy 2.4+)

----------------------------------------------------------------------
Ran 2 tests in 0.001s

FAILED (failures=2)

And here on 2.5

$ python3.14 test_np_24_25_vectorize.py
numpy version: 2.5.0
FF
======================================================================
FAIL: testVectorizePassesPythonFloat (__main__.TestVectorizeTypes.testVectorizePassesPythonFloat)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/njr/python/artists/miro/test_np_24_25_vectorize.py", line 20, in testVectorizePassesPythonFloat
    self.assertEqual(seen[0], float,
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
                     'np.vectorize passed %s, expected float '
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     '(possible regression in numpy 2.4+)' % seen[0])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: <class 'numpy.float64'> != <class 'float'> : np.vectorize passed <class 'numpy.float64'>, expected float (possible regression in numpy 2.4+)

======================================================================
FAIL: testVectorizePassesPythonInt (__main__.TestVectorizeTypes.testVectorizePassesPythonInt)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/njr/python/artists/miro/test_np_24_25_vectorize.py", line 11, in testVectorizePassesPythonInt
    self.assertEqual(seen[0], int,
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
                     'np.vectorize passed %s, expected int '
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     '(possible regression in numpy 2.4+)' % seen[0])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: <class 'numpy.int32'> != <class 'int'> : np.vectorize passed <class 'numpy.int32'>, expected int (possible regression in numpy 2.4+)

----------------------------------------------------------------------
Ran 2 tests in 0.001s

FAILED (failures=2)

Reproduce the code example:

import unittest
import numpy as np


class TestVectorizeTypes(unittest.TestCase):
    def testVectorizePassesPythonInt(self):
        seen = []
        np.vectorize(lambda x: seen.append(type(x)) or x)(
            np.array([1], dtype=np.int32)
        )
        self.assertEqual(seen[0], int,
                         'np.vectorize passed %s, expected int '
                         '(possible regression in numpy 2.4+)' % seen[0])

    def testVectorizePassesPythonFloat(self):
        seen = []
        np.vectorize(lambda x: seen.append(type(x)) or x)(
            np.array([1.0], dtype=np.float64)
        )
        self.assertEqual(seen[0], float,
                         'np.vectorize passed %s, expected float '
                         '(possible regression in numpy 2.4+)' % seen[0])


if __name__ == '__main__':
    print(f'numpy version: {np.__version__}')
    unittest.main()

Error message:

No numpy error.

Python and NumPy Versions:

2.3.0
3.14.6 (main, Jun 10 2026, 15:24:40) [Clang 17.0.0 (clang-1700.0.13.5)]


2.4.0
3.14.6 (main, Jun 10 2026, 15:24:40) [Clang 17.0.0 (clang-1700.0.13.5)]

2.5.0
3.14.6 (main, Jun 10 2026, 15:24:40) [Clang 17.0.0 (clang-1700.0.13.5)]

Runtime Environment:

No response

How does this issue affect you or how did you find it:

Running tests for my software with a newer versions of numpy.

Activity

  1. njr0
    added
    00 - Bug
    on Jun 26, 2026
  2. sahil-mangla commented on Jun 26, 2026

    @sahil-mangla
    sahil-mangla
    on Jun 26, 2026 · Hidden as low-quality
    show commentMore actions
  3. ngoldbaum commented on Jul 3, 2026

    @ngoldbaum
    ngoldbaum
    on Jul 3, 2026
    Member
    More actions

    So the behavior you're seeing in NumPy 2.3 is fallout from #28624.

    It was reverted in #29196, which was part of NumPy 2.3.1. I note that you are testing NumPy 2.3.0 and there were several 2.3.x bugfix releases you are missing in your test matrix. The NumPy 2.4 and 2.5 behavior is also identical to NumPy 1.26 through NumPy 2.2.

    I wrote an incorrect comment before this that I deleted, sorry for the noise!

  4. ngoldbaum
    closed this as not plannedon Jul 3, 2026
  5. njr0 commented on Jul 8, 2026

    @njr0
    njr0
    on Jul 8, 2026
    Author
    More actions

    Sure. It is possible my claim that this behaviour was in many previous versions is wrong. I have been using numpy for at least 18 years, but (thinking about it more carefully) I haven't used vectorize much, so maybe I only started when I was on 2.3. Apologies if I was mistaken. Thanks for looking at it @ngoldbaum.

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

    00 - Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.