-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAINT: Backport numpy._core stubs. Remove NumpyUnpickler
- Loading branch information
Showing
18 changed files
with
87 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
`numpy.lib.format.NumpyUnpickler` | ||
--------------------------------- | ||
`numpy._core` submodules' stubs | ||
------------------------------- | ||
|
||
`numpy.lib.format.NumpyUnpickler` class was added | ||
that provides a stable way for loading pickled arrays, | ||
`numpy._core` submodules' stubs were added | ||
to provide a stable way for loading pickled arrays, | ||
created with NumPy 2.0, with Numpy 1.26. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
""" | ||
This private module only contains stubs for interoperability with | ||
NumPy 2.0 pickled arrays. It may not be used by the end user. | ||
""" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from numpy.core import _dtype | ||
|
||
_globals = globals() | ||
|
||
for item in _dtype.__dir__(): | ||
_globals[item] = getattr(_dtype, item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from numpy.core import _dtype_ctypes | ||
|
||
_globals = globals() | ||
|
||
for item in _dtype_ctypes.__dir__(): | ||
_globals[item] = getattr(_dtype_ctypes, item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from numpy.core import _internal | ||
|
||
_globals = globals() | ||
|
||
for item in _internal.__dir__(): | ||
_globals[item] = getattr(_internal, item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from numpy.core import _multiarray_umath | ||
|
||
_globals = globals() | ||
|
||
for item in _multiarray_umath.__dir__(): | ||
_globals[item] = getattr(_multiarray_umath, item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from numpy.core import multiarray | ||
|
||
_globals = globals() | ||
|
||
for item in multiarray.__dir__(): | ||
_globals[item] = getattr(multiarray, item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from numpy.core import umath | ||
|
||
_globals = globals() | ||
|
||
for item in umath.__dir__(): | ||
_globals[item] = getattr(umath, item) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from os import path | ||
import pickle | ||
|
||
import numpy as np | ||
|
||
|
||
def test_importable__core_stubs(): | ||
""" | ||
Checks if stubs for `numpy._core` are importable. | ||
""" | ||
from numpy._core.multiarray import _reconstruct | ||
from numpy._core.umath import cos | ||
from numpy._core._multiarray_umath import exp | ||
from numpy._core._internal import ndarray | ||
from numpy._core._dtype import _construction_repr | ||
from numpy._core._dtype_ctypes import dtype_from_ctypes_type | ||
|
||
|
||
def test_unpickle_numpy_2_0_pickle(): | ||
""" | ||
Checks that NumPy 1.26 is able to load pickles created with | ||
NumPy 2.0 without errors/warnings. | ||
""" | ||
data_dir = path.join(path.dirname(__file__), "data") | ||
filename = path.join(data_dir, "numpy_2_0_array.pkl") | ||
with open(filename, mode="rb") as file: | ||
content = file.read() | ||
|
||
# Let's make sure that the pickle object we're loading | ||
# was built with NumPy 2.0. | ||
assert b"numpy._core.multiarray" in content | ||
|
||
arr = pickle.loads(content, encoding="latin1") | ||
|
||
assert isinstance(arr, np.ndarray) | ||
assert arr.shape == (73,) and arr.dtype == np.float64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,7 @@ pure_subdirs = [ | |
'_pyinstaller', | ||
'_typing', | ||
'_utils', | ||
'_core', | ||
'array_api', | ||
'compat', | ||
'doc', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters