8000 API: Update `lib.shape_base` namespace by mtsokol · Pull Request #24566 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

API: Update lib.shape_base namespace #24566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,13 @@

from . import lib
from .lib import (
DataSource, apply_along_axis, apply_over_axes,
array_split, c_, column_stack, diag_indices,
diag_indices_from, dsplit, dstack,
emath, expand_dims, fill_diagonal,
fromregex, get_array_wrap, genfromtxt,
hsplit, index_exp, ix_, kron, load, loadtxt,
mgrid, ndenumerate, ndindex, ogrid,
DataSource, c_, diag_indices, diag_indices_from, emath,
fromregex, genfromtxt, index_exp, ix_, load, loadtxt,
mgrid, ndenumerate, ndindex, ogrid, fill_diagonal,
packbits, poly, poly1d, polyadd, polyder,
polydiv, polyfit, polyint, polymul, polysub, polyval,
put_along_axis, r_, ravel_multi_index,
roots, row_stack, s_, save, savetxt, savez,
savez_compressed, split, take_along_axis, tile,
unpackbits, unravel_index, vsplit
r_, ravel_multi_index, roots, s_, save, savetxt, savez,
savez_compressed, unpackbits, unravel_index
)
from .lib._histograms_impl import (
histogram, histogram_bin_edges, histogramdd
Expand All @@ -217,6 +211,11 @@
histogram2d, mask_indices, tril_indices, tril_indices_from,
triu_indices, triu_indices_from
)
from .lib._shape_base_impl import (
apply_over_axes, apply_along_axis, array_split, column_stack, dsplit,
dstack, expand_dims, hsplit, kron, put_along_axis, row_stack, split,
take_along_axis, tile, vsplit
)
from .lib._type_check_impl import (
iscomplexobj, isrealobj, imag, iscomplex, isreal, nan_to_num, real,
real_if_close, typename, mintypecode, common_type
Expand Down Expand Up @@ -296,6 +295,7 @@
set(lib._nanfunctions_impl.__all__) |
set(lib._function_base_impl.__all__) |
set(lib._twodim_base_impl.__all__) |
set(lib._shape_base_impl.__all__) |
set(lib._type_check_impl.__all__) |
set(lib._arraysetops_impl.__all__) |
set(lib._ufunclike_impl.__all__) |
Expand Down
3 changes: 1 addition & 2 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ from numpy.lib.polynomial import (
polyfit as polyfit,
)

from numpy.lib.shape_base import (
from numpy.lib._shape_base_impl import (
column_stack as column_stack,
row_stack as row_stack,
dstack as dstack,
Expand All @@ -531,7 +531,6 @@ from numpy.lib.shape_base import (
apply_along_axis as apply_along_axis,
kron as kron,
tile as tile,
get_array_wrap as get_array_wrap,
take_along_axis as take_along_axis,
put_along_axis as put_along_axis,
)
Expand Down
3 changes: 2 additions & 1 deletion numpy/_expired_attrs_2_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@
"`scalar_types` argument, use `numpy.result_type` and pass the "
"Python values `0`, `0.0`, or `0j`.",
"round_": "Use `np.round` instead.",
"nbytes": "Use `np.dtype(<dtype>).itemsize` instead."
"nbytes": "Use `np.dtype(<dtype>).itemsize` instead.",
"get_array_wrap": "",
}
2 changes: 1 addition & 1 deletion numpy/core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ def test_lib_functions_deprecation_call(self):
from numpy.lib._utils_impl import safe_eval
from numpy.lib.npyio import recfromcsv, recfromtxt
from numpy.lib._function_base_impl import disp
from numpy.lib.shape_base import get_array_wrap
from numpy.lib._shape_base_impl import get_array_wrap
from numpy.core.numerictypes import maximum_sctype
from numpy.lib.tests.test_io import TextIO

Expand Down
7 changes: 3 additions & 4 deletions numpy/lib/__init__.py
8000
Original file line number Diff line numberDiff line change
Expand Up @@ -23,8 +23,8 @@
from . import index_tricks
from . import _nanfunctions_impl
from . import _function_base_impl
from . import shape_base
from . import _stride_tricks_impl
from . import _shape_base_impl
from . import stride_tricks
from . import _twodim_base_impl
from . import _ufunclike_impl
Expand All @@ -38,7 +38,6 @@
from . import _version

from .index_tricks import *
from .shape_base import *
from .polynomial import *
from .npyio import *
from .arrayterator import Arrayterator
Expand All @@ -49,7 +48,6 @@

__all__ = ['emath']
__all__ += index_tricks.__all__
__all__ += shape_base.__all__
__all__ += polynomial.__all__
__all__ += npyio.__all__

Expand All @@ -70,7 +68,8 @@ def __getattr__(attr):
return math
elif attr in (
"histograms", "type_check", "nanfunctions", "function_base",
"arraypad", "arraysetops", "ufunclike", "utils", "twodim_base"
"arraypad", "arraysetops", "ufunclike", "utils", "twodim_base",
"shape_base"
):
raise AttributeError(
f"`np.lib.{attr}` is now private. If you are using a public "
Expand Down
19 changes: 0 additions & 19 deletions numpy/lib/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,6 @@ from numpy.lib.polynomial import (
poly1d as poly1d,
)

from numpy.lib.shape_base import (
column_stack as column_stack,
row_stack as row_stack,
dstack as dstack,
array_split as array_split,
split as split,
hsplit as hsplit,
vsplit as vsplit,
dsplit as dsplit,
apply_over_axes as apply_over_axes,
expand_dims as expand_dims,
apply_along_axis as apply_along_axis,
kron as kron,
tile as tile,
get_array_wrap as get_array_wrap,
take_along_axis as take_along_axis,
put_along_axis as put_along_axis,
)

from numpy.core.multiarray import (
add_docstring as add_docstring,
tracemalloc_domain as tracemalloc_domain,
Expand Down
15 changes: 1 addition & 14 deletions numpy/lib/shape_base.py → numpy/lib/_shape_base_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
__all__ = [
'column_stack', 'row_stack', 'dstack', 'array_split', 'split',
'hsplit', 'vsplit', 'dsplit', 'apply_over_axes', 'expand_dims',
'apply_along_axis', 'kron', 'tile', 'get_array_wrap', 'take_along_axis',
'apply_along_axis', 'kron', 'tile', 'take_along_axis',
'put_along_axis'
]

Expand Down Expand Up @@ -1036,19 +1036,6 @@ def dsplit(ary, indices_or_sections):
return split(ary, indices_or_sections, 2)


def get_array_prepare(*args):
"""Find the wrapper for the array with the highest priority.

In case of ties, leftmost wins. If no wrapper is found, return None
"""
wrappers = sorted((getattr(x, '__array_priority__', 0), -i,
x.__array_prepare__) for i, x in enumerate(args)
if hasattr(x, '__array_prepare__'))
if wrappers:
return wrappers[-1][-1]
return None


def get_array_wrap(*args):
"""Find the wrapper for the array with the highest priority.

Expand Down
5 changes: 0 additions & 5 deletions numpy/lib/shape_base.pyi → numpy/lib/_shape_base_impl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ def dsplit(
indices_or_sections: _ShapeLike,
) -> list[NDArray[Any]]: ...

@overload
def get_array_prepare(*args: _SupportsArrayPrepare) -> _ArrayPrepare: ...
@overload
def get_array_prepare(*args: object) -> None | _ArrayPrepare: ...

@overload
def get_array_wrap(*args: _SupportsArrayWrap) -> _ArrayWrap: ...
@overload
Expand Down
4 changes: 2 additions & 2 deletions numpy/lib/tests/test_shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import sys
import pytest

from numpy.exceptions import AxisError
from numpy.lib.shape_base import (
from numpy import (
apply_along_axis, apply_over_axes, array_split, split, hsplit, dsplit,
vsplit, dstack, column_stack, kron, tile, expand_dims, take_along_axis,
put_along_axis
)
from numpy.exceptions import AxisError
from numpy.testing import (
assert_, assert_equal, assert_array_equal, assert_raises, assert_warns
)
Expand Down
2 changes: 1 addition & 1 deletion numpy/testing/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ def warn(arr):
sup.record(UserWarning)
# suppress warning from other module (may have .pyc ending),
# if apply_along_axis is moved, had to be changed.
sup.filter(module=np.lib.shape_base)
sup.filter(module=np.lib._shape_base_impl)
warnings.warn("Some warning")
warn_other_module()
# Check that the suppression did test the file correctly (this module
Expand Down
2 changes: 0 additions & 2 deletions numpy/tests/test_public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_numpy_namespace():
# NumPy namespace (some are useful though, others need to be cleaned up)
undocumented = {
'compare_chararrays': 'numpy.core._multiarray_umath.compare_chararrays',
'get_array_wrap': 'numpy.lib.shape_base.get_array_wrap',
'show_config': 'numpy.__config__.show',
}
# We override dir to not show these members
Expand Down Expand Up @@ -197,7 +196,6 @@ def test_NPY_NO_EXPORT():
"lib.index_tricks",
"lib.npyio",
"lib.polynomial",
"lib.shape_base",
"lib.user_array", # note: not in np.lib, but probably should just be deleted
"linalg.lapack_lite",
"linalg.linalg",
Expand Down
3 changes: 0 additions & 3 deletions numpy/typing/tests/data/reveal/shape_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ reveal_type(np.vsplit(AR_LIKE_f8, [3, 5, 6, 10])) # E: list[ndarray[Any, dtype[
reveal_type(np.dsplit(AR_i8, [3, 5, 6, 10])) # E: list[ndarray[Any, dtype[{int64}]]]
reveal_type(np.dsplit(AR_LIKE_f8, [3, 5, 6, 10])) # E: list[ndarray[Any, dtype[Any]]]

reveal_type(np.lib.shape_base.get_array_prepare(AR_i8)) # E: lib.shape_base._ArrayPrepare
reveal_type(np.lib.shape_base.get_array_prepare(AR_i8, 1)) # E: Union[None, lib.shape_base._ArrayPrepare]

reveal_type(np.kron(AR_b, AR_b)) # E: ndarray[Any, dtype[bool_]]
reveal_type(np.kron(AR_b, AR_i8)) # E: ndarray[Any, dtype[signedinteger[Any]]]
reveal_type(np.kron(AR_f8, AR_f8)) # E: ndarray[Any, dtype[floating[Any]]]
Expand Down
0