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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import warnings

from ._globals import _NoValue, _CopyMode
from ._expired_attrs_2_0 import __expired_attributes__


# If a version with git hash was stored, use that instead
Expand Down Expand Up @@ -343,6 +344,12 @@ def __getattr__(attr):

if attr in __former_attrs__:
raise AttributeError(__former_attrs__[attr])

if attr in __expired_attributes__:
raise AttributeError(
f"`np.{attr}` was removed in the NumPy 2.0 release. "
f"{__expired_attributes__[attr]}"
)

raise AttributeError("module {!r} has no attribute "
"{!r}".format(__name__, attr))
Expand Down
30 changes: 30 additions & 0 deletions numpy/_expired_attrs_2_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Dict of expired attributes that are discontinued since 2.0 release.
Each item is associated with a migration note.
"""

__expired_attributes__ = {
"geterrobj": "Use the np.errstate context manager instead.",
"seterrobj": "Use the np.errstate context manager instead.",
"cast": "Use `np.asarray(arr, dtype=dtype)` instead.",
"source": "Use `inspect.getsource` instead.",
"lookfor": "Search NumPy's documentation directly.",
"who": "Use an IDE variable explorer or `locals()` instead.",
"fastCopyAndTranspose": "Use `arr.T.copy()` instead.",
"set_numeric_ops":
"For the general case, use `PyUFunc_ReplaceLoopBySignature`. "
"For ndarray subclasses, define the ``__array_ufunc__`` method "
"and override the relevant ufunc.",
"NINF": "Use `-np.inf` instead.",
"PINF": "Use `np.inf` instead.",
"NZERO": "Use `-0.0` instead.",
"PZERO": "Use `0.0` instead.",
"add_newdoc":
"It's an internal function and doesn't have a replacement.",
"add_docstring":
"It's an internal function and doesn't have a replacement.",
"add_newdoc_ufunc":
"It's an internal function and doesn't have a replacement.",
"compat": "There's no replacement, as Python 2 is no longer supported.",
"safe_eval": "Use `ast.literal_eval` instead."
}
1 change: 1 addition & 0 deletions numpy/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ python_sources = [
'_globals.py',
'_pytesttester.py',
'_pytesttester.pyi',
'_expired_attrs_2_0.py',
'conftest.py',
'ctypeslib.py',
'ctypeslib.pyi',
Expand Down
Loading