8000 API: Update lib.shape_base namespace · numpy/numpy@f51caf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit f51caf1

Browse files
committed
API: Update lib.shape_base namespace
1 parent a277f62 commit f51caf1

12 files changed

+37
-50
lines changed

numpy/__init__.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,20 @@
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, byte_bounds, c_, column_stack, diag, diag_indices,
189-
diag_indices_from, diagflat, dsplit, dstack,
190-
ediff1d, emath, expand_dims, eye, fill_diagonal, fix,
191-
fliplr, flipud, fromregex, get_array_wrap, genfromtxt,
192-
get_include, histogram2d, hsplit, in1d, index_exp, info, intersect1d,
193-
isin, isneginf, ix_, kron, load, loadtxt, mask_indices,
186+
DataSource, broadcast_arrays, broadcast_shapes,
187+
broadcast_to, byte_bounds, c_, diag, diag_indices,
188+
diag_indices_from, diagflat, ediff1d, emath, eye, fill_diagonal,
189+
fix, fliplr, flipud, fromregex, genfromtxt,
190+
get_include, histogram2d, in1d, index_exp, info, intersect1d,
191+
isin, isneginf, ix_, load, loadtxt, mask_indices,
194192
mgrid, ndenumerate, ndindex, ogrid,
195193
packbits, pad, poly, poly1d, polyadd, polyder,
196194
polydiv, polyfit, polyint, polymul, polysub, polyval,
197-
put_along_axis, r_, ravel_multi_index,
198-
roots, row_stack, s_, save, savetxt, savez, savez_compressed,
199-
setdiff1d, setxor1d, show_runtime, split,
200-
take_along_axis, tile, tri, tril,
201-
tril_indices, tril_indices_from, union1d, unique, unpackbits,
202-
unravel_index, vander, vsplit, triu, triu_indices, triu_indices_from,
203-
isposinf
195+
r_, ravel_multi_index, roots, s_, save, savetxt, savez,
196+
savez_compressed, setdiff1d, setxor1d, show_runtime,
197+
tri, tril, tril_indices, tril_indices_from, union1d, unique,
198+
unpackbits, unravel_index, vander, triu, triu_indices,
199+
triu_indices_from, isposinf
204200
)
205201
from .lib._histograms_impl import (
206202
histogram, histogram_bin_edges, histogramdd
@@ -217,6 +213,11 @@
217213
corrcoef, median, sinc, hamming, hanning, bartlett, blackman,
218214
kaiser, trapz, i0, meshgrid, delete, insert, append, interp, quantile
219215
)
216+
from .lib._shape_base_impl import (
217+
apply_over_axes, apply_along_axis, array_split, column_stack, dsplit,
218+
dstack, expand_dims, hsplit, kron, put_along_axis, row_stack, split,
219+
take_along_axis, tile, vsplit
220+
)
220221
from .lib._type_check_impl import (
221222
iscomplexobj, isrealobj, imag, iscomplex, isreal, nan_to_num, real,
222223
real_if_close, typename, mintypecode, common_type
@@ -284,6 +285,7 @@
284285
set(_mat.__all__) | set(lib._histograms_impl.__all__) |
285286
set(lib._nanfunctions_impl.__all__) |
286287
set(lib._function_base_impl.__all__) |
288+
set(lib._shape_base_impl.__all__) |
287289
set(lib._type_check_impl.__all__) |
288290
{"show_config", "__version__"}
289291
)

numpy/__init__.pyi

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

521-
from numpy.lib.shape_base import (
521+
from numpy.lib._shape_base_impl import (
522522
column_stack as column_stack,
523523
row_stack as row_stack,
524524
dstack as dstack,
@@ -532,7 +532,6 @@ from numpy.lib.shape_base import (
532532
apply_along_axis as apply_along_axis,
533533
kron as kron,
534534
tile as tile,
535-
get_array_wrap as get_array_wrap,
536535
take_along_axis as take_along_axis,
537536
put_along_axis as put_along_axis,
538537
)

numpy/_expired_attrs_2_0.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@
6161
"deprecate": "Raise `DeprecationWarning` instead.",
6262
"deprecate_with_doc": "Raise `DeprecationWarning` instead.",
6363
"disp": "Use your own printing function instead.",
64+
"get_array_wrap": ""
6465
}

numpy/core/tests/test_deprecations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ def test_lib_functions_deprecation_call(self):
756756
from numpy.lib.utils import safe_eval
757757
from numpy.lib.npyio import recfromcsv, recfromtxt
758758
from numpy.lib._function_base_impl import disp
759-
from numpy.lib.shape_base import get_array_wrap
< F438 code>759+
from numpy.lib._shape_base_impl import get_array_wrap
760760
from numpy.core.numerictypes import maximum_sctype
761761
from numpy.lib.tests.test_io import TextIO
762762

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
2929
from . import ufunclike
@@ -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 .twodim_base import *
4342
from .ufunclike import *
@@ -55,7 +54,6 @@
5554

5655
__all__ = ['emath']
5756
__all__ += index_tricks.__all__
58-
__all__ += shape_base.__all__
5957
__all__ += stride_tricks.__all__
6058
__all__ += twodim_base.__all__
6159
__all__ += ufunclike.__all__

numpy/lib/__init__.pyi

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,6 @@ from numpy.lib.polynomial import (
8585
poly1d as poly1d,
8686
)
8787

88-
from numpy.lib.shape_base import (
89-
column_stack as column_stack,
90-
row_stack as row_stack,
91-
dstack as dstack,
92-
array_split as array_split,
93-
split as split,
94-
hsplit as hsplit,
95-
vsplit as vsplit,
96-
dsplit as dsplit,
97-
apply_over_axes as apply_over_axes,
98-
expand_dims as expand_dims,
99-
apply_along_axis as apply_along_axis,
100-
kron as kron,
101-
tile as tile,
102-
get_array_wrap as get_array_wrap,
103-
take_along_axis as take_along_axis,
104-
put_along_axis as put_along_axis,
105-
)
106-
10788
from numpy.lib.stride_tricks import (
10889
broadcast_to as broadcast_to,
10990
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
@@ -36,7 +36,6 @@ def test_numpy_namespace():
3636
undocumented = {
3737
'byte_bounds': 'numpy.lib.utils.byte_bounds',
3838
'compare_chararrays': 'numpy.core._multiarray_umath.compare_chararrays',
39-
'get_array_wrap': 'numpy.lib.shape_base.get_array_wrap',
4039
'get_include': 'numpy.lib.utils.get_include',
4140
'show_config': 'numpy.__config__.show',
4241
'show_runtime': 'numpy.lib.utils.show_runtime',
@@ -202,7 +201,6 @@ def test_NPY_NO_EXPORT():
202201
"lib.index_tricks",
203202
"lib.npyio",
204203
"lib.polynomial",
205-
"lib.shape_base",
206204
"lib.twodim_base",
207205
"lib.ufunclike",
208206
"lib.user_array", # note: not in np.lib, but probably should just be deleted

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)
0