Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24906 from mtsokol/backport-_core-stubs
MAINT: Backport `numpy._core` stubs. Remove `NumpyUnpickler`
- Loading branch information
Showing
19 changed files
with
101 additions
and
29 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 @@ | ||
`numpy._core` submodules' stubs | ||
------------------------------- | ||
|
||
`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,48 @@ | ||
from os import path | ||
import pickle | ||
|
||
import numpy as np | ||
|
||
|
||
class TestNumPy2Compatibility: | ||
|
||
data_dir = path.join(path.dirname(__file__), "data") | ||
filename = path.join(data_dir, "numpy_2_0_array.pkl") | ||
|
||
def test_importable__core_stubs(self): | ||
""" | ||
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_file(self): | ||
""" | ||
Checks that NumPy 1.26 and pickle is able to load pickles | ||
created with NumPy 2.0 without errors/warnings. | ||
""" | ||
with open(self.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 | ||
|
||
def test_numpy_load_numpy_2_0_file(self): | ||
""" | ||
Checks that `numpy.load` for NumPy 1.26 is able to load pickles | ||
created with NumPy 2.0 without errors/warnings. | ||
""" | ||
arr = np.load(self.filename, encoding="latin1", allow_pickle=True) | ||
|
||
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