Skip to content
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

API: Update arraypad,arraysetops, ufunclike and utils namespaces in np.lib #24567

Merged
merged 4 commits into from
Aug 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

def show_cpu_features():
from numpy.lib.utils import _opt_info
from numpy.lib._utils_impl import _opt_info
info = _opt_info()
info = "NumPy CPU features: " + (info if info else 'nothing enabled')
# ASV wrapping stdout & stderr, so we assume having a tty here
Expand Down
5 changes: 0 additions & 5 deletions doc/source/reference/routines.set.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ Set routines

.. currentmodule:: numpy

.. autosummary::
:toctree: generated/

lib.arraysetops

Making proper sets
------------------
.. autosummary::
Expand Down
28 changes: 19 additions & 9 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,18 @@
from .lib import (
DataSource, apply_along_axis, apply_over_axes,
array_split, broadcast_arrays, broadcast_shapes,
broadcast_to, byte_bounds, c_, column_stack, diag_indices,
broadcast_to, c_, column_stack, diag_indices,
diag_indices_from, dsplit, dstack,
ediff1d, emath, expand_dims, fill_diagonal, fix,
emath, expand_dims, fill_diagonal,
fromregex, get_array_wrap, genfromtxt,
get_include, hsplit, in1d, index_exp, info, intersect1d,
isin, isneginf, ix_, kron, load, loadtxt,
hsplit, index_exp, ix_, kron, load, loadtxt,
mgrid, ndenumerate, ndindex, ogrid,
packbits, pad, poly, poly1d, polyadd, polyder,
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,
setdiff1d, setxor1d, show_runtime, split,
take_along_axis, tile, union1d, unique, unpackbits,
unravel_index, vsplit, isposinf
roots, row_stack, s_, save, savetxt, savez,
savez_compressed, split, take_along_axis, tile,
unpackbits, unravel_index, vsplit
)
from .lib._histograms_impl import (
histogram, histogram_bin_edges, histogramdd
Expand All @@ -224,6 +222,14 @@
iscomplexobj, isrealobj, imag, iscomplex, isreal, nan_to_num, real,
real_if_close, typename, mintypecode, common_type
)
from .lib._arraysetops_impl import (
ediff1d, in1d, intersect1d, isin, setdiff1d, setxor1d, union1d, unique
)
from .lib._ufunclike_impl import fix, isneginf, isposinf
from .lib._arraypad_impl import pad
from .lib._utils_impl import (
byte_bounds, show_runtime, get_include, info
)
from . import matrixlib as _mat
from .matrixlib import (
asmatrix, bmat, matrix
Expand Down Expand Up @@ -289,6 +295,10 @@
set(lib._function_base_impl.__all__) |
set(lib._twodim_base_impl.__all__) |
set(lib._type_check_impl.__all__) |
set(lib._arraysetops_impl.__all__) |
set(lib._ufunclike_impl.__all__) |
set(lib._arraypad_impl.__all__) |
set(lib._utils_impl.__all__) |
{"show_config", "__version__"}
)

Expand Down
10 changes: 4 additions & 6 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ from numpy.lib import (
emath as emath,
)

from numpy.lib.arraypad import (
from numpy.lib._arraypad_impl import (
pad as pad,
)

from numpy.lib.arraysetops import (
from numpy.lib._arraysetops_impl import (
ediff1d as ediff1d,
intersect1d as intersect1d,
setxor1d as setxor1d,
Expand Down Expand Up @@ -575,17 +575,15 @@ from numpy.lib._type_check_impl import (
common_type as common_type,
)

from numpy.lib.ufunclike import (
from numpy.lib._ufunclike_impl import (
fix as fix,
isposinf as isposinf,
isneginf as isneginf,
)

from numpy.lib.utils import (
issubdtype as issubdtype,
from numpy.lib._utils_impl import (
get_include as get_include,
info as info,
source as source,
byte_bounds as byte_bounds,
show_runtime as show_runtime,
)
Expand Down
2 changes: 1 addition & 1 deletion numpy/_pytesttester.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _show_numpy_info():
print("NumPy version %s" % np.__version__)
relaxed_strides = np.ones((10, 1), order="C").flags.f_contiguous
print("NumPy relaxed strides checking option:", relaxed_strides)
info = np.lib.utils._opt_info()
info = np.lib._utils_impl._opt_info()
print("NumPy CPU features: ", (info if info else 'nothing enabled'))


Expand Down
2 changes: 1 addition & 1 deletion numpy/core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ def test_deprecated_np_lib_math(self):
class TestLibImports(_DeprecationTestCase):
# Deprecated in Numpy 1.26.0, 2023-09
def test_lib_functions_deprecation_call(self):
from numpy.lib.utils import safe_eval
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
Expand Down
27 changes: 13 additions & 14 deletions numpy/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,22 @@
from . import shape_base
from . import stride_tricks
from . import _twodim_base_impl
from . import ufunclike
from . import _ufunclike_impl
from . import _histograms_impl
from . import polynomial
from . import utils
from . import arraysetops
from . import _utils_impl
from . import _arraysetops_impl
from . import npyio
from . import arrayterator
from . import arraypad
from . import _arraypad_impl
from . import _version

from .index_tricks import *
from .shape_base import *
from .stride_tricks import *
from .ufunclike import *

from .polynomial import *
from .utils import *
from .arraysetops import *
from .npyio import *
from .arrayterator import Arrayterator
from .arraypad import *
from ._version import *
from numpy.core._multiarray_umath import add_docstring, tracemalloc_domain
from numpy.core.function_base import add_newdoc
Expand All @@ -56,11 +51,7 @@
__all__ += index_tricks.__all__
__all__ += shape_base.__all__
__all__ += stride_tricks.__all__
__all__ += ufunclike.__all__
__all__ += arraypad.__all__
__all__ += polynomial.__all__
__all__ += utils.__all__
__all__ += arraysetops.__all__
__all__ += npyio.__all__

from numpy._pytesttester import PytestTester
Expand All @@ -78,7 +69,15 @@ def __getattr__(attr):
"`math` module (Deprecated Numpy 1.25). Replace usages of "
"`numpy.lib.math` with `math`", DeprecationWarning, stacklevel=2)
return math
elif attr in (
"histograms", "type_check", "nanfunctions", "function_base",
"arraypad", "arraysetops", "ufunclike", "utils", "twodim_base"
):
raise AttributeError(
f"`np.lib.{attr}` is now private. If you are using a public "
"function, it should be available in the main numpy namespace, "
"otherwise check the NumPy 2.0 migration guide."
)
ngoldbaum marked this conversation as resolved.
Show resolved Hide resolved
else:
raise AttributeError("module {!r} has no attribute "
"{!r}".format(__name__, attr))

28 changes: 0 additions & 28 deletions numpy/lib/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@ from numpy.lib._version import (
NumpyVersion as NumpyVersion,
)

from numpy.lib.arraypad import (
pad as pad,
)

from numpy.lib.arraysetops import (
ediff1d as ediff1d,
intersect1d as intersect1d,
setxor1d as setxor1d,
union1d as union1d,
setdiff1d as setdiff1d,
unique as unique,
in1d as in1d,
isin as isin,
)

from numpy.lib.arrayterator import (
Arrayterator as Arrayterator,
)
Expand Down Expand Up @@ -110,19 +95,6 @@ from numpy.lib.stride_tricks import (
broadcast_shapes as broadcast_shapes,
)

from numpy.lib.ufunclike import (
fix as fix,
isposinf as isposinf,
isneginf as isneginf,
)

from numpy.lib.utils import (
get_include as get_include,
info as info,
byte_bounds as byte_bounds,
show_runtime as show_runtime,
)

from numpy.core.multiarray import (
add_docstring as add_docstring,
tracemalloc_domain as tracemalloc_domain,
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 0 additions & 22 deletions numpy/lib/arraysetops.py → numpy/lib/_arraysetops_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ def unique(ar, return_index=False, return_inverse=False,

See Also
--------
numpy.lib.arraysetops : Module with a number of other functions for
performing set operations on arrays.
repeat : Repeat elements of an array.

Notes
Expand Down Expand Up @@ -404,12 +402,6 @@ def intersect1d(ar1, ar2, assume_unique=False, return_indices=False):
The indices of the first occurrences of the common values in `ar2`.
Only provided if `return_indices` is True.


See Also
--------
numpy.lib.arraysetops : Module with a number of other functions for
performing set operations on arrays.

Examples
--------
>>> np.intersect1d([1, 3, 4, 3], [3, 1, 2, 1])
Expand Down Expand Up @@ -577,8 +569,6 @@ def in1d(ar1, ar2, assume_unique=False, invert=False, *, kind=None):
--------
isin : Version of this function that preserves the
shape of ar1.
numpy.lib.arraysetops : Module with a number of other functions for
performing set operations on arrays.

Notes
-----
Expand Down Expand Up @@ -818,8 +808,6 @@ def isin(element, test_elements, assume_unique=False, invert=False, *,
See Also
--------
in1d : Flattened version of this function.
numpy.lib.arraysetops : Module with a number of other functions for
performing set operations on arrays.

Notes
-----
Expand Down Expand Up @@ -914,11 +902,6 @@ def union1d(ar1, ar2):
union1d : ndarray
Unique, sorted union of the input arrays.

See Also
--------
numpy.lib.arraysetops : Module with a number of other functions for
performing set operations on arrays.

Examples
--------
>>> np.union1d([-1, 0, 1], [-2, 0, 2])
Expand Down Expand Up @@ -961,11 +944,6 @@ def setdiff1d(ar1, ar2, assume_unique=False):
is sorted when `assume_unique=False`, but otherwise only sorted
if the input is sorted.

See Also
--------
numpy.lib.arraysetops : Module with a number of other functions for
performing set operations on arrays.

Examples
--------
>>> a = np.array([1, 2, 3, 2, 4, 1])
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion numpy/lib/_function_base_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3901,7 +3901,7 @@ def _median(a, axis=None, out=None, overwrite_input=False):
rout = mean(part[indexer], axis=axis, out=out)
if supports_nans and sz > 0:
# If nans are possible, warn and replace by nans like mean would.
rout = np.lib.utils._median_nancheck(part, rout, axis)
rout = np.lib._utils_impl._median_nancheck(part, rout, axis)

return rout

Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/_type_check_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy.core.numeric as _nx
from numpy.core.numeric import asarray, asanyarray, isnan, zeros
from numpy.core import overrides, getlimits
from .ufunclike import isneginf, isposinf
from ._ufunclike_impl import isneginf, isposinf


array_function_dispatch = functools.partial(
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions numpy/lib/utils.py → numpy/lib/_utils_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
]


@set_module('numpy')
def show_runtime():
"""
Print information about various resources in the system
Expand Down Expand Up @@ -69,6 +70,7 @@ def show_runtime():
pprint(config_found)


@set_module('numpy')
def get_include():
"""
Return the directory that contains the NumPy \\*.h header files.
Expand Down Expand Up @@ -290,6 +292,7 @@ def deprecate_with_doc(msg):
#--------------------------------------------


@set_module('numpy')
def byte_bounds(a):
"""
Returns pointers to the end-points of an array.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion numpy/lib/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
import warnings

import numpy
from numpy.lib.utils import drop_metadata
from numpy.lib._utils_impl import drop_metadata


__all__ = []
Expand Down
4 changes: 2 additions & 2 deletions numpy/lib/tests/test_arraypad.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np
from numpy.testing import assert_array_equal, assert_allclose, assert_equal
from numpy.lib.arraypad import _as_pairs
from numpy.lib._arraypad_impl import _as_pairs


_numeric_dtypes = (
Expand Down Expand Up @@ -628,7 +628,7 @@ def test_check_constant_odd_pad_amount(self):

def test_check_constant_pad_2d(self):
arr = np.arange(4).reshape(2, 2)
test = np.lib.pad(arr, ((1, 2), (1, 3)), mode='constant',
test = np.pad(arr, ((1, 2), (1, 3)), mode='constant',
constant_values=((1, 2), (3, 4)))
expected = np.array(
[[3, 1, 1, 4, 4, 4],
Expand Down
6 changes: 3 additions & 3 deletions numpy/lib/tests/test_arraysetops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"""
import numpy as np

from numpy.testing import (assert_array_equal, assert_equal,
assert_raises, assert_raises_regex)
from numpy.lib.arraysetops import (
from numpy import (
ediff1d, intersect1d, setxor1d, union1d, setdiff1d, unique, in1d, isin
)
from numpy.exceptions import AxisError
from numpy.testing import (assert_array_equal, assert_equal,
assert_raises, assert_raises_regex)
import pytest


Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ def test_metadata_dtype(dt, fail):
else:
arr2 = np.load(buf)
# BUG: assert_array_equal does not check metadata
from numpy.lib.utils import drop_metadata
from numpy.lib._utils_impl import drop_metadata
assert_array_equal(arr, arr2)
assert drop_metadata(arr.dtype) is not arr.dtype
assert drop_metadata(arr2.dtype) is arr2.dtype