Skip to content

BUG: NumPy 2.2.0rc1 import fails with PYTHONOPTIMIZE=2 #27866

Closed

Description

@tylerjereddy

A build failure was observed per scipy/scipy#21957 for this particular SciPy build incantation: python -m build --wheel --no-isolation -Ccompile-args=-j32

I bisected to the NumPy commit below. Is this a bug in NumPy or something we need to adjust downstream? @mhvk and @seberg were the PR reviewers.

b47bd25e3caba52321a6ba420650fc0eff97f473 is the first bad commit
commit b47bd25e3caba52321a6ba420650fc0eff97f473
Author: Clément Robert <[email protected]>
Date:   Fri Nov 22 11:56:31 2024 +0100

    API: register NEP 35 functions as array_functions (#27490)
    
    Register `like=` functions as array-functions.   This is currently decided based on finding the magic `${ARRAY_FUNCTION_LIKE}` string in the documentation.
    
    Close gh-27451

Activity

  1. tylerjereddy commented on Nov 26, 2024

    @tylerjereddy
    ContributorAuthor

    Whoa, my reproducer on x86_64 Linux is pretty simple with Python 3.10:

    import numpy as np

    pip install -U --pre numpy

    python probe.py

    Traceback (most recent call last):
      File "/home/treddy/rough_work/numpy/issue_27866/probe.py", line 1, in <module>
        import numpy as np
      File "/home/treddy/python_venvs/py_310_scipy/lib/python3.10/site-packages/numpy/__init__.py", line 114, in <module>
        from numpy.__config__ import show as show_config
      File "/home/treddy/python_venvs/py_310_scipy/lib/python3.10/site-packages/numpy/__config__.py", line 4, in <module>
        from numpy._core._multiarray_umath import (
      File "/home/treddy/python_venvs/py_310_scipy/lib/python3.10/site-packages/numpy/_core/__init__.py", line 74, in <module>
        from . import numeric
      File "/home/treddy/python_venvs/py_310_scipy/lib/python3.10/site-packages/numpy/_core/numeric.py", line 139, in <module>
        def ones(shape, dtype=None, order='C', *, device=None, like=None):
      File "/home/treddy/python_venvs/py_310_scipy/lib/python3.10/site-packages/numpy/_core/overrides.py", line 28, in finalize_array_function_like
        public_api.__doc__ = get_array_function_like_doc(public_api)
      File "/home/treddy/python_venvs/py_310_scipy/lib/python3.10/site-packages/numpy/_core/overrides.py", line 25, in get_array_function_like_doc
        return docstring.replace("${ARRAY_FUNCTION_LIKE}", array_function_like_doc)
    AttributeError: 'NoneType' object has no attribute 'replace'
    
  2. changed the title [-]BUG: SciPy build failure against NumPy 2.2.0rc1[/-] [+]BUG: SciPy build failure against NumPy 2.2.0rc1 (Python 3.10)[/+] on Nov 26, 2024
  3. tylerjereddy commented on Nov 27, 2024

    @tylerjereddy
    ContributorAuthor

    How strange, Ubuntu 22.04 seems common between my machine and the failing CI, but when I play with Python 3.10 on other Linux OS' I don't reproduce. Or maybe I'm just crazy, this is a weird one.

    Edit: to be clear, the problem seems to (amazingly, or is this some known thing??) simplify to a function with a docstring returning None for function._doc__ in the situations where I reproduce...

  4. mhvk commented on Nov 27, 2024

    @mhvk
    Contributor

    Might there be some hidden optimization option that removes docstrings (I vaguely recall -O does it?). Regardless, the code should not break on that...

  5. tylerjereddy commented on Nov 27, 2024

    @tylerjereddy
    ContributorAuthor

    Ah, that's a very reasonable guess, PYTHONOPTIMIZE=2 is only set in the SciPy CI for that one failing job.

    When I test locally, the one-line reproducer (import numpy as np) with NumPy main indeed passes in a clean environment with any supported Python version and fails consistently via i.e., PYTHONOPTIMIZE=2 python probe.py.

  6. changed the title [-]BUG: SciPy build failure against NumPy 2.2.0rc1 (Python 3.10)[/-] [+]BUG: NumPy 2.2.0rc1 import fails with PYTHONOPTIMIZE=2[/+] on Nov 27, 2024
  7. added this to the 2.2.0 release milestone on Nov 27, 2024
  8. rgommers commented on Nov 27, 2024

    @rgommers
    Member

    PYTHONOPTIMIZE=2 is only set in the SciPy CI for that one failing job.

    Apparently we have a CI coverage gap here. With the fix for this, we should add PYTHONOPTIMIZE=2 to one of the jobs in linux.yml.

    @neutrinoceros since this came from gh-27490, would you perhaps be able to have a look at fixing this issue?

  9. neutrinoceros commented on Nov 27, 2024

    @neutrinoceros
    Contributor

    Thanks for the ping Ralph. I got a fix ready in gh-27868

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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions