Skip to content

Commit c84e087

Browse files
committed
API: Update lib.shape_base namespace
1 parent b43384e commit c84e087

File tree

12 files changed

+32
-47
lines changed

12 files changed

+32
-47
lines changed

numpy/__init__.py

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

184184
from . import lib
185185
from .lib import (
186-
DataSource, apply_along_axis, apply_over_axes,
187-
array_split, broadcast_arrays, broadcast_shapes,
188-
broadcast_to, c_, column_stack, diag_indices,
189-
diag_indices_from, dsplit, dstack,
190-
emath, expand_dims, fill_diagonal,
191-
fromregex, get_array_wrap, genfromtxt,
192-
hsplit, index_exp, ix_, kron, load, loadtxt,
186+
DataSource, broadcast_arrays, broadcast_shapes, broadcast_to, c_,
187+
diag_indices, diag_indices_from, emath, fill_diagonal,
188+
fromregex, genfromtxt, index_exp, ix_, load, loadtxt,
193189
mgrid, ndenumerate, ndindex, ogrid,
194190
packbits, poly, poly1d, polyadd, polyder,
195191
polydiv, polyfit, polyint, polymul, polysub, polyval,
196-
put_along_axis, r_, ravel_multi_index,
197-
roots, row_stack, s_, save, savetxt, savez,
198-
savez_compressed, split, take_along_axis, tile,
199-
unpackbits, unravel_index, vsplit
192+
r_, ravel_multi_index, roots, s_, save, savetxt, savez,
193+
savez_compressed, unpackbits, unravel_index
200194
)
201195
from .lib._histograms_impl import (
202196
histogram, histogram_bin_edges, histogramdd
@@ -218,6 +212,11 @@
218212
histogram2d, mask_indices, tril_indices, tril_indices_from,
219213
triu_indices, triu_indices_from
220214
)
215+
from .lib._shape_base_impl import (
216+
apply_over_axes, apply_along_axis, array_split, column_stack, dsplit,
217+
dstack, expand_dims, hsplit, kron, put_along_axis, row_stack, split,
218+
take_along_axis, tile, vsplit
219+
)
221220
from .lib._type_check_impl import (
222221
iscomplexobj, isrealobj, imag, iscomplex, isreal, nan_to_num, real,
223222
real_if_close, typename, mintypecode, common_type
@@ -294,6 +293,7 @@
294293
set(lib._nanfunctions_impl.__all__) |
295294
set(lib._function_base_impl.__all__) |
296295
set(lib._twodim_base_impl.__all__) |
296+
set(lib._shape_base_impl.__all__) |
297297
set(lib._type_check_impl.__all__) |
298298
set(lib._arraysetops_impl.__all__) |
299299
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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from . import index_tricks
2424
from . import _nanfunctions_impl
2525
from . import _function_base_impl
26-
from . import shape_base
26+
from . import _shape_base_impl
2727
from . import stride_tricks
2828
from . import _twodim_base_impl
2929
from . import _ufunclike_impl
@@ -37,7 +37,6 @@
3737
from . import _version
3838

3939
from .index_tricks import *
40-
from .shape_base import *
4140
from .stride_tricks import *
4241
from .polynomial import *
4342
from .npyio import *
@@ -49,7 +48,6 @@
4948

5049
__all__ = ['emath']
5150
__all__ += index_tricks.__all__
52-
__all__ += shape_base.__all__
5351
__all__ += stride_tricks.__all__
5452
__all__ += polynomial.__all__
5553
__all__ += npyio.__all__

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.lib.stride_tricks import (
9374
broadcast_to as broadcast_to,
9475
broadcast_arrays as broadcast_arrays,

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)