Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Add expiration notes for NumPy 2.0 removals #24518

Merged
merged 3 commits into from
Aug 24, 2023

Conversation

mtsokol
Copy link
Member

@mtsokol mtsokol commented Aug 24, 2023

Hi @rgommers @ngoldbaum,

This PR adds a separate file and a migration notes mechanism (similar to previously removed functionalities, like "financial") for NumPy 2.0 expired functions and aliases.

Here I add notes for items that have been removed in Part 1 and Part 2 (excluding some niche internal enums that didn't have a single usage in libraries such as SciPy or Pandas).

@mtsokol mtsokol changed the title MAINT: Add expiration notes for 2.0 removals MAINT: Add expiration notes for NumPy 2.0 removals Aug 24, 2023
@ngoldbaum
Copy link
Member

This looks great!

I noticed that the AttributeError gets converted into an unhelpful ImportError if you do e.g. from numpy import NINF:

In [2]: np.NINF
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 np.NINF

File ~/.pyenv/versions/3.10.9-debug/lib/python3.10/site-packages/numpy/__init__.py:349, in __getattr__(attr)
    346     raise AttributeError(__former_attrs__[attr])
    348 if attr in __expired_attributes__:
--> 349     raise AttributeError(
    350         f"`np.{attr}` was removed in NumPy 2.0 release. "
    351         f"{__expired_attributes__[attr]}"
    352     )
    354 raise AttributeError("module {!r} has no attribute "
    355                      "{!r}".format(__name__, attr))

AttributeError: `np.NINF` was removed in NumPy 2.0 release. Use `-np.inf` instead.

In [3]: from numpy import NINF
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[3], line 1
----> 1 from numpy import NINF

ImportError: cannot import name 'NINF' from 'numpy' (/home/nathan/.pyenv/versions/3.10.9-debug/lib/python3.10/site-packages/numpy/__init__.py)

I spent a little time today trying to figure out a way to get a nicer ImportError, and I don't think there is. I also asked on the Python discourse: https://discuss.python.org/t/module-level-getattr-and-from-imports/32236

If there's nothing we can do about the from imports, I think it's still a big improvement to include the AttributeError, since someone might subsequent check a direct attribute access trying to debug the ImportError.

numpy/__init__.py Outdated Show resolved Hide resolved
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
@mtsokol mtsokol requested a review from ngoldbaum August 24, 2023 18:36
@ngoldbaum
Copy link
Member

This looks good now, I think.

I'm going to propose a separate PR to generate better errors with from imports.

Thanks @mtsokol!

@ngoldbaum ngoldbaum merged commit 7057b2f into numpy:main Aug 24, 2023
54 of 56 checks passed
@mtsokol mtsokol deleted the introduce-expiration-notes branch August 24, 2023 20:46
@rgommers rgommers added this to the 2.0.0 release milestone Aug 25, 2023
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.

None yet

3 participants