Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68ffec2

Browse files
committed
API: Update lib.shape_base namespace
1 parent b73a5ae commit 68ffec2

12 files changed

+33
-47
lines changed

numpy/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,13 @@
183183

184184
from . import lib
185185
from .lib import (
186-
DataSource, apply_along_axis, apply_over_axes,
187-
array_split, c_, column_stack, diag_indices,
188-
diag_indices_from, dsplit, dstack,
189-
emath, expand_dims, fill_diagonal,
190-
fromregex, get_array_wrap, genfromtxt,
191-
hsplit, index_exp, ix_, kron, load, loadtxt,
192-
mgrid, ndenumerate, ndindex, ogrid,
186+
DataSource, c_, diag_indices, diag_indices_from, emath,
187+
fromregex, genfromtxt, index_exp, ix_, load, loadtxt,
188+
mgrid, ndenumerate, ndindex, ogrid, fill_diagonal,
193189
packbits, poly, poly1d, polyadd, polyder,
194190
polydiv, polyfit, polyint, polymul, polysub, polyval,
195-
put_along_axis, r_, ravel_multi_index,
196-
roots, row_stack, s_, save, savetxt, savez,
197-
savez_compressed, split, take_along_axis, tile,
198-
unpackbits, unravel_index, vsplit
191+
r_, ravel_multi_index, roots, s_, save, savetxt, savez,
192+
savez_compressed, unpackbits, unravel_index
199193
)
200194
from .lib._histograms_impl import (
201195
histogram, histogram_bin_edges, histogramdd
@@ -217,6 +211,11 @@
217211
histogram2d, mask_indices, tril_indices, tril_indices_from,
218212
triu_indices, triu_indices_from
219213
)
214+
from .lib._shape_base_impl import (
215+
apply_over_axes, apply_along_axis, array_split, column_stack, dsplit,
216+
dstack, expand_dims, hsplit, kron, put_along_axis, row_stack, split,
217+
take_along_axis, tile, vsplit
218+
)
220219
from .lib._type_check_impl import (
221220
iscomplexobj, isrealobj, imag, iscomplex, isreal, nan_to_num, real,
222221
real_if_close, typename, mintypecode, common_type
@@ -296,6 +295,7 @@
296295
set(lib._nanfunctions_impl.__all__) |
297296
set(lib._function_base_impl.__all__) |
298297
set(lib._twodim_base_impl.__all__) |
298+
set(lib._shape_base_impl.__all__) |
299299
set(lib._type_check_impl.__all__) |
300300
set(lib._arraysetops_impl.__all__) |
301301
set(lib._ufunclike_impl.__all__) |

numpy/__init__.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ from numpy.lib.polynomial import (
517517
polyfit as polyfit,
518518
)
519519

520-
from numpy.lib.shape_base import (
520+
from numpy.lib._shape_base_impl import (
521521
column_stack as column_stack,
522522
row_stack as row_stack,
523523
dstack as dstack,
@@ -531,7 +531,6 @@ from numpy.lib.shape_base import (
531531
apply_along_axis as apply_along_axis,
532532
kron as kron,
533533
tile as tile,
534-
get_array_wrap as get_array_wrap,
535534
take_along_axis as take_along_axis,
536535
put_along_axis as put_along_axis,
537536
)

numpy/_expired_attrs_2_0.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@
6565
"`scalar_types` argument, use `numpy.result_type` and pass the "
6666
"Python values `0`, `0.0`, or `0j`.",
6767
"round_": "Use `np.round` instead.",
68-
"nbytes": "Use `np.dtype(<dtype>).itemsize` instead."
68+
"nbytes": "Use `np.dtype(<dtype>).itemsize` instead.",
69+
"get_array_wrap": "",
6970
}

numpy/core/tests/test_deprecations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ def test_lib_functions_deprecation_call(self):
752752
from numpy.lib._utils_impl import safe_eval
753753
from numpy.lib.npyio import recfromcsv, recfromtxt
754754
from numpy.lib._function_base_impl import disp
755-
from numpy.lib.shape_base import get_array_wrap
755+
from numpy.lib._shape_base_impl import get_array_wrap
756756
from numpy.core.numerictypes import maximum_sctype
757757
from numpy.lib.tests.test_io import TextIO
758758

numpy/lib/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from . import index_tricks
2424
from . import _nanfunctions_impl
2525
from . import _function_base_impl
26-
from . import shape_base
2726
from . import _stride_tricks_impl
27+
from . import _shape_base_impl
2828
from . import stride_tricks
2929
from . import _twodim_base_impl
3030
from . import _ufunclike_impl
@@ -33,12 +33,12 @@
3333
from . import _utils_impl
3434
from . import _arraysetops_impl
3535
from . import npyio
36+
from . import stride_tricks
3637
from . import arrayterator
3738
from . import _arraypad_impl
3839
from . import _version
3940

4041
from .index_tricks import *
41-
from .shape_base import *
4242
from .polynomial import *
4343
from .npyio import *
4444
from .arrayterator import Arrayterator
@@ -49,7 +49,6 @@
4949

5050
__all__ = ['emath']
5151
__all__ += index_tricks.__all__
52-
__all__ += shape_base.__all__
5352
__all__ += polynomial.__all__
5453
__all__ += npyio.__all__
5554

numpy/lib/__init__.pyi

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,6 @@ from numpy.lib.polynomial import (
7070
poly1d as poly1d,
7171
)
7272

73-
from numpy.lib.shape_base import (
74-
column_stack as column_stack,
75-
row_stack as row_stack,
76-
dstack as dstack,
77-
array_split as array_split,
78-
split as split,
79-
hsplit as hsplit,
80-
vsplit as vsplit,
81-
dsplit as dsplit,
82-
apply_over_axes as apply_over_axes,
83-
expand_dims as expand_dims,
84-
apply_along_axis as apply_along_axis,
85-
kron as kron,
86-
tile as tile,
87-
get_array_wrap as get_array_wrap,
88-
take_along_axis as take_along_axis,
89-
put_along_axis as put_along_axis,
90-
)
91-
9273
from numpy.core.multiarray import (
9374
add_docstring as add_docstring,
9475
tracemalloc_domain as tracemalloc_domain,

numpy/lib/shape_base.py renamed to numpy/lib/_shape_base_impl.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
__all__ = [
1717
'column_stack', 'row_stack', 'dstack', 'array_split', 'split',
1818
'hsplit', 'vsplit', 'dsplit', 'apply_over_axes', 'expand_dims',
19-
'apply_along_axis', 'kron', 'tile', 'get_array_wrap', 'take_along_axis',
19+
'apply_along_axis', 'kron', 'tile', 'take_along_axis',
2020
'put_along_axis'
2121
]
2222

@@ -1039,8 +1039,19 @@ def dsplit(ary, indices_or_sections):
10391039
def get_array_prepare(*args):
10401040
"""Find the wrapper for the array with the highest priority.
10411041
1042-
In case of ties, leftmost wins. If no wrapper is found, return None
1042+
In case of ties, leftmost wins. If no wrapper is found, return None.
1043+
1044+
.. deprecated:: 2.0
10431045
"""
1046+
1047+
# Deprecated in NumPy 2.0, 2023-08-28
1048+
warnings.warn(
1049+
"`get_array_prepare` is deprecated. "
1050+
"(deprecated in NumPy 2.0)",
1051+
DeprecationWarning,
1052+
stacklevel=2
1053+
)
1054+
10441055
wrappers = sorted((getattr(x, '__array_priority__', 0), -i,
10451056
x.__array_prepare__) for i, x in enumerate(args)
10461057
if hasattr(x, '__array_prepare__'))
File renamed without changes.

numpy/lib/tests/test_shape_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import sys
44
import pytest
55

6-
from numpy.exceptions import AxisError
7-
from numpy.lib.shape_base import (
6+
from numpy import (
87
apply_along_axis, apply_over_axes, array_split, split, hsplit, dsplit,
98
vsplit, dstack, column_stack, kron, tile, expand_dims, take_along_axis,
109
put_along_axis
1110
)
11+
from numpy.exceptions import AxisError
1212
from numpy.testing import (
1313
assert_, assert_equal, assert_array_equal, assert_raises, assert_warns
1414
)

numpy/testing/tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ def warn(arr):
13511351
sup.record(UserWarning)
13521352
# suppress warning from other module (may have .pyc ending),
13531353
# if apply_along_axis is moved, had to be changed.
1354-
sup.filter(module=np.lib.shape_base)
1354+
sup.filter(module=np.lib._shape_base_impl)
13551355
warnings.warn("Some warning")
13561356
warn_other_module()
13571357
# Check that the suppression did test the file correctly (this module

numpy/tests/test_public_api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def test_numpy_namespace():
3535
# NumPy namespace (some are useful though, others need to be cleaned up)
3636
undocumented = {
3737
'compare_chararrays': 'numpy.core._multiarray_umath.compare_chararrays',
38-
'get_array_wrap': 'numpy.lib.shape_base.get_array_wrap',
3938
'show_config': 'numpy.__config__.show',
4039
}
4140
# We override dir to not show these members
@@ -197,7 +196,6 @@ def test_NPY_NO_EXPORT():
197196
"lib.index_tricks",
198197
"lib.npyio",
199198
"lib.polynomial",
200-
"lib.shape_base",
201199
"lib.user_array", # note: not in np.lib, but probably should just be deleted
202200
"linalg.lapack_lite",
203201
"linalg.linalg",

numpy/typing/tests/data/reveal/shape_base.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ reveal_type(np.vsplit(AR_LIKE_f8, [3, 5, 6, 10])) # E: list[ndarray[Any, dtype[
4343
reveal_type(np.dsplit(AR_i8, [3, 5, 6, 10])) # E: list[ndarray[Any, dtype[{int64}]]]
4444
reveal_type(np.dsplit(AR_LIKE_f8, [3, 5, 6, 10])) # E: list[ndarray[Any, dtype[Any]]]
4545

46-
reveal_type(np.lib.shape_base.get_array_prepare(AR_i8)) # E: lib.shape_base._ArrayPrepare
47-
reveal_type(np.lib.shape_base.get_array_prepare(AR_i8, 1)) # E: Union[None, lib.shape_base._ArrayPrepare]
48-
4946
reveal_type(np.kron(AR_b, AR_b)) # E: ndarray[Any, dtype[bool_]]
5047
reveal_type(np.kron(AR_b, AR_i8)) # E: ndarray[Any, dtype[signedinteger[Any]]]
5148
reveal_type(np.kron(AR_f8, AR_f8)) # E: ndarray[Any, dtype[floating[Any]]]

0 commit comments

Comments
 (0)