module documentation

Undocumented

Constant PRIVATE​_BUT​_PRESENT​_MODULES Undocumented
Constant PUBLIC​_ALIASED​_MODULES Undocumented
Constant PUBLIC​_MODULES Undocumented
Constant SKIP​_LIST Undocumented
Constant SKIP​_LIST​_2 Undocumented
Variable ctypes Undocumented
Function check​_dir Returns a mapping of all objects with the wrong __module__ attribute.
Function is​_unexpected Check if this needs to be considered.
Function test​_all​_modules​_are​_expected Test that we don't add anything that looks like a new public module by accident. Check is based on filenames.
Function test​_all​_modules​_are​_expected​_2 Method checking all objects. The pkgutil-based method in test_all_modules_are_expected does not catch imports into a namespace, only filenames. So this test is more thorough, and checks this like:
Function test​_api​_importable Check that all submodules listed higher up in this file can be imported
Function test​_array​_api​_entry​_point Entry point for Array API implementation can be found with importlib and returns the numpy.array_api namespace.
Function test​_dir​_testing Assert that output of dir has only one "testing/tester" attribute without duplicate
Function test​_import​_lazy​_import Make sure we can actually use the modules we lazy load.
Function test_​NPY_​NO_​EXPORT Undocumented
Function test​_numpy​_fft Undocumented
Function test​_numpy​_linalg Undocumented
Function test​_numpy​_namespace Undocumented
PRIVATE_BUT_PRESENT_MODULES =

Undocumented

Value
[('numpy.' + s) for s in ['compat', 'compat.py3k', 'conftest', 'core',
    'core.arrayprint', 'core.defchararray', 'core.einsumfunc',
    'core.fromnumeric', 'core.function_base', 'core.getlimits',
    'core.memmap', 'core.multiarray', 'core.numeric', 'core.numerictypes',
    'core.overrides', 'core.records', 'core.shape_base', 'core.umath',
    'core.umath_tests', 'distutils.armccompiler', 'distutils.ccompiler',
    'distutils.ccompiler_opt', 'distutils.command',
...
PUBLIC_ALIASED_MODULES: list[str] =

Undocumented

Value
['numpy.char', 'numpy.emath', 'numpy.rec']
PUBLIC_MODULES =

Undocumented

Value
[('numpy.' + s) for s in ['array_api', 'array_api.linalg', 'ctypeslib',
    'distutils', 'distutils.cpuinfo', 'distutils.exec_command',
    'distutils.misc_util', 'distutils.log', 'distutils.system_info', 'doc',
    'doc.constants', 'doc.ufuncs', 'f2py', 'fft', 'lib', 'lib.format',
    'lib.mixins', 'lib.recfunctions', 'lib.scimath', 'lib.stride_tricks',
    'linalg', 'ma', 'ma.extras', 'ma.mrecords', 'matlib', 'polynomial',
    'polynomial.chebyshev', 'polynomial.hermite', 'polynomial.hermite_e',
...
SKIP_LIST: list[str] =

Undocumented

Value
['numpy.core.code_generators',
 'numpy.core.code_generators.genapi',
 'numpy.core.code_generators.generate_umath',
 'numpy.core.code_generators.ufunc_docstrings',
 'numpy.core.code_generators.generate_numpy_api',
 'numpy.core.code_generators.generate_ufunc_api',
 'numpy.core.code_generators.numpy_api',
...
SKIP_LIST_2: list[str] =

Undocumented

Value
['numpy.math',
 'numpy.distutils.log.sys',
 'numpy.doc.constants.re',
 'numpy.doc.constants.textwrap',
 'numpy.lib.emath',
 'numpy.lib.math',
 'numpy.matlib.char',
...
ctypes =

Undocumented

def check_dir(module, module_name=None):
Returns a mapping of all objects with the wrong __module__ attribute.
def is_unexpected(name):
Check if this needs to be considered.
def test_all_modules_are_expected():
Test that we don't add anything that looks like a new public module by accident. Check is based on filenames.
def test_all_modules_are_expected_2():

Method checking all objects. The pkgutil-based method in test_all_modules_are_expected does not catch imports into a namespace, only filenames. So this test is more thorough, and checks this like:

import .lib.scimath as emath

To check if something in a module is (effectively) public, one can check if there's anything in that namespace that's a public function/object but is not exposed in a higher-level namespace. For example for a numpy.lib submodule:

mod = np.lib.mixins
for obj in mod.__all__:
    if obj in np.__all__:
        continue
    elif obj in np.lib.__all__:
        continue

    else:
        print(obj)
def test_api_importable():

Check that all submodules listed higher up in this file can be imported

Note that if a PRIVATE_BUT_PRESENT_MODULES entry goes missing, it may simply need to be removed from the list (deprecation may or may not be needed - apply common sense).

@pytest.mark.xfail((sysconfig.get_config_var('Py_DEBUG') is not None), reason='NumPy possibly built with `USE_DEBUG=True ./tools/travis-test.sh`, which does not expose the `array_api` entry point. See https://github.com/numpy/numpy/pull/19800')
def test_array_api_entry_point():
Entry point for Array API implementation can be found with importlib and returns the numpy.array_api namespace.
def test_dir_testing():
Assert that output of dir has only one "testing/tester" attribute without duplicate
@pytest.mark.parametrize('name', ['testing', 'Tester'])
def test_import_lazy_import(name):

Make sure we can actually use the modules we lazy load.

While not exported as part of the public API, it was accessible. With the use of __getattr__ and __dir__, this isn't always true It can happen that an infinite recursion may happen.

This is the only way I found that would force the failure to appear on the badly implemented code.

We also test for the presence of the lazily imported modules in dir

@pytest.mark.skipif((ctypes is None), reason='ctypes not available in this python')
def test_NPY_NO_EXPORT():

Undocumented

def test_numpy_fft():

Undocumented

def test_numpy_linalg():

Undocumented

def test_numpy_namespace():

Undocumented