content stringlengths 1 103k ⌀ | path stringlengths 8 216 | filename stringlengths 2 179 | language stringclasses 15
values | size_bytes int64 2 189k | quality_score float64 0.5 0.95 | complexity float64 0 1 | documentation_ratio float64 0 1 | repository stringclasses 5
values | stars int64 0 1k | created_date stringdate 2023-07-10 19:21:08 2025-07-09 19:11:45 | license stringclasses 4
values | is_test bool 2
classes | file_hash stringlengths 32 32 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
import sys\nfrom importlib.util import LazyLoader, find_spec, module_from_spec\n\nimport pytest\n\n\n# Warning raised by _reload_guard() in numpy/__init__.py\n@pytest.mark.filterwarnings("ignore:The NumPy module was reloaded")\ndef test_lazy_load():\n # gh-22045. lazyload doesn't import submodule names into the namespace\n # muck with sys.modules to test the importing system\n old_numpy = sys.modules.pop("numpy")\n\n numpy_modules = {}\n for mod_name, mod in list(sys.modules.items()):\n if mod_name[:6] == "numpy.":\n numpy_modules[mod_name] = mod\n sys.modules.pop(mod_name)\n\n try:\n # create lazy load of numpy as np\n spec = find_spec("numpy")\n module = module_from_spec(spec)\n sys.modules["numpy"] = module\n loader = LazyLoader(spec.loader)\n loader.exec_module(module)\n np = module\n\n # test a subpackage import\n from numpy.lib import recfunctions # noqa: F401\n\n # test triggering the import of the package\n np.ndarray\n\n finally:\n if old_numpy:\n sys.modules["numpy"] = old_numpy\n sys.modules.update(numpy_modules)\n | .venv\Lib\site-packages\numpy\tests\test_lazyloading.py | test_lazyloading.py | Python | 1,198 | 0.95 | 0.131579 | 0.2 | python-kit | 560 | 2023-10-10T23:05:29.893450 | Apache-2.0 | true | c49d4e770bcddec6f081c309219c81ba |
import numpy as np\nimport numpy.matlib\nfrom numpy.testing import assert_, assert_array_equal\n\n\ndef test_empty():\n x = numpy.matlib.empty((2,))\n assert_(isinstance(x, np.matrix))\n assert_(x.shape, (1, 2))\n\ndef test_ones():\n assert_array_equal(numpy.matlib.ones((2, 3)),\n np.matrix([[ 1., 1., 1.],\n [ 1., 1., 1.]]))\n\n assert_array_equal(numpy.matlib.ones(2), np.matrix([[ 1., 1.]]))\n\ndef test_zeros():\n assert_array_equal(numpy.matlib.zeros((2, 3)),\n np.matrix([[ 0., 0., 0.],\n [ 0., 0., 0.]]))\n\n assert_array_equal(numpy.matlib.zeros(2), np.matrix([[0., 0.]]))\n\ndef test_identity():\n x = numpy.matlib.identity(2, dtype=int)\n assert_array_equal(x, np.matrix([[1, 0], [0, 1]]))\n\ndef test_eye():\n xc = numpy.matlib.eye(3, k=1, dtype=int)\n assert_array_equal(xc, np.matrix([[ 0, 1, 0],\n [ 0, 0, 1],\n [ 0, 0, 0]]))\n assert xc.flags.c_contiguous\n assert not xc.flags.f_contiguous\n\n xf = numpy.matlib.eye(3, 4, dtype=int, order='F')\n assert_array_equal(xf, np.matrix([[ 1, 0, 0, 0],\n [ 0, 1, 0, 0],\n [ 0, 0, 1, 0]]))\n assert not xf.flags.c_contiguous\n assert xf.flags.f_contiguous\n\ndef test_rand():\n x = numpy.matlib.rand(3)\n # check matrix type, array would have shape (3,)\n assert_(x.ndim == 2)\n\ndef test_randn():\n x = np.matlib.randn(3)\n # check matrix type, array would have shape (3,)\n assert_(x.ndim == 2)\n\ndef test_repmat():\n a1 = np.arange(4)\n x = numpy.matlib.repmat(a1, 2, 2)\n y = np.array([[0, 1, 2, 3, 0, 1, 2, 3],\n [0, 1, 2, 3, 0, 1, 2, 3]])\n assert_array_equal(x, y)\n | .venv\Lib\site-packages\numpy\tests\test_matlib.py | test_matlib.py | Python | 1,913 | 0.95 | 0.135593 | 0.042553 | awesome-app | 404 | 2025-01-03T15:39:15.647146 | MIT | true | 40623a9126da8469057ba95676cf031c |
"""\nCheck the numpy config is valid.\n"""\nfrom unittest.mock import patch\n\nimport pytest\n\nimport numpy as np\n\npytestmark = pytest.mark.skipif(\n not hasattr(np.__config__, "_built_with_meson"),\n reason="Requires Meson builds",\n)\n\n\nclass TestNumPyConfigs:\n REQUIRED_CONFIG_KEYS = [\n "Compilers",\n "Machine Information",\n "Python Information",\n ]\n\n @patch("numpy.__config__._check_pyyaml")\n def test_pyyaml_not_found(self, mock_yaml_importer):\n mock_yaml_importer.side_effect = ModuleNotFoundError()\n with pytest.warns(UserWarning):\n np.show_config()\n\n def test_dict_mode(self):\n config = np.show_config(mode="dicts")\n\n assert isinstance(config, dict)\n assert all(key in config for key in self.REQUIRED_CONFIG_KEYS), (\n "Required key missing,"\n " see index of `False` with `REQUIRED_CONFIG_KEYS`"\n )\n\n def test_invalid_mode(self):\n with pytest.raises(AttributeError):\n np.show_config(mode="foo")\n\n def test_warn_to_add_tests(self):\n assert len(np.__config__.DisplayModes) == 2, (\n "New mode detected,"\n " please add UT if applicable and increment this count"\n )\n | .venv\Lib\site-packages\numpy\tests\test_numpy_config.py | test_numpy_config.py | Python | 1,281 | 0.85 | 0.152174 | 0 | vue-tools | 718 | 2024-03-11T04:34:09.952477 | GPL-3.0 | true | 7895d6cf39a5aee69d5b803a85413eb8 |
"""\nCheck the numpy version is valid.\n\nNote that a development version is marked by the presence of 'dev0' or '+'\nin the version string, all else is treated as a release. The version string\nitself is set from the output of ``git describe`` which relies on tags.\n\nExamples\n--------\n\nValid Development: 1.22.0.dev0 1.22.0.dev0+5-g7999db4df2 1.22.0+5-g7999db4df2\nValid Release: 1.21.0.rc1, 1.21.0.b1, 1.21.0\nInvalid: 1.22.0.dev, 1.22.0.dev0-5-g7999db4dfB, 1.21.0.d1, 1.21.a\n\nNote that a release is determined by the version string, which in turn\nis controlled by the result of the ``git describe`` command.\n"""\nimport re\n\nimport numpy as np\nfrom numpy.testing import assert_\n\n\ndef test_valid_numpy_version():\n # Verify that the numpy version is a valid one (no .post suffix or other\n # nonsense). See gh-6431 for an issue caused by an invalid version.\n version_pattern = r"^[0-9]+\.[0-9]+\.[0-9]+(a[0-9]|b[0-9]|rc[0-9])?"\n dev_suffix = r"(\.dev[0-9]+(\+git[0-9]+\.[0-9a-f]+)?)?"\n res = re.match(version_pattern + dev_suffix + '$', np.__version__)\n\n assert_(res is not None, np.__version__)\n\n\ndef test_short_version():\n # Check numpy.short_version actually exists\n if np.version.release:\n assert_(np.__version__ == np.version.short_version,\n "short_version mismatch in release version")\n else:\n assert_(np.__version__.split("+")[0] == np.version.short_version,\n "short_version mismatch in development version")\n\n\ndef test_version_module():\n contents = {s for s in dir(np.version) if not s.startswith('_')}\n expected = {\n 'full_version',\n 'git_revision',\n 'release',\n 'short_version',\n 'version',\n }\n\n assert contents == expected\n | .venv\Lib\site-packages\numpy\tests\test_numpy_version.py | test_numpy_version.py | Python | 1,798 | 0.95 | 0.12963 | 0.073171 | react-lib | 156 | 2024-11-13T04:53:26.294913 | BSD-3-Clause | true | 91bfaabddb43889846cb750251c97381 |
import functools\nimport importlib\nimport inspect\nimport pkgutil\nimport subprocess\nimport sys\nimport sysconfig\nimport types\nimport warnings\n\nimport pytest\n\nimport numpy\nimport numpy as np\nfrom numpy.testing import IS_WASM\n\ntry:\n import ctypes\nexcept ImportError:\n ctypes = None\n\n\ndef check_dir(module, module_name=None):\n """Returns a mapping of all objects with the wrong __module__ attribute."""\n if module_name is None:\n module_name = module.__name__\n results = {}\n for name in dir(module):\n if name == "core":\n continue\n item = getattr(module, name)\n if (hasattr(item, '__module__') and hasattr(item, '__name__')\n and item.__module__ != module_name):\n results[name] = item.__module__ + '.' + item.__name__\n return results\n\n\ndef test_numpy_namespace():\n # We override dir to not show these members\n allowlist = {\n 'recarray': 'numpy.rec.recarray',\n }\n bad_results = check_dir(np)\n # pytest gives better error messages with the builtin assert than with\n # assert_equal\n assert bad_results == allowlist\n\n\n@pytest.mark.skipif(IS_WASM, reason="can't start subprocess")\n@pytest.mark.parametrize('name', ['testing'])\ndef test_import_lazy_import(name):\n """Make sure we can actually use the modules we lazy load.\n\n While not exported as part of the public API, it was accessible. With the\n use of __getattr__ and __dir__, this isn't always true It can happen that\n an infinite recursion may happen.\n\n This is the only way I found that would force the failure to appear on the\n badly implemented code.\n\n We also test for the presence of the lazily imported modules in dir\n\n """\n exe = (sys.executable, '-c', "import numpy; numpy." + name)\n result = subprocess.check_output(exe)\n assert not result\n\n # Make sure they are still in the __dir__\n assert name in dir(np)\n\n\ndef test_dir_testing():\n """Assert that output of dir has only one "testing/tester"\n attribute without duplicate"""\n assert len(dir(np)) == len(set(dir(np)))\n\n\ndef test_numpy_linalg():\n bad_results = check_dir(np.linalg)\n assert bad_results == {}\n\n\ndef test_numpy_fft():\n bad_results = check_dir(np.fft)\n assert bad_results == {}\n\n\n@pytest.mark.skipif(ctypes is None,\n reason="ctypes not available in this python")\ndef test_NPY_NO_EXPORT():\n cdll = ctypes.CDLL(np._core._multiarray_tests.__file__)\n # Make sure an arbitrary NPY_NO_EXPORT function is actually hidden\n f = getattr(cdll, 'test_not_exported', None)\n assert f is None, ("'test_not_exported' is mistakenly exported, "\n "NPY_NO_EXPORT does not work")\n\n\n# Historically NumPy has not used leading underscores for private submodules\n# much. This has resulted in lots of things that look like public modules\n# (i.e. things that can be imported as `import numpy.somesubmodule.somefile`),\n# but were never intended to be public. The PUBLIC_MODULES list contains\n# modules that are either public because they were meant to be, or because they\n# contain public functions/objects that aren't present in any other namespace\n# for whatever reason and therefore should be treated as public.\n#\n# The PRIVATE_BUT_PRESENT_MODULES list contains modules that look public (lack\n# of underscores) but should not be used. For many of those modules the\n# current status is fine. For others it may make sense to work on making them\n# private, to clean up our public API and avoid confusion.\nPUBLIC_MODULES = ['numpy.' + s for s in [\n "ctypeslib",\n "dtypes",\n "exceptions",\n "f2py",\n "fft",\n "lib",\n "lib.array_utils",\n "lib.format",\n "lib.introspect",\n "lib.mixins",\n "lib.npyio",\n "lib.recfunctions", # note: still needs cleaning, was forgotten for 2.0\n "lib.scimath",\n "lib.stride_tricks",\n "linalg",\n "ma",\n "ma.extras",\n "ma.mrecords",\n "polynomial",\n "polynomial.chebyshev",\n "polynomial.hermite",\n "polynomial.hermite_e",\n "polynomial.laguerre",\n "polynomial.legendre",\n "polynomial.polynomial",\n "random",\n "strings",\n "testing",\n "testing.overrides",\n "typing",\n "typing.mypy_plugin",\n "version",\n]]\nif sys.version_info < (3, 12):\n PUBLIC_MODULES += [\n 'numpy.' + s for s in [\n "distutils",\n "distutils.cpuinfo",\n "distutils.exec_command",\n "distutils.misc_util",\n "distutils.log",\n "distutils.system_info",\n ]\n ]\n\n\nPUBLIC_ALIASED_MODULES = [\n "numpy.char",\n "numpy.emath",\n "numpy.rec",\n]\n\n\nPRIVATE_BUT_PRESENT_MODULES = ['numpy.' + s for s in [\n "conftest",\n "core",\n "core.multiarray",\n "core.numeric",\n "core.umath",\n "core.arrayprint",\n "core.defchararray",\n "core.einsumfunc",\n "core.fromnumeric",\n "core.function_base",\n "core.getlimits",\n "core.numerictypes",\n "core.overrides",\n "core.records",\n "core.shape_base",\n "f2py.auxfuncs",\n "f2py.capi_maps",\n "f2py.cb_rules",\n "f2py.cfuncs",\n "f2py.common_rules",\n "f2py.crackfortran",\n "f2py.diagnose",\n "f2py.f2py2e",\n "f2py.f90mod_rules",\n "f2py.func2subr",\n "f2py.rules",\n "f2py.symbolic",\n "f2py.use_rules",\n "fft.helper",\n "lib.user_array", # note: not in np.lib, but probably should just be deleted\n "linalg.lapack_lite",\n "linalg.linalg",\n "ma.core",\n "ma.testutils",\n "matlib",\n "matrixlib",\n "matrixlib.defmatrix",\n "polynomial.polyutils",\n "random.mtrand",\n "random.bit_generator",\n "testing.print_coercion_tables",\n]]\nif sys.version_info < (3, 12):\n PRIVATE_BUT_PRESENT_MODULES += [\n 'numpy.' + s for s in [\n "distutils.armccompiler",\n "distutils.fujitsuccompiler",\n "distutils.ccompiler",\n 'distutils.ccompiler_opt',\n "distutils.command",\n "distutils.command.autodist",\n "distutils.command.bdist_rpm",\n "distutils.command.build",\n "distutils.command.build_clib",\n "distutils.command.build_ext",\n "distutils.command.build_py",\n "distutils.command.build_scripts",\n "distutils.command.build_src",\n "distutils.command.config",\n "distutils.command.config_compiler",\n "distutils.command.develop",\n "distutils.command.egg_info",\n "distutils.command.install",\n "distutils.command.install_clib",\n "distutils.command.install_data",\n "distutils.command.install_headers",\n "distutils.command.sdist",\n "distutils.conv_template",\n "distutils.core",\n "distutils.extension",\n "distutils.fcompiler",\n "distutils.fcompiler.absoft",\n "distutils.fcompiler.arm",\n "distutils.fcompiler.compaq",\n "distutils.fcompiler.environment",\n "distutils.fcompiler.g95",\n "distutils.fcompiler.gnu",\n "distutils.fcompiler.hpux",\n "distutils.fcompiler.ibm",\n "distutils.fcompiler.intel",\n "distutils.fcompiler.lahey",\n "distutils.fcompiler.mips",\n "distutils.fcompiler.nag",\n "distutils.fcompiler.none",\n "distutils.fcompiler.pathf95",\n "distutils.fcompiler.pg",\n "distutils.fcompiler.nv",\n "distutils.fcompiler.sun",\n "distutils.fcompiler.vast",\n "distutils.fcompiler.fujitsu",\n "distutils.from_template",\n "distutils.intelccompiler",\n "distutils.lib2def",\n "distutils.line_endings",\n "distutils.mingw32ccompiler",\n "distutils.msvccompiler",\n "distutils.npy_pkg_config",\n "distutils.numpy_distribution",\n "distutils.pathccompiler",\n "distutils.unixccompiler",\n ]\n ]\n\n\ndef is_unexpected(name):\n """Check if this needs to be considered."""\n return (\n '._' not in name and '.tests' not in name and '.setup' not in name\n and name not in PUBLIC_MODULES\n and name not in PUBLIC_ALIASED_MODULES\n and name not in PRIVATE_BUT_PRESENT_MODULES\n )\n\n\nif sys.version_info >= (3, 12):\n SKIP_LIST = []\nelse:\n SKIP_LIST = ["numpy.distutils.msvc9compiler"]\n\n\ndef test_all_modules_are_expected():\n """\n Test that we don't add anything that looks like a new public module by\n accident. Check is based on filenames.\n """\n\n modnames = []\n for _, modname, ispkg in pkgutil.walk_packages(path=np.__path__,\n prefix=np.__name__ + '.',\n onerror=None):\n if is_unexpected(modname) and modname not in SKIP_LIST:\n # We have a name that is new. If that's on purpose, add it to\n # PUBLIC_MODULES. We don't expect to have to add anything to\n # PRIVATE_BUT_PRESENT_MODULES. Use an underscore in the name!\n modnames.append(modname)\n\n if modnames:\n raise AssertionError(f'Found unexpected modules: {modnames}')\n\n\n# Stuff that clearly shouldn't be in the API and is detected by the next test\n# below\nSKIP_LIST_2 = [\n 'numpy.lib.math',\n 'numpy.matlib.char',\n 'numpy.matlib.rec',\n 'numpy.matlib.emath',\n 'numpy.matlib.exceptions',\n 'numpy.matlib.math',\n 'numpy.matlib.linalg',\n 'numpy.matlib.fft',\n 'numpy.matlib.random',\n 'numpy.matlib.ctypeslib',\n 'numpy.matlib.ma',\n]\nif sys.version_info < (3, 12):\n SKIP_LIST_2 += [\n 'numpy.distutils.log.sys',\n 'numpy.distutils.log.logging',\n 'numpy.distutils.log.warnings',\n ]\n\n\ndef test_all_modules_are_expected_2():\n """\n Method checking all objects. The pkgutil-based method in\n `test_all_modules_are_expected` does not catch imports into a namespace,\n only filenames. So this test is more thorough, and checks this like:\n\n import .lib.scimath as emath\n\n To check if something in a module is (effectively) public, one can check if\n there's anything in that namespace that's a public function/object but is\n not exposed in a higher-level namespace. For example for a `numpy.lib`\n submodule::\n\n mod = np.lib.mixins\n for obj in mod.__all__:\n if obj in np.__all__:\n continue\n elif obj in np.lib.__all__:\n continue\n\n else:\n print(obj)\n\n """\n\n def find_unexpected_members(mod_name):\n members = []\n module = importlib.import_module(mod_name)\n if hasattr(module, '__all__'):\n objnames = module.__all__\n else:\n objnames = dir(module)\n\n for objname in objnames:\n if not objname.startswith('_'):\n fullobjname = mod_name + '.' + objname\n if isinstance(getattr(module, objname), types.ModuleType):\n if is_unexpected(fullobjname):\n if fullobjname not in SKIP_LIST_2:\n members.append(fullobjname)\n\n return members\n\n unexpected_members = find_unexpected_members("numpy")\n for modname in PUBLIC_MODULES:\n unexpected_members.extend(find_unexpected_members(modname))\n\n if unexpected_members:\n raise AssertionError("Found unexpected object(s) that look like "\n f"modules: {unexpected_members}")\n\n\ndef test_api_importable():\n """\n Check that all submodules listed higher up in this file can be imported\n\n Note that if a PRIVATE_BUT_PRESENT_MODULES entry goes missing, it may\n simply need to be removed from the list (deprecation may or may not be\n needed - apply common sense).\n """\n def check_importable(module_name):\n try:\n importlib.import_module(module_name)\n except (ImportError, AttributeError):\n return False\n\n return True\n\n module_names = []\n for module_name in PUBLIC_MODULES:\n if not check_importable(module_name):\n module_names.append(module_name)\n\n if module_names:\n raise AssertionError("Modules in the public API that cannot be "\n f"imported: {module_names}")\n\n for module_name in PUBLIC_ALIASED_MODULES:\n try:\n eval(module_name)\n except AttributeError:\n module_names.append(module_name)\n\n if module_names:\n raise AssertionError("Modules in the public API that were not "\n f"found: {module_names}")\n\n with warnings.catch_warnings(record=True) as w:\n warnings.filterwarnings('always', category=DeprecationWarning)\n warnings.filterwarnings('always', category=ImportWarning)\n for module_name in PRIVATE_BUT_PRESENT_MODULES:\n if not check_importable(module_name):\n module_names.append(module_name)\n\n if module_names:\n raise AssertionError("Modules that are not really public but looked "\n "public and can not be imported: "\n f"{module_names}")\n\n\n@pytest.mark.xfail(\n sysconfig.get_config_var("Py_DEBUG") not in (None, 0, "0"),\n reason=(\n "NumPy possibly built with `USE_DEBUG=True ./tools/travis-test.sh`, "\n "which does not expose the `array_api` entry point. "\n "See https://github.com/numpy/numpy/pull/19800"\n ),\n)\ndef test_array_api_entry_point():\n """\n Entry point for Array API implementation can be found with importlib and\n returns the main numpy namespace.\n """\n # For a development install that did not go through meson-python,\n # the entrypoint will not have been installed. So ensure this test fails\n # only if numpy is inside site-packages.\n numpy_in_sitepackages = sysconfig.get_path('platlib') in np.__file__\n\n eps = importlib.metadata.entry_points()\n xp_eps = eps.select(group="array_api")\n if len(xp_eps) == 0:\n if numpy_in_sitepackages:\n msg = "No entry points for 'array_api' found"\n raise AssertionError(msg) from None\n return\n\n try:\n ep = next(ep for ep in xp_eps if ep.name == "numpy")\n except StopIteration:\n if numpy_in_sitepackages:\n msg = "'numpy' not in array_api entry points"\n raise AssertionError(msg) from None\n return\n\n if ep.value == 'numpy.array_api':\n # Looks like the entrypoint for the current numpy build isn't\n # installed, but an older numpy is also installed and hence the\n # entrypoint is pointing to the old (no longer existing) location.\n # This isn't a problem except for when running tests with `spin` or an\n # in-place build.\n return\n\n xp = ep.load()\n msg = (\n f"numpy entry point value '{ep.value}' "\n "does not point to our Array API implementation"\n )\n assert xp is numpy, msg\n\n\ndef test_main_namespace_all_dir_coherence():\n """\n Checks if `dir(np)` and `np.__all__` are consistent and return\n the same content, excluding exceptions and private members.\n """\n def _remove_private_members(member_set):\n return {m for m in member_set if not m.startswith('_')}\n\n def _remove_exceptions(member_set):\n return member_set.difference({\n "bool" # included only in __dir__\n })\n\n all_members = _remove_private_members(np.__all__)\n all_members = _remove_exceptions(all_members)\n\n dir_members = _remove_private_members(np.__dir__())\n dir_members = _remove_exceptions(dir_members)\n\n assert all_members == dir_members, (\n "Members that break symmetry: "\n f"{all_members.symmetric_difference(dir_members)}"\n )\n\n\n@pytest.mark.filterwarnings(\n r"ignore:numpy.core(\.\w+)? is deprecated:DeprecationWarning"\n)\ndef test_core_shims_coherence():\n """\n Check that all "semi-public" members of `numpy._core` are also accessible\n from `numpy.core` shims.\n """\n import numpy.core as core\n\n for member_name in dir(np._core):\n # Skip private and test members. Also if a module is aliased,\n # no need to add it to np.core\n if (\n member_name.startswith("_")\n or member_name in ["tests", "strings"]\n or f"numpy.{member_name}" in PUBLIC_ALIASED_MODULES\n ):\n continue\n\n member = getattr(np._core, member_name)\n\n # np.core is a shim and all submodules of np.core are shims\n # but we should be able to import everything in those shims\n # that are available in the "real" modules in np._core, with\n # the exception of the namespace packages (__spec__.origin is None),\n # like numpy._core.include, or numpy._core.lib.pkgconfig.\n if (\n inspect.ismodule(member)\n and member.__spec__ and member.__spec__.origin is not None\n ):\n submodule = member\n submodule_name = member_name\n for submodule_member_name in dir(submodule):\n # ignore dunder names\n if submodule_member_name.startswith("__"):\n continue\n submodule_member = getattr(submodule, submodule_member_name)\n\n core_submodule = __import__(\n f"numpy.core.{submodule_name}",\n fromlist=[submodule_member_name]\n )\n\n assert submodule_member is getattr(\n core_submodule, submodule_member_name\n )\n\n else:\n assert member is getattr(core, member_name)\n\n\ndef test_functions_single_location():\n """\n Check that each public function is available from one location only.\n\n Test performs BFS search traversing NumPy's public API. It flags\n any function-like object that is accessible from more that one place.\n """\n from collections.abc import Callable\n from typing import Any\n\n from numpy._core._multiarray_umath import (\n _ArrayFunctionDispatcher as dispatched_function,\n )\n\n visited_modules: set[types.ModuleType] = {np}\n visited_functions: set[Callable[..., Any]] = set()\n # Functions often have `__name__` overridden, therefore we need\n # to keep track of locations where functions have been found.\n functions_original_paths: dict[Callable[..., Any], str] = {}\n\n # Here we aggregate functions with more than one location.\n # It must be empty for the test to pass.\n duplicated_functions: list[tuple] = []\n\n modules_queue = [np]\n\n while len(modules_queue) > 0:\n\n module = modules_queue.pop()\n\n for member_name in dir(module):\n member = getattr(module, member_name)\n\n # first check if we got a module\n if (\n inspect.ismodule(member) and # it's a module\n "numpy" in member.__name__ and # inside NumPy\n not member_name.startswith("_") and # not private\n "numpy._core" not in member.__name__ and # outside _core\n # not a legacy or testing module\n member_name not in ["f2py", "ma", "testing", "tests"] and\n member not in visited_modules # not visited yet\n ):\n modules_queue.append(member)\n visited_modules.add(member)\n\n # else check if we got a function-like object\n elif (\n inspect.isfunction(member) or\n isinstance(member, (dispatched_function, np.ufunc))\n ):\n if member in visited_functions:\n\n # skip main namespace functions with aliases\n if (\n member.__name__ in [\n "absolute", # np.abs\n "arccos", # np.acos\n "arccosh", # np.acosh\n "arcsin", # np.asin\n "arcsinh", # np.asinh\n "arctan", # np.atan\n "arctan2", # np.atan2\n "arctanh", # np.atanh\n "left_shift", # np.bitwise_left_shift\n "right_shift", # np.bitwise_right_shift\n "conjugate", # np.conj\n "invert", # np.bitwise_not & np.bitwise_invert\n "remainder", # np.mod\n "divide", # np.true_divide\n "concatenate", # np.concat\n "power", # np.pow\n "transpose", # np.permute_dims\n ] and\n module.__name__ == "numpy"\n ):\n continue\n # skip trimcoef from numpy.polynomial as it is\n # duplicated by design.\n if (\n member.__name__ == "trimcoef" and\n module.__name__.startswith("numpy.polynomial")\n ):\n continue\n\n # skip ufuncs that are exported in np.strings as well\n if member.__name__ in (\n "add",\n "equal",\n "not_equal",\n "greater",\n "greater_equal",\n "less",\n "less_equal",\n ) and module.__name__ == "numpy.strings":\n continue\n\n # numpy.char reexports all numpy.strings functions for\n # backwards-compatibility\n if module.__name__ == "numpy.char":\n continue\n\n # function is present in more than one location!\n duplicated_functions.append(\n (member.__name__,\n module.__name__,\n functions_original_paths[member])\n )\n else:\n visited_functions.add(member)\n functions_original_paths[member] = module.__name__\n\n del visited_functions, visited_modules, functions_original_paths\n\n assert len(duplicated_functions) == 0, duplicated_functions\n\n\ndef test___module___attribute():\n modules_queue = [np]\n visited_modules = {np}\n visited_functions = set()\n incorrect_entries = []\n\n while len(modules_queue) > 0:\n module = modules_queue.pop()\n for member_name in dir(module):\n member = getattr(module, member_name)\n # first check if we got a module\n if (\n inspect.ismodule(member) and # it's a module\n "numpy" in member.__name__ and # inside NumPy\n not member_name.startswith("_") and # not private\n "numpy._core" not in member.__name__ and # outside _core\n # not in a skip module list\n member_name not in [\n "char", "core", "f2py", "ma", "lapack_lite", "mrecords",\n "testing", "tests", "polynomial", "typing", "mtrand",\n "bit_generator",\n ] and\n member not in visited_modules # not visited yet\n ):\n modules_queue.append(member)\n visited_modules.add(member)\n elif (\n not inspect.ismodule(member) and\n hasattr(member, "__name__") and\n not member.__name__.startswith("_") and\n member.__module__ != module.__name__ and\n member not in visited_functions\n ):\n # skip ufuncs that are exported in np.strings as well\n if member.__name__ in (\n "add", "equal", "not_equal", "greater", "greater_equal",\n "less", "less_equal",\n ) and module.__name__ == "numpy.strings":\n continue\n\n # recarray and record are exported in np and np.rec\n if (\n (member.__name__ == "recarray" and module.__name__ == "numpy") or\n (member.__name__ == "record" and module.__name__ == "numpy.rec")\n ):\n continue\n\n # ctypeslib exports ctypes c_long/c_longlong\n if (\n member.__name__ in ("c_long", "c_longlong") and\n module.__name__ == "numpy.ctypeslib"\n ):\n continue\n\n # skip cdef classes\n if member.__name__ in (\n "BitGenerator", "Generator", "MT19937", "PCG64", "PCG64DXSM",\n "Philox", "RandomState", "SFC64", "SeedSequence",\n ):\n continue\n\n incorrect_entries.append(\n {\n "Func": member.__name__,\n "actual": member.__module__,\n "expected": module.__name__,\n }\n )\n visited_functions.add(member)\n\n if incorrect_entries:\n assert len(incorrect_entries) == 0, incorrect_entries\n\n\ndef _check_correct_qualname_and_module(obj) -> bool:\n qualname = obj.__qualname__\n name = obj.__name__\n module_name = obj.__module__\n assert name == qualname.split(".")[-1]\n\n module = sys.modules[module_name]\n actual_obj = functools.reduce(getattr, qualname.split("."), module)\n return (\n actual_obj is obj or\n # `obj` may be a bound method/property of `actual_obj`:\n (\n hasattr(actual_obj, "__get__") and hasattr(obj, "__self__") and\n actual_obj.__module__ == obj.__module__ and\n actual_obj.__qualname__ == qualname\n )\n )\n\n\ndef test___qualname___and___module___attribute():\n # NumPy messes with module and name/qualname attributes, but any object\n # should be discoverable based on its module and qualname, so test that.\n # We do this for anything with a name (ensuring qualname is also set).\n modules_queue = [np]\n visited_modules = {np}\n visited_functions = set()\n incorrect_entries = []\n\n while len(modules_queue) > 0:\n module = modules_queue.pop()\n for member_name in dir(module):\n member = getattr(module, member_name)\n # first check if we got a module\n if (\n inspect.ismodule(member) and # it's a module\n "numpy" in member.__name__ and # inside NumPy\n not member_name.startswith("_") and # not private\n member_name not in {"tests", "typing"} and # 2024-12: type names don't match\n "numpy._core" not in member.__name__ and # outside _core\n member not in visited_modules # not visited yet\n ):\n modules_queue.append(member)\n visited_modules.add(member)\n elif (\n not inspect.ismodule(member) and\n hasattr(member, "__name__") and\n not member.__name__.startswith("_") and\n not member_name.startswith("_") and\n not _check_correct_qualname_and_module(member) and\n member not in visited_functions\n ):\n incorrect_entries.append(\n {\n "found_at": f"{module.__name__}:{member_name}",\n "advertises": f"{member.__module__}:{member.__qualname__}",\n }\n )\n visited_functions.add(member)\n\n if incorrect_entries:\n assert len(incorrect_entries) == 0, incorrect_entries\n | .venv\Lib\site-packages\numpy\tests\test_public_api.py | test_public_api.py | Python | 28,657 | 0.95 | 0.151365 | 0.090909 | react-lib | 628 | 2025-01-21T01:49:50.913852 | BSD-3-Clause | true | 2c39250d90bc692ba1f2f03049b7e236 |
import pickle\nimport subprocess\nimport sys\nimport textwrap\nfrom importlib import reload\n\nimport pytest\n\nimport numpy.exceptions as ex\nfrom numpy.testing import (\n IS_WASM,\n assert_,\n assert_equal,\n assert_raises,\n assert_warns,\n)\n\n\ndef test_numpy_reloading():\n # gh-7844. Also check that relevant globals retain their identity.\n import numpy as np\n import numpy._globals\n\n _NoValue = np._NoValue\n VisibleDeprecationWarning = ex.VisibleDeprecationWarning\n ModuleDeprecationWarning = ex.ModuleDeprecationWarning\n\n with assert_warns(UserWarning):\n reload(np)\n assert_(_NoValue is np._NoValue)\n assert_(ModuleDeprecationWarning is ex.ModuleDeprecationWarning)\n assert_(VisibleDeprecationWarning is ex.VisibleDeprecationWarning)\n\n assert_raises(RuntimeError, reload, numpy._globals)\n with assert_warns(UserWarning):\n reload(np)\n assert_(_NoValue is np._NoValue)\n assert_(ModuleDeprecationWarning is ex.ModuleDeprecationWarning)\n assert_(VisibleDeprecationWarning is ex.VisibleDeprecationWarning)\n\ndef test_novalue():\n import numpy as np\n for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):\n assert_equal(repr(np._NoValue), '<no value>')\n assert_(pickle.loads(pickle.dumps(np._NoValue,\n protocol=proto)) is np._NoValue)\n\n\n@pytest.mark.skipif(IS_WASM, reason="can't start subprocess")\ndef test_full_reimport():\n """At the time of writing this, it is *not* truly supported, but\n apparently enough users rely on it, for it to be an annoying change\n when it started failing previously.\n """\n # Test within a new process, to ensure that we do not mess with the\n # global state during the test run (could lead to cryptic test failures).\n # This is generally unsafe, especially, since we also reload the C-modules.\n code = textwrap.dedent(r"""\n import sys\n from pytest import warns\n import numpy as np\n\n for k in list(sys.modules.keys()):\n if "numpy" in k:\n del sys.modules[k]\n\n with warns(UserWarning):\n import numpy as np\n """)\n p = subprocess.run([sys.executable, '-c', code], capture_output=True)\n if p.returncode:\n raise AssertionError(\n f"Non-zero return code: {p.returncode!r}\n\n{p.stderr.decode()}"\n )\n | .venv\Lib\site-packages\numpy\tests\test_reloading.py | test_reloading.py | Python | 2,441 | 0.95 | 0.108108 | 0.064516 | vue-tools | 204 | 2024-03-10T12:58:25.869263 | GPL-3.0 | true | d30960347c8a5f68ca9acf1d7d64b697 |
""" Test scripts\n\nTest that we can run executable scripts that have been installed with numpy.\n"""\nimport os\nimport subprocess\nimport sys\nfrom os.path import dirname, isfile\nfrom os.path import join as pathjoin\n\nimport pytest\n\nimport numpy as np\nfrom numpy.testing import IS_WASM, assert_equal\n\nis_inplace = isfile(pathjoin(dirname(np.__file__), '..', 'setup.py'))\n\n\ndef find_f2py_commands():\n if sys.platform == 'win32':\n exe_dir = dirname(sys.executable)\n if exe_dir.endswith('Scripts'): # virtualenv\n return [os.path.join(exe_dir, 'f2py')]\n else:\n return [os.path.join(exe_dir, "Scripts", 'f2py')]\n else:\n # Three scripts are installed in Unix-like systems:\n # 'f2py', 'f2py{major}', and 'f2py{major.minor}'. For example,\n # if installed with python3.9 the scripts would be named\n # 'f2py', 'f2py3', and 'f2py3.9'.\n version = sys.version_info\n major = str(version.major)\n minor = str(version.minor)\n return ['f2py', 'f2py' + major, 'f2py' + major + '.' + minor]\n\n\n@pytest.mark.skipif(is_inplace, reason="Cannot test f2py command inplace")\n@pytest.mark.xfail(reason="Test is unreliable")\n@pytest.mark.parametrize('f2py_cmd', find_f2py_commands())\ndef test_f2py(f2py_cmd):\n # test that we can run f2py script\n stdout = subprocess.check_output([f2py_cmd, '-v'])\n assert_equal(stdout.strip(), np.__version__.encode('ascii'))\n\n\n@pytest.mark.skipif(IS_WASM, reason="Cannot start subprocess")\ndef test_pep338():\n stdout = subprocess.check_output([sys.executable, '-mnumpy.f2py', '-v'])\n assert_equal(stdout.strip(), np.__version__.encode('ascii'))\n | .venv\Lib\site-packages\numpy\tests\test_scripts.py | test_scripts.py | Python | 1,714 | 0.95 | 0.122449 | 0.128205 | vue-tools | 558 | 2024-09-18T05:17:07.764769 | BSD-3-Clause | true | e3c8ab9e6975292cf41d34e355533896 |
"""\nTests which scan for certain occurrences in the code, they may not find\nall of these occurrences but should catch almost all.\n"""\nimport ast\nimport tokenize\nfrom pathlib import Path\n\nimport pytest\n\nimport numpy\n\n\nclass ParseCall(ast.NodeVisitor):\n def __init__(self):\n self.ls = []\n\n def visit_Attribute(self, node):\n ast.NodeVisitor.generic_visit(self, node)\n self.ls.append(node.attr)\n\n def visit_Name(self, node):\n self.ls.append(node.id)\n\n\nclass FindFuncs(ast.NodeVisitor):\n def __init__(self, filename):\n super().__init__()\n self.__filename = filename\n\n def visit_Call(self, node):\n p = ParseCall()\n p.visit(node.func)\n ast.NodeVisitor.generic_visit(self, node)\n\n if p.ls[-1] == 'simplefilter' or p.ls[-1] == 'filterwarnings':\n if node.args[0].value == "ignore":\n raise AssertionError(\n "warnings should have an appropriate stacklevel; "\n f"found in {self.__filename} on line {node.lineno}")\n\n if p.ls[-1] == 'warn' and (\n len(p.ls) == 1 or p.ls[-2] == 'warnings'):\n\n if "testing/tests/test_warnings.py" == self.__filename:\n # This file\n return\n\n # See if stacklevel exists:\n if len(node.args) == 3:\n return\n args = {kw.arg for kw in node.keywords}\n if "stacklevel" in args:\n return\n raise AssertionError(\n "warnings should have an appropriate stacklevel; "\n f"found in {self.__filename} on line {node.lineno}")\n\n\n@pytest.mark.slow\ndef test_warning_calls():\n # combined "ignore" and stacklevel error\n base = Path(numpy.__file__).parent\n\n for path in base.rglob("*.py"):\n if base / "testing" in path.parents:\n continue\n if path == base / "__init__.py":\n continue\n if path == base / "random" / "__init__.py":\n continue\n if path == base / "conftest.py":\n continue\n # use tokenize to auto-detect encoding on systems where no\n # default encoding is defined (e.g. LANG='C')\n with tokenize.open(str(path)) as file:\n tree = ast.parse(file.read())\n FindFuncs(path).visit(tree)\n | .venv\Lib\site-packages\numpy\tests\test_warnings.py | test_warnings.py | Python | 2,406 | 0.95 | 0.294872 | 0.080645 | vue-tools | 9 | 2024-03-22T01:03:05.796554 | Apache-2.0 | true | 9cb657512c2bdfcd8d0878a6a1f70449 |
\nimport collections\n\nimport numpy as np\n\n\ndef test_no_duplicates_in_np__all__():\n # Regression test for gh-10198.\n dups = {k: v for k, v in collections.Counter(np.__all__).items() if v > 1}\n assert len(dups) == 0\n | .venv\Lib\site-packages\numpy\tests\test__all__.py | test__all__.py | Python | 232 | 0.95 | 0.4 | 0.166667 | react-lib | 156 | 2025-06-06T22:56:10.683755 | BSD-3-Clause | true | 1aae8a09cf4d5aae2db31e3807003c58 |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test_configtool.cpython-313.pyc | test_configtool.cpython-313.pyc | Other | 3,790 | 0.95 | 0 | 0 | python-kit | 910 | 2025-01-09T21:16:10.581694 | BSD-3-Clause | true | cb03032798620e1da471293d856948fd |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test_ctypeslib.cpython-313.pyc | test_ctypeslib.cpython-313.pyc | Other | 22,016 | 0.95 | 0 | 0 | react-lib | 573 | 2024-02-11T19:41:25.605600 | BSD-3-Clause | true | 63c3287691744d700c3796bfd747393b |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test_lazyloading.cpython-313.pyc | test_lazyloading.cpython-313.pyc | Other | 1,774 | 0.95 | 0 | 0 | node-utils | 653 | 2023-12-01T19:00:40.334118 | Apache-2.0 | true | c7f732fc23f57e10eaed9b4a052ca774 |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test_matlib.cpython-313.pyc | test_matlib.cpython-313.pyc | Other | 4,225 | 0.8 | 0 | 0 | node-utils | 671 | 2025-02-04T14:49:28.673847 | MIT | true | 0c3af4b8c6b809910ec1dc5c7305be8b |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test_numpy_config.cpython-313.pyc | test_numpy_config.cpython-313.pyc | Other | 2,963 | 0.95 | 0.02381 | 0.076923 | react-lib | 442 | 2023-10-08T02:47:11.669622 | Apache-2.0 | true | d82b4422cf1ec98c173ed220f90d7c14 |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test_numpy_version.cpython-313.pyc | test_numpy_version.cpython-313.pyc | Other | 2,501 | 0.8 | 0 | 0 | react-lib | 351 | 2025-05-04T04:48:00.287253 | MIT | true | 9e9b44f924f7541257a95c6b4702fffa |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test_public_api.cpython-313.pyc | test_public_api.cpython-313.pyc | Other | 25,200 | 0.95 | 0.06383 | 0.009174 | awesome-app | 856 | 2025-04-22T07:58:18.370133 | BSD-3-Clause | true | 5e65d30085f6b9953cc0aa665626035f |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test_reloading.cpython-313.pyc | test_reloading.cpython-313.pyc | Other | 3,540 | 0.95 | 0.052632 | 0.075472 | python-kit | 61 | 2025-03-14T21:54:39.537593 | Apache-2.0 | true | 1dc849d9f8d6cfbc664242d41ff36620 |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test_scripts.cpython-313.pyc | test_scripts.cpython-313.pyc | Other | 2,844 | 0.8 | 0 | 0 | awesome-app | 771 | 2025-06-22T23:31:01.386963 | Apache-2.0 | true | 2d92cb3841900157f170cc9fecba8aa7 |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test_warnings.cpython-313.pyc | test_warnings.cpython-313.pyc | Other | 4,441 | 0.8 | 0.057143 | 0 | python-kit | 269 | 2023-09-23T09:11:27.786567 | BSD-3-Clause | true | bf2170832e68f8619a4589dad98fd115 |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\test__all__.cpython-313.pyc | test__all__.cpython-313.pyc | Other | 712 | 0.7 | 0 | 0 | react-lib | 261 | 2025-04-01T19:59:33.784206 | Apache-2.0 | true | 68cb3fb13785adade9846fbc5efd0c94 |
\n\n | .venv\Lib\site-packages\numpy\tests\__pycache__\__init__.cpython-313.pyc | __init__.cpython-313.pyc | Other | 186 | 0.7 | 0 | 0 | awesome-app | 376 | 2024-01-05T22:02:36.785110 | BSD-3-Clause | true | ca0831a42c2235831b2642cddbc20a43 |
"""A mypy_ plugin for managing a number of platform-specific annotations.\nIts functionality can be split into three distinct parts:\n\n* Assigning the (platform-dependent) precisions of certain `~numpy.number`\n subclasses, including the likes of `~numpy.int_`, `~numpy.intp` and\n `~numpy.longlong`. See the documentation on\n :ref:`scalar types <arrays.scalars.built-in>` for a comprehensive overview\n of the affected classes. Without the plugin the precision of all relevant\n classes will be inferred as `~typing.Any`.\n* Removing all extended-precision `~numpy.number` subclasses that are\n unavailable for the platform in question. Most notably this includes the\n likes of `~numpy.float128` and `~numpy.complex256`. Without the plugin *all*\n extended-precision types will, as far as mypy is concerned, be available\n to all platforms.\n* Assigning the (platform-dependent) precision of `~numpy.ctypeslib.c_intp`.\n Without the plugin the type will default to `ctypes.c_int64`.\n\n .. versionadded:: 1.22\n\n.. deprecated:: 2.3\n\nExamples\n--------\nTo enable the plugin, one must add it to their mypy `configuration file`_:\n\n.. code-block:: ini\n\n [mypy]\n plugins = numpy.typing.mypy_plugin\n\n.. _mypy: https://mypy-lang.org/\n.. _configuration file: https://mypy.readthedocs.io/en/stable/config_file.html\n\n"""\n\nfrom collections.abc import Callable, Iterable\nfrom typing import TYPE_CHECKING, Final, TypeAlias, cast\n\nimport numpy as np\n\n__all__: list[str] = []\n\n\ndef _get_precision_dict() -> dict[str, str]:\n names = [\n ("_NBitByte", np.byte),\n ("_NBitShort", np.short),\n ("_NBitIntC", np.intc),\n ("_NBitIntP", np.intp),\n ("_NBitInt", np.int_),\n ("_NBitLong", np.long),\n ("_NBitLongLong", np.longlong),\n\n ("_NBitHalf", np.half),\n ("_NBitSingle", np.single),\n ("_NBitDouble", np.double),\n ("_NBitLongDouble", np.longdouble),\n ]\n ret: dict[str, str] = {}\n for name, typ in names:\n n = 8 * np.dtype(typ).itemsize\n ret[f"{_MODULE}._nbit.{name}"] = f"{_MODULE}._nbit_base._{n}Bit"\n return ret\n\n\ndef _get_extended_precision_list() -> list[str]:\n extended_names = [\n "float96",\n "float128",\n "complex192",\n "complex256",\n ]\n return [i for i in extended_names if hasattr(np, i)]\n\ndef _get_c_intp_name() -> str:\n # Adapted from `np.core._internal._getintp_ctype`\n return {\n "i": "c_int",\n "l": "c_long",\n "q": "c_longlong",\n }.get(np.dtype("n").char, "c_long")\n\n\n_MODULE: Final = "numpy._typing"\n\n#: A dictionary mapping type-aliases in `numpy._typing._nbit` to\n#: concrete `numpy.typing.NBitBase` subclasses.\n_PRECISION_DICT: Final = _get_precision_dict()\n\n#: A list with the names of all extended precision `np.number` subclasses.\n_EXTENDED_PRECISION_LIST: Final = _get_extended_precision_list()\n\n#: The name of the ctypes equivalent of `np.intp`\n_C_INTP: Final = _get_c_intp_name()\n\n\ntry:\n if TYPE_CHECKING:\n from mypy.typeanal import TypeAnalyser\n\n import mypy.types\n from mypy.build import PRI_MED\n from mypy.nodes import ImportFrom, MypyFile, Statement\n from mypy.plugin import AnalyzeTypeContext, Plugin\n\nexcept ModuleNotFoundError as e:\n\n def plugin(version: str) -> type:\n raise e\n\nelse:\n\n _HookFunc: TypeAlias = Callable[[AnalyzeTypeContext], mypy.types.Type]\n\n def _hook(ctx: AnalyzeTypeContext) -> mypy.types.Type:\n """Replace a type-alias with a concrete ``NBitBase`` subclass."""\n typ, _, api = ctx\n name = typ.name.split(".")[-1]\n name_new = _PRECISION_DICT[f"{_MODULE}._nbit.{name}"]\n return cast("TypeAnalyser", api).named_type(name_new)\n\n def _index(iterable: Iterable[Statement], id: str) -> int:\n """Identify the first ``ImportFrom`` instance the specified `id`."""\n for i, value in enumerate(iterable):\n if getattr(value, "id", None) == id:\n return i\n raise ValueError("Failed to identify a `ImportFrom` instance "\n f"with the following id: {id!r}")\n\n def _override_imports(\n file: MypyFile,\n module: str,\n imports: list[tuple[str, str | None]],\n ) -> None:\n """Override the first `module`-based import with new `imports`."""\n # Construct a new `from module import y` statement\n import_obj = ImportFrom(module, 0, names=imports)\n import_obj.is_top_level = True\n\n # Replace the first `module`-based import statement with `import_obj`\n for lst in [file.defs, cast("list[Statement]", file.imports)]:\n i = _index(lst, module)\n lst[i] = import_obj\n\n class _NumpyPlugin(Plugin):\n """A mypy plugin for handling versus numpy-specific typing tasks."""\n\n def get_type_analyze_hook(self, fullname: str) -> _HookFunc | None:\n """Set the precision of platform-specific `numpy.number`\n subclasses.\n\n For example: `numpy.int_`, `numpy.longlong` and `numpy.longdouble`.\n """\n if fullname in _PRECISION_DICT:\n return _hook\n return None\n\n def get_additional_deps(\n self, file: MypyFile\n ) -> list[tuple[int, str, int]]:\n """Handle all import-based overrides.\n\n * Import platform-specific extended-precision `numpy.number`\n subclasses (*e.g.* `numpy.float96` and `numpy.float128`).\n * Import the appropriate `ctypes` equivalent to `numpy.intp`.\n\n """\n fullname = file.fullname\n if fullname == "numpy":\n _override_imports(\n file,\n f"{_MODULE}._extended_precision",\n imports=[(v, v) for v in _EXTENDED_PRECISION_LIST],\n )\n elif fullname == "numpy.ctypeslib":\n _override_imports(\n file,\n "ctypes",\n imports=[(_C_INTP, "_c_intp")],\n )\n return [(PRI_MED, fullname, -1)]\n\n def plugin(version: str) -> type:\n import warnings\n\n plugin = "numpy.typing.mypy_plugin"\n # Deprecated 2025-01-10, NumPy 2.3\n warn_msg = (\n f"`{plugin}` is deprecated, and will be removed in a future "\n f"release. Please remove `plugins = {plugin}` in your mypy config."\n f"(deprecated in NumPy 2.3)"\n )\n warnings.warn(warn_msg, DeprecationWarning, stacklevel=3)\n\n return _NumpyPlugin\n | .venv\Lib\site-packages\numpy\typing\mypy_plugin.py | mypy_plugin.py | Python | 6,736 | 0.95 | 0.133333 | 0.084967 | python-kit | 737 | 2024-03-27T13:09:13.506441 | MIT | false | 23e5513871b3ed7641b0beced06d4c31 |
"""\n============================\nTyping (:mod:`numpy.typing`)\n============================\n\n.. versionadded:: 1.20\n\nLarge parts of the NumPy API have :pep:`484`-style type annotations. In\naddition a number of type aliases are available to users, most prominently\nthe two below:\n\n- `ArrayLike`: objects that can be converted to arrays\n- `DTypeLike`: objects that can be converted to dtypes\n\n.. _typing-extensions: https://pypi.org/project/typing-extensions/\n\nMypy plugin\n-----------\n\n.. versionadded:: 1.21\n\n.. automodule:: numpy.typing.mypy_plugin\n\n.. currentmodule:: numpy.typing\n\nDifferences from the runtime NumPy API\n--------------------------------------\n\nNumPy is very flexible. Trying to describe the full range of\npossibilities statically would result in types that are not very\nhelpful. For that reason, the typed NumPy API is often stricter than\nthe runtime NumPy API. This section describes some notable\ndifferences.\n\nArrayLike\n~~~~~~~~~\n\nThe `ArrayLike` type tries to avoid creating object arrays. For\nexample,\n\n.. code-block:: python\n\n >>> np.array(x**2 for x in range(10))\n array(<generator object <genexpr> at ...>, dtype=object)\n\nis valid NumPy code which will create a 0-dimensional object\narray. Type checkers will complain about the above example when using\nthe NumPy types however. If you really intended to do the above, then\nyou can either use a ``# type: ignore`` comment:\n\n.. code-block:: python\n\n >>> np.array(x**2 for x in range(10)) # type: ignore\n\nor explicitly type the array like object as `~typing.Any`:\n\n.. code-block:: python\n\n >>> from typing import Any\n >>> array_like: Any = (x**2 for x in range(10))\n >>> np.array(array_like)\n array(<generator object <genexpr> at ...>, dtype=object)\n\nndarray\n~~~~~~~\n\nIt's possible to mutate the dtype of an array at runtime. For example,\nthe following code is valid:\n\n.. code-block:: python\n\n >>> x = np.array([1, 2])\n >>> x.dtype = np.bool\n\nThis sort of mutation is not allowed by the types. Users who want to\nwrite statically typed code should instead use the `numpy.ndarray.view`\nmethod to create a view of the array with a different dtype.\n\nDTypeLike\n~~~~~~~~~\n\nThe `DTypeLike` type tries to avoid creation of dtype objects using\ndictionary of fields like below:\n\n.. code-block:: python\n\n >>> x = np.dtype({"field1": (float, 1), "field2": (int, 3)})\n\nAlthough this is valid NumPy code, the type checker will complain about it,\nsince its usage is discouraged.\nPlease see : :ref:`Data type objects <arrays.dtypes>`\n\nNumber precision\n~~~~~~~~~~~~~~~~\n\nThe precision of `numpy.number` subclasses is treated as a invariant generic\nparameter (see :class:`~NBitBase`), simplifying the annotating of processes\ninvolving precision-based casting.\n\n.. code-block:: python\n\n >>> from typing import TypeVar\n >>> import numpy as np\n >>> import numpy.typing as npt\n\n >>> T = TypeVar("T", bound=npt.NBitBase)\n >>> def func(a: "np.floating[T]", b: "np.floating[T]") -> "np.floating[T]":\n ... ...\n\nConsequently, the likes of `~numpy.float16`, `~numpy.float32` and\n`~numpy.float64` are still sub-types of `~numpy.floating`, but, contrary to\nruntime, they're not necessarily considered as sub-classes.\n\nTimedelta64\n~~~~~~~~~~~\n\nThe `~numpy.timedelta64` class is not considered a subclass of\n`~numpy.signedinteger`, the former only inheriting from `~numpy.generic`\nwhile static type checking.\n\n0D arrays\n~~~~~~~~~\n\nDuring runtime numpy aggressively casts any passed 0D arrays into their\ncorresponding `~numpy.generic` instance. Until the introduction of shape\ntyping (see :pep:`646`) it is unfortunately not possible to make the\nnecessary distinction between 0D and >0D arrays. While thus not strictly\ncorrect, all operations that can potentially perform a 0D-array -> scalar\ncast are currently annotated as exclusively returning an `~numpy.ndarray`.\n\nIf it is known in advance that an operation *will* perform a\n0D-array -> scalar cast, then one can consider manually remedying the\nsituation with either `typing.cast` or a ``# type: ignore`` comment.\n\nRecord array dtypes\n~~~~~~~~~~~~~~~~~~~\n\nThe dtype of `numpy.recarray`, and the :ref:`routines.array-creation.rec`\nfunctions in general, can be specified in one of two ways:\n\n* Directly via the ``dtype`` argument.\n* With up to five helper arguments that operate via `numpy.rec.format_parser`:\n ``formats``, ``names``, ``titles``, ``aligned`` and ``byteorder``.\n\nThese two approaches are currently typed as being mutually exclusive,\n*i.e.* if ``dtype`` is specified than one may not specify ``formats``.\nWhile this mutual exclusivity is not (strictly) enforced during runtime,\ncombining both dtype specifiers can lead to unexpected or even downright\nbuggy behavior.\n\nAPI\n---\n\n"""\n# NOTE: The API section will be appended with additional entries\n# further down in this file\n\n# pyright: reportDeprecated=false\n\nfrom numpy._typing import ArrayLike, DTypeLike, NBitBase, NDArray\n\n__all__ = ["ArrayLike", "DTypeLike", "NBitBase", "NDArray"]\n\n\n__DIR = __all__ + [k for k in globals() if k.startswith("__") and k.endswith("__")]\n__DIR_SET = frozenset(__DIR)\n\n\ndef __dir__() -> list[str]:\n return __DIR\n\ndef __getattr__(name: str):\n if name == "NBitBase":\n import warnings\n\n # Deprecated in NumPy 2.3, 2025-05-01\n warnings.warn(\n "`NBitBase` is deprecated and will be removed from numpy.typing in the "\n "future. Use `@typing.overload` or a `TypeVar` with a scalar-type as upper "\n "bound, instead. (deprecated in NumPy 2.3)",\n DeprecationWarning,\n stacklevel=2,\n )\n return NBitBase\n\n if name in __DIR_SET:\n return globals()[name]\n\n raise AttributeError(f"module {__name__!r} has no attribute {name!r}")\n\n\nif __doc__ is not None:\n from numpy._typing._add_docstring import _docstrings\n __doc__ += _docstrings\n __doc__ += '\n.. autoclass:: numpy.typing.NBitBase\n'\n del _docstrings\n\nfrom numpy._pytesttester import PytestTester\n\ntest = PytestTester(__name__)\ndel PytestTester\n | .venv\Lib\site-packages\numpy\typing\__init__.py | __init__.py | Python | 6,249 | 0.95 | 0.074627 | 0.05036 | vue-tools | 223 | 2025-04-30T22:34:46.836553 | BSD-3-Clause | false | fc8b6f150411db9fa5f36ccdb938e4af |
import os\nimport sys\nfrom pathlib import Path\n\nimport numpy as np\nfrom numpy.testing import assert_\n\nROOT = Path(np.__file__).parents[0]\nFILES = [\n ROOT / "py.typed",\n ROOT / "__init__.pyi",\n ROOT / "ctypeslib" / "__init__.pyi",\n ROOT / "_core" / "__init__.pyi",\n ROOT / "f2py" / "__init__.pyi",\n ROOT / "fft" / "__init__.pyi",\n ROOT / "lib" / "__init__.pyi",\n ROOT / "linalg" / "__init__.pyi",\n ROOT / "ma" / "__init__.pyi",\n ROOT / "matrixlib" / "__init__.pyi",\n ROOT / "polynomial" / "__init__.pyi",\n ROOT / "random" / "__init__.pyi",\n ROOT / "testing" / "__init__.pyi",\n]\nif sys.version_info < (3, 12):\n FILES += [ROOT / "distutils" / "__init__.pyi"]\n\n\nclass TestIsFile:\n def test_isfile(self):\n """Test if all ``.pyi`` files are properly installed."""\n for file in FILES:\n assert_(os.path.isfile(file))\n | .venv\Lib\site-packages\numpy\typing\tests\test_isfile.py | test_isfile.py | Python | 910 | 0.85 | 0.15625 | 0 | react-lib | 898 | 2025-02-26T02:40:48.158600 | BSD-3-Clause | true | ebb34143ae66a66563c1ac5005206591 |
"""Test the runtime usage of `numpy.typing`."""\n\nfrom typing import (\n Any,\n NamedTuple,\n Union, # pyright: ignore[reportDeprecated]\n get_args,\n get_origin,\n get_type_hints,\n)\n\nimport pytest\n\nimport numpy as np\nimport numpy._typing as _npt\nimport numpy.typing as npt\n\n\nclass TypeTup(NamedTuple):\n typ: type\n args: tuple[type, ...]\n origin: type | None\n\n\nNDArrayTup = TypeTup(npt.NDArray, npt.NDArray.__args__, np.ndarray)\n\nTYPES = {\n "ArrayLike": TypeTup(npt.ArrayLike, npt.ArrayLike.__args__, Union),\n "DTypeLike": TypeTup(npt.DTypeLike, npt.DTypeLike.__args__, Union),\n "NBitBase": TypeTup(npt.NBitBase, (), None),\n "NDArray": NDArrayTup,\n}\n\n\n@pytest.mark.parametrize("name,tup", TYPES.items(), ids=TYPES.keys())\ndef test_get_args(name: type, tup: TypeTup) -> None:\n """Test `typing.get_args`."""\n typ, ref = tup.typ, tup.args\n out = get_args(typ)\n assert out == ref\n\n\n@pytest.mark.parametrize("name,tup", TYPES.items(), ids=TYPES.keys())\ndef test_get_origin(name: type, tup: TypeTup) -> None:\n """Test `typing.get_origin`."""\n typ, ref = tup.typ, tup.origin\n out = get_origin(typ)\n assert out == ref\n\n\n@pytest.mark.parametrize("name,tup", TYPES.items(), ids=TYPES.keys())\ndef test_get_type_hints(name: type, tup: TypeTup) -> None:\n """Test `typing.get_type_hints`."""\n typ = tup.typ\n\n def func(a: typ) -> None: pass\n\n out = get_type_hints(func)\n ref = {"a": typ, "return": type(None)}\n assert out == ref\n\n\n@pytest.mark.parametrize("name,tup", TYPES.items(), ids=TYPES.keys())\ndef test_get_type_hints_str(name: type, tup: TypeTup) -> None:\n """Test `typing.get_type_hints` with string-representation of types."""\n typ_str, typ = f"npt.{name}", tup.typ\n\n def func(a: typ_str) -> None: pass\n\n out = get_type_hints(func)\n ref = {"a": typ, "return": type(None)}\n assert out == ref\n\n\ndef test_keys() -> None:\n """Test that ``TYPES.keys()`` and ``numpy.typing.__all__`` are synced."""\n keys = TYPES.keys()\n ref = set(npt.__all__)\n assert keys == ref\n\n\nPROTOCOLS: dict[str, tuple[type[Any], object]] = {\n "_SupportsDType": (_npt._SupportsDType, np.int64(1)),\n "_SupportsArray": (_npt._SupportsArray, np.arange(10)),\n "_SupportsArrayFunc": (_npt._SupportsArrayFunc, np.arange(10)),\n "_NestedSequence": (_npt._NestedSequence, [1]),\n}\n\n\n@pytest.mark.parametrize("cls,obj", PROTOCOLS.values(), ids=PROTOCOLS.keys())\nclass TestRuntimeProtocol:\n def test_isinstance(self, cls: type[Any], obj: object) -> None:\n assert isinstance(obj, cls)\n assert not isinstance(None, cls)\n\n def test_issubclass(self, cls: type[Any], obj: object) -> None:\n if cls is _npt._SupportsDType:\n pytest.xfail(\n "Protocols with non-method members don't support issubclass()"\n )\n assert issubclass(type(obj), cls)\n assert not issubclass(type(None), cls)\n | .venv\Lib\site-packages\numpy\typing\tests\test_runtime.py | test_runtime.py | Python | 3,021 | 0.95 | 0.117647 | 0 | react-lib | 71 | 2024-12-18T06:31:56.233409 | BSD-3-Clause | true | e348cd43e4d65656081c31a620478c3b |
import importlib.util\nimport os\nimport re\nimport shutil\nimport textwrap\nfrom collections import defaultdict\nfrom typing import TYPE_CHECKING\n\nimport pytest\n\n# Only trigger a full `mypy` run if this environment variable is set\n# Note that these tests tend to take over a minute even on a macOS M1 CPU,\n# and more than that in CI.\nRUN_MYPY = "NPY_RUN_MYPY_IN_TESTSUITE" in os.environ\nif RUN_MYPY and RUN_MYPY not in ('0', '', 'false'):\n RUN_MYPY = True\n\n# Skips all functions in this file\npytestmark = pytest.mark.skipif(\n not RUN_MYPY,\n reason="`NPY_RUN_MYPY_IN_TESTSUITE` not set"\n)\n\n\ntry:\n from mypy import api\nexcept ImportError:\n NO_MYPY = True\nelse:\n NO_MYPY = False\n\nif TYPE_CHECKING:\n from collections.abc import Iterator\n\n # We need this as annotation, but it's located in a private namespace.\n # As a compromise, do *not* import it during runtime\n from _pytest.mark.structures import ParameterSet\n\nDATA_DIR = os.path.join(os.path.dirname(__file__), "data")\nPASS_DIR = os.path.join(DATA_DIR, "pass")\nFAIL_DIR = os.path.join(DATA_DIR, "fail")\nREVEAL_DIR = os.path.join(DATA_DIR, "reveal")\nMISC_DIR = os.path.join(DATA_DIR, "misc")\nMYPY_INI = os.path.join(DATA_DIR, "mypy.ini")\nCACHE_DIR = os.path.join(DATA_DIR, ".mypy_cache")\n\n#: A dictionary with file names as keys and lists of the mypy stdout as values.\n#: To-be populated by `run_mypy`.\nOUTPUT_MYPY: defaultdict[str, list[str]] = defaultdict(list)\n\n\ndef _key_func(key: str) -> str:\n """Split at the first occurrence of the ``:`` character.\n\n Windows drive-letters (*e.g.* ``C:``) are ignored herein.\n """\n drive, tail = os.path.splitdrive(key)\n return os.path.join(drive, tail.split(":", 1)[0])\n\n\ndef _strip_filename(msg: str) -> tuple[int, str]:\n """Strip the filename and line number from a mypy message."""\n _, tail = os.path.splitdrive(msg)\n _, lineno, msg = tail.split(":", 2)\n return int(lineno), msg.strip()\n\n\ndef strip_func(match: re.Match[str]) -> str:\n """`re.sub` helper function for stripping module names."""\n return match.groups()[1]\n\n\n@pytest.fixture(scope="module", autouse=True)\ndef run_mypy() -> None:\n """Clears the cache and run mypy before running any of the typing tests.\n\n The mypy results are cached in `OUTPUT_MYPY` for further use.\n\n The cache refresh can be skipped using\n\n NUMPY_TYPING_TEST_CLEAR_CACHE=0 pytest numpy/typing/tests\n """\n if (\n os.path.isdir(CACHE_DIR)\n and bool(os.environ.get("NUMPY_TYPING_TEST_CLEAR_CACHE", True)) # noqa: PLW1508\n ):\n shutil.rmtree(CACHE_DIR)\n\n split_pattern = re.compile(r"(\s+)?\^(\~+)?")\n for directory in (PASS_DIR, REVEAL_DIR, FAIL_DIR, MISC_DIR):\n # Run mypy\n stdout, stderr, exit_code = api.run([\n "--config-file",\n MYPY_INI,\n "--cache-dir",\n CACHE_DIR,\n directory,\n ])\n if stderr:\n pytest.fail(f"Unexpected mypy standard error\n\n{stderr}", False)\n elif exit_code not in {0, 1}:\n pytest.fail(f"Unexpected mypy exit code: {exit_code}\n\n{stdout}", False)\n\n str_concat = ""\n filename: str | None = None\n for i in stdout.split("\n"):\n if "note:" in i:\n continue\n if filename is None:\n filename = _key_func(i)\n\n str_concat += f"{i}\n"\n if split_pattern.match(i) is not None:\n OUTPUT_MYPY[filename].append(str_concat)\n str_concat = ""\n filename = None\n\n\ndef get_test_cases(*directories: str) -> "Iterator[ParameterSet]":\n for directory in directories:\n for root, _, files in os.walk(directory):\n for fname in files:\n short_fname, ext = os.path.splitext(fname)\n if ext not in (".pyi", ".py"):\n continue\n\n fullpath = os.path.join(root, fname)\n yield pytest.param(fullpath, id=short_fname)\n\n\n_FAIL_INDENT = " " * 4\n_FAIL_SEP = "\n" + "_" * 79 + "\n\n"\n\n_FAIL_MSG_REVEAL = """{}:{} - reveal mismatch:\n\n{}"""\n\n\n@pytest.mark.slow\n@pytest.mark.skipif(NO_MYPY, reason="Mypy is not installed")\n@pytest.mark.parametrize("path", get_test_cases(PASS_DIR, FAIL_DIR))\ndef test_pass(path) -> None:\n # Alias `OUTPUT_MYPY` so that it appears in the local namespace\n output_mypy = OUTPUT_MYPY\n\n if path not in output_mypy:\n return\n\n relpath = os.path.relpath(path)\n\n # collect any reported errors, and clean up the output\n messages = []\n for message in output_mypy[path]:\n lineno, content = _strip_filename(message)\n content = content.removeprefix("error:").lstrip()\n messages.append(f"{relpath}:{lineno} - {content}")\n\n if messages:\n pytest.fail("\n".join(messages), pytrace=False)\n\n\n@pytest.mark.slow\n@pytest.mark.skipif(NO_MYPY, reason="Mypy is not installed")\n@pytest.mark.parametrize("path", get_test_cases(REVEAL_DIR))\ndef test_reveal(path: str) -> None:\n """Validate that mypy correctly infers the return-types of\n the expressions in `path`.\n """\n __tracebackhide__ = True\n\n output_mypy = OUTPUT_MYPY\n if path not in output_mypy:\n return\n\n relpath = os.path.relpath(path)\n\n # collect any reported errors, and clean up the output\n failures = []\n for error_line in output_mypy[path]:\n lineno, error_msg = _strip_filename(error_line)\n error_msg = textwrap.indent(error_msg, _FAIL_INDENT)\n reason = _FAIL_MSG_REVEAL.format(relpath, lineno, error_msg)\n failures.append(reason)\n\n if failures:\n reasons = _FAIL_SEP.join(failures)\n pytest.fail(reasons, pytrace=False)\n\n\n@pytest.mark.slow\n@pytest.mark.skipif(NO_MYPY, reason="Mypy is not installed")\n@pytest.mark.parametrize("path", get_test_cases(PASS_DIR))\ndef test_code_runs(path: str) -> None:\n """Validate that the code in `path` properly during runtime."""\n path_without_extension, _ = os.path.splitext(path)\n dirname, filename = path.split(os.sep)[-2:]\n\n spec = importlib.util.spec_from_file_location(\n f"{dirname}.{filename}", path\n )\n assert spec is not None\n assert spec.loader is not None\n\n test_module = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(test_module)\n | .venv\Lib\site-packages\numpy\typing\tests\test_typing.py | test_typing.py | Python | 6,494 | 0.95 | 0.156098 | 0.075949 | python-kit | 634 | 2024-07-22T00:11:38.332660 | BSD-3-Clause | true | a24d1f3cfa590482cd0295149916cfb5 |
[mypy]\nenable_error_code = deprecated, ignore-without-code, truthy-bool\nstrict_bytes = True\nwarn_unused_ignores = True\nimplicit_reexport = False\ndisallow_any_unimported = True\ndisallow_any_generics = True\nshow_absolute_path = True\npretty = True\n | .venv\Lib\site-packages\numpy\typing\tests\data\mypy.ini | mypy.ini | Other | 254 | 0.85 | 0 | 0 | react-lib | 553 | 2023-12-28T21:18:27.475976 | BSD-3-Clause | true | be709efbed10dc11c4ce0d73dd2026ea |
from typing import Any\n\nimport numpy as np\nimport numpy.typing as npt\n\nb_ = np.bool()\ndt = np.datetime64(0, "D")\ntd = np.timedelta64(0, "D")\n\nAR_b: npt.NDArray[np.bool]\nAR_u: npt.NDArray[np.uint32]\nAR_i: npt.NDArray[np.int64]\nAR_f: npt.NDArray[np.longdouble]\nAR_c: npt.NDArray[np.complex128]\nAR_m: npt.NDArray[np.timedelta64]\nAR_M: npt.NDArray[np.datetime64]\n\nANY: Any\n\nAR_LIKE_b: list[bool]\nAR_LIKE_u: list[np.uint32]\nAR_LIKE_i: list[int]\nAR_LIKE_f: list[float]\nAR_LIKE_c: list[complex]\nAR_LIKE_m: list[np.timedelta64]\nAR_LIKE_M: list[np.datetime64]\n\n# Array subtraction\n\n# NOTE: mypys `NoReturn` errors are, unfortunately, not that great\n_1 = AR_b - AR_LIKE_b # type: ignore[var-annotated]\n_2 = AR_LIKE_b - AR_b # type: ignore[var-annotated]\nAR_i - bytes() # type: ignore[operator]\n\nAR_f - AR_LIKE_m # type: ignore[operator]\nAR_f - AR_LIKE_M # type: ignore[operator]\nAR_c - AR_LIKE_m # type: ignore[operator]\nAR_c - AR_LIKE_M # type: ignore[operator]\n\nAR_m - AR_LIKE_f # type: ignore[operator]\nAR_M - AR_LIKE_f # type: ignore[operator]\nAR_m - AR_LIKE_c # type: ignore[operator]\nAR_M - AR_LIKE_c # type: ignore[operator]\n\nAR_m - AR_LIKE_M # type: ignore[operator]\nAR_LIKE_m - AR_M # type: ignore[operator]\n\n# array floor division\n\nAR_M // AR_LIKE_b # type: ignore[operator]\nAR_M // AR_LIKE_u # type: ignore[operator]\nAR_M // AR_LIKE_i # type: ignore[operator]\nAR_M // AR_LIKE_f # type: ignore[operator]\nAR_M // AR_LIKE_c # type: ignore[operator]\nAR_M // AR_LIKE_m # type: ignore[operator]\nAR_M // AR_LIKE_M # type: ignore[operator]\n\nAR_b // AR_LIKE_M # type: ignore[operator]\nAR_u // AR_LIKE_M # type: ignore[operator]\nAR_i // AR_LIKE_M # type: ignore[operator]\nAR_f // AR_LIKE_M # type: ignore[operator]\nAR_c // AR_LIKE_M # type: ignore[operator]\nAR_m // AR_LIKE_M # type: ignore[operator]\nAR_M // AR_LIKE_M # type: ignore[operator]\n\n_3 = AR_m // AR_LIKE_b # type: ignore[var-annotated]\nAR_m // AR_LIKE_c # type: ignore[operator]\n\nAR_b // AR_LIKE_m # type: ignore[operator]\nAR_u // AR_LIKE_m # type: ignore[operator]\nAR_i // AR_LIKE_m # type: ignore[operator]\nAR_f // AR_LIKE_m # type: ignore[operator]\nAR_c // AR_LIKE_m # type: ignore[operator]\n\n# regression tests for https://github.com/numpy/numpy/issues/28957\nAR_c // 2 # type: ignore[operator]\nAR_c // AR_i # type: ignore[operator]\nAR_c // AR_c # type: ignore[operator]\n\n# Array multiplication\n\nAR_b *= AR_LIKE_u # type: ignore[arg-type]\nAR_b *= AR_LIKE_i # type: ignore[arg-type]\nAR_b *= AR_LIKE_f # type: ignore[arg-type]\nAR_b *= AR_LIKE_c # type: ignore[arg-type]\nAR_b *= AR_LIKE_m # type: ignore[arg-type]\n\nAR_u *= AR_LIKE_f # type: ignore[arg-type]\nAR_u *= AR_LIKE_c # type: ignore[arg-type]\nAR_u *= AR_LIKE_m # type: ignore[arg-type]\n\nAR_i *= AR_LIKE_f # type: ignore[arg-type]\nAR_i *= AR_LIKE_c # type: ignore[arg-type]\nAR_i *= AR_LIKE_m # type: ignore[arg-type]\n\nAR_f *= AR_LIKE_c # type: ignore[arg-type]\nAR_f *= AR_LIKE_m # type: ignore[arg-type]\n\n# Array power\n\nAR_b **= AR_LIKE_b # type: ignore[misc]\nAR_b **= AR_LIKE_u # type: ignore[misc]\nAR_b **= AR_LIKE_i # type: ignore[misc]\nAR_b **= AR_LIKE_f # type: ignore[misc]\nAR_b **= AR_LIKE_c # type: ignore[misc]\n\nAR_u **= AR_LIKE_f # type: ignore[arg-type]\nAR_u **= AR_LIKE_c # type: ignore[arg-type]\n\nAR_i **= AR_LIKE_f # type: ignore[arg-type]\nAR_i **= AR_LIKE_c # type: ignore[arg-type]\n\nAR_f **= AR_LIKE_c # type: ignore[arg-type]\n\n# Scalars\n\nb_ - b_ # type: ignore[call-overload]\n\ndt + dt # type: ignore[operator]\ntd - dt # type: ignore[operator]\ntd % 1 # type: ignore[operator]\ntd / dt # type: ignore[operator]\ntd % dt # type: ignore[operator]\n\n-b_ # type: ignore[operator]\n+b_ # type: ignore[operator]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\arithmetic.pyi | arithmetic.pyi | Other | 3,821 | 0.95 | 0.007937 | 0.072917 | react-lib | 854 | 2024-02-03T03:23:41.470995 | Apache-2.0 | true | 0eb29817f61c6ecbd3e556850c9bbda1 |
from collections.abc import Callable\nfrom typing import Any\n\nimport numpy as np\nimport numpy.typing as npt\n\nAR: npt.NDArray[np.float64]\nfunc1: Callable[[Any], str]\nfunc2: Callable[[np.integer], str]\n\nnp.array2string(AR, style=None) # type: ignore[call-overload]\nnp.array2string(AR, legacy="1.14") # type: ignore[call-overload]\nnp.array2string(AR, sign="*") # type: ignore[call-overload]\nnp.array2string(AR, floatmode="default") # type: ignore[call-overload]\nnp.array2string(AR, formatter={"A": func1}) # type: ignore[call-overload]\nnp.array2string(AR, formatter={"float": func2}) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\arrayprint.pyi | arrayprint.pyi | Other | 632 | 0.95 | 0 | 0 | react-lib | 991 | 2024-12-31T22:52:58.760305 | GPL-3.0 | true | e87ac459d2eef9fa8b26ae48db1a9556 |
import numpy as np\nimport numpy.typing as npt\n\nAR_i8: npt.NDArray[np.int64]\nar_iter = np.lib.Arrayterator(AR_i8)\n\nnp.lib.Arrayterator(np.int64()) # type: ignore[arg-type]\nar_iter.shape = (10, 5) # type: ignore[misc]\nar_iter[None] # type: ignore[index]\nar_iter[None, 1] # type: ignore[index]\nar_iter[np.intp()] # type: ignore[index]\nar_iter[np.intp(), ...] # type: ignore[index]\nar_iter[AR_i8] # type: ignore[index]\nar_iter[AR_i8, :] # type: ignore[index]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\arrayterator.pyi | arrayterator.pyi | Other | 477 | 0.95 | 0 | 0 | python-kit | 225 | 2025-03-29T18:29:19.190811 | MIT | true | 720ceb7cb66e8712a366741f16b752de |
import numpy as np\nimport numpy.typing as npt\n\na: npt.NDArray[np.float64]\ngenerator = (i for i in range(10))\n\nnp.require(a, requirements=1) # type: ignore[call-overload]\nnp.require(a, requirements="TEST") # type: ignore[arg-type]\n\nnp.zeros("test") # type: ignore[arg-type]\nnp.zeros() # type: ignore[call-overload]\n\nnp.ones("test") # type: ignore[arg-type]\nnp.ones() # type: ignore[call-overload]\n\nnp.array(0, float, True) # type: ignore[call-overload]\n\nnp.linspace(None, 'bob') # type: ignore[call-overload]\nnp.linspace(0, 2, num=10.0) # type: ignore[call-overload]\nnp.linspace(0, 2, endpoint='True') # type: ignore[call-overload]\nnp.linspace(0, 2, retstep=b'False') # type: ignore[call-overload]\nnp.linspace(0, 2, dtype=0) # type: ignore[call-overload]\nnp.linspace(0, 2, axis=None) # type: ignore[call-overload]\n\nnp.logspace(None, 'bob') # type: ignore[call-overload]\nnp.logspace(0, 2, base=None) # type: ignore[call-overload]\n\nnp.geomspace(None, 'bob') # type: ignore[call-overload]\n\nnp.stack(generator) # type: ignore[call-overload]\nnp.hstack({1, 2}) # type: ignore[call-overload]\nnp.vstack(1) # type: ignore[call-overload]\n\nnp.array([1], like=1) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\array_constructors.pyi | array_constructors.pyi | Other | 1,234 | 0.95 | 0.029412 | 0 | vue-tools | 591 | 2023-11-09T07:44:10.807912 | BSD-3-Clause | true | fe38fa9da3afb17d5234f288b0978554 |
import numpy as np\nfrom numpy._typing import ArrayLike\n\nclass A: ...\n\nx1: ArrayLike = (i for i in range(10)) # type: ignore[assignment]\nx2: ArrayLike = A() # type: ignore[assignment]\nx3: ArrayLike = {1: "foo", 2: "bar"} # type: ignore[assignment]\n\nscalar = np.int64(1)\nscalar.__array__(dtype=np.float64) # type: ignore[call-overload]\narray = np.array([1])\narray.__array__(dtype=np.float64) # type: ignore[call-overload]\n\narray.setfield(np.eye(1), np.int32, (0, 1)) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\array_like.pyi | array_like.pyi | Other | 511 | 0.95 | 0.133333 | 0 | vue-tools | 83 | 2023-08-06T19:11:45.384858 | MIT | true | ff76821092d686ad21ac96ede005922b |
import numpy as np\nimport numpy.typing as npt\n\nAR_i8: npt.NDArray[np.int64]\n\nnp.pad(AR_i8, 2, mode="bob") # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\array_pad.pyi | array_pad.pyi | Other | 143 | 0.95 | 0 | 0 | awesome-app | 282 | 2024-01-23T14:19:16.369890 | GPL-3.0 | true | f2a45eb3119a25b15b0c8cccaa88423f |
import numpy as np\n\ni8 = np.int64()\ni4 = np.int32()\nu8 = np.uint64()\nb_ = np.bool()\ni = int()\n\nf8 = np.float64()\n\nb_ >> f8 # type: ignore[call-overload]\ni8 << f8 # type: ignore[call-overload]\ni | f8 # type: ignore[operator]\ni8 ^ f8 # type: ignore[call-overload]\nu8 & f8 # type: ignore[call-overload]\n~f8 # type: ignore[operator]\n# TODO: Certain mixes like i4 << u8 go to float and thus should fail\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\bitwise_ops.pyi | bitwise_ops.pyi | Other | 421 | 0.95 | 0 | 0.071429 | vue-tools | 712 | 2024-09-28T00:24:52.928237 | BSD-3-Clause | true | 33fd0d58a461c2f916bbe1e6030718a8 |
import numpy as np\nimport numpy.typing as npt\n\nAR_U: npt.NDArray[np.str_]\nAR_S: npt.NDArray[np.bytes_]\n\nnp.char.equal(AR_U, AR_S) # type: ignore[arg-type]\nnp.char.not_equal(AR_U, AR_S) # type: ignore[arg-type]\n\nnp.char.greater_equal(AR_U, AR_S) # type: ignore[arg-type]\nnp.char.less_equal(AR_U, AR_S) # type: ignore[arg-type]\nnp.char.greater(AR_U, AR_S) # type: ignore[arg-type]\nnp.char.less(AR_U, AR_S) # type: ignore[arg-type]\n\nnp.char.encode(AR_S) # type: ignore[arg-type]\nnp.char.decode(AR_U) # type: ignore[arg-type]\n\nnp.char.join(AR_U, b"_") # type: ignore[arg-type]\nnp.char.join(AR_S, "_") # type: ignore[arg-type]\n\nnp.char.ljust(AR_U, 5, fillchar=b"a") # type: ignore[arg-type]\nnp.char.ljust(AR_S, 5, fillchar="a") # type: ignore[arg-type]\nnp.char.rjust(AR_U, 5, fillchar=b"a") # type: ignore[arg-type]\nnp.char.rjust(AR_S, 5, fillchar="a") # type: ignore[arg-type]\n\nnp.char.lstrip(AR_U, chars=b"a") # type: ignore[arg-type]\nnp.char.lstrip(AR_S, chars="a") # type: ignore[arg-type]\nnp.char.strip(AR_U, chars=b"a") # type: ignore[arg-type]\nnp.char.strip(AR_S, chars="a") # type: ignore[arg-type]\nnp.char.rstrip(AR_U, chars=b"a") # type: ignore[arg-type]\nnp.char.rstrip(AR_S, chars="a") # type: ignore[arg-type]\n\nnp.char.partition(AR_U, b"a") # type: ignore[arg-type]\nnp.char.partition(AR_S, "a") # type: ignore[arg-type]\nnp.char.rpartition(AR_U, b"a") # type: ignore[arg-type]\nnp.char.rpartition(AR_S, "a") # type: ignore[arg-type]\n\nnp.char.replace(AR_U, b"_", b"-") # type: ignore[arg-type]\nnp.char.replace(AR_S, "_", "-") # type: ignore[arg-type]\n\nnp.char.split(AR_U, b"_") # type: ignore[arg-type]\nnp.char.split(AR_S, "_") # type: ignore[arg-type]\nnp.char.rsplit(AR_U, b"_") # type: ignore[arg-type]\nnp.char.rsplit(AR_S, "_") # type: ignore[arg-type]\n\nnp.char.count(AR_U, b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nnp.char.count(AR_S, "a", end=9) # type: ignore[arg-type]\n\nnp.char.endswith(AR_U, b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nnp.char.endswith(AR_S, "a", end=9) # type: ignore[arg-type]\nnp.char.startswith(AR_U, b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nnp.char.startswith(AR_S, "a", end=9) # type: ignore[arg-type]\n\nnp.char.find(AR_U, b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nnp.char.find(AR_S, "a", end=9) # type: ignore[arg-type]\nnp.char.rfind(AR_U, b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nnp.char.rfind(AR_S, "a", end=9) # type: ignore[arg-type]\n\nnp.char.index(AR_U, b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nnp.char.index(AR_S, "a", end=9) # type: ignore[arg-type]\nnp.char.rindex(AR_U, b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nnp.char.rindex(AR_S, "a", end=9) # type: ignore[arg-type]\n\nnp.char.isdecimal(AR_S) # type: ignore[arg-type]\nnp.char.isnumeric(AR_S) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\char.pyi | char.pyi | Other | 2,865 | 0.95 | 0 | 0 | python-kit | 266 | 2024-12-24T14:53:36.100286 | GPL-3.0 | true | 810224a447b21a2703cc133b992e289f |
from typing import Any\nimport numpy as np\n\nAR_U: np.char.chararray[tuple[Any, ...], np.dtype[np.str_]]\nAR_S: np.char.chararray[tuple[Any, ...], np.dtype[np.bytes_]]\n\nAR_S.encode() # type: ignore[misc]\nAR_U.decode() # type: ignore[misc]\n\nAR_U.join(b"_") # type: ignore[arg-type]\nAR_S.join("_") # type: ignore[arg-type]\n\nAR_U.ljust(5, fillchar=b"a") # type: ignore[arg-type]\nAR_S.ljust(5, fillchar="a") # type: ignore[arg-type]\nAR_U.rjust(5, fillchar=b"a") # type: ignore[arg-type]\nAR_S.rjust(5, fillchar="a") # type: ignore[arg-type]\n\nAR_U.lstrip(chars=b"a") # type: ignore[arg-type]\nAR_S.lstrip(chars="a") # type: ignore[arg-type]\nAR_U.strip(chars=b"a") # type: ignore[arg-type]\nAR_S.strip(chars="a") # type: ignore[arg-type]\nAR_U.rstrip(chars=b"a") # type: ignore[arg-type]\nAR_S.rstrip(chars="a") # type: ignore[arg-type]\n\nAR_U.partition(b"a") # type: ignore[arg-type]\nAR_S.partition("a") # type: ignore[arg-type]\nAR_U.rpartition(b"a") # type: ignore[arg-type]\nAR_S.rpartition("a") # type: ignore[arg-type]\n\nAR_U.replace(b"_", b"-") # type: ignore[arg-type]\nAR_S.replace("_", "-") # type: ignore[arg-type]\n\nAR_U.split(b"_") # type: ignore[arg-type]\nAR_S.split("_") # type: ignore[arg-type]\nAR_S.split(1) # type: ignore[arg-type]\nAR_U.rsplit(b"_") # type: ignore[arg-type]\nAR_S.rsplit("_") # type: ignore[arg-type]\n\nAR_U.count(b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nAR_S.count("a", end=9) # type: ignore[arg-type]\n\nAR_U.endswith(b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nAR_S.endswith("a", end=9) # type: ignore[arg-type]\nAR_U.startswith(b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nAR_S.startswith("a", end=9) # type: ignore[arg-type]\n\nAR_U.find(b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nAR_S.find("a", end=9) # type: ignore[arg-type]\nAR_U.rfind(b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nAR_S.rfind("a", end=9) # type: ignore[arg-type]\n\nAR_U.index(b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nAR_S.index("a", end=9) # type: ignore[arg-type]\nAR_U.rindex(b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nAR_S.rindex("a", end=9) # type: ignore[arg-type]\n\nAR_U == AR_S # type: ignore[operator]\nAR_U != AR_S # type: ignore[operator]\nAR_U >= AR_S # type: ignore[operator]\nAR_U <= AR_S # type: ignore[operator]\nAR_U > AR_S # type: ignore[operator]\nAR_U < AR_S # type: ignore[operator]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\chararray.pyi | chararray.pyi | Other | 2,418 | 0.95 | 0 | 0 | awesome-app | 888 | 2025-05-23T10:12:19.422826 | GPL-3.0 | true | 7fd53aaf6aa76ef5b6b148ef0a5d69c1 |
import numpy as np\nimport numpy.typing as npt\n\nAR_i: npt.NDArray[np.int64]\nAR_f: npt.NDArray[np.float64]\nAR_c: npt.NDArray[np.complex128]\nAR_m: npt.NDArray[np.timedelta64]\nAR_M: npt.NDArray[np.datetime64]\n\nAR_f > AR_m # type: ignore[operator]\nAR_c > AR_m # type: ignore[operator]\n\nAR_m > AR_f # type: ignore[operator]\nAR_m > AR_c # type: ignore[operator]\n\nAR_i > AR_M # type: ignore[operator]\nAR_f > AR_M # type: ignore[operator]\nAR_m > AR_M # type: ignore[operator]\n\nAR_M > AR_i # type: ignore[operator]\nAR_M > AR_f # type: ignore[operator]\nAR_M > AR_m # type: ignore[operator]\n\nAR_i > str() # type: ignore[operator]\nAR_i > bytes() # type: ignore[operator]\nstr() > AR_M # type: ignore[operator]\nbytes() > AR_M # type: ignore[operator]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\comparisons.pyi | comparisons.pyi | Other | 777 | 0.95 | 0 | 0 | node-utils | 131 | 2025-03-22T05:37:36.584121 | BSD-3-Clause | true | 718a1ebdddeff7e3ac7f6358d0049b58 |
import numpy as np\n\nnp.little_endian = np.little_endian # type: ignore[misc]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\constants.pyi | constants.pyi | Other | 81 | 0.75 | 0 | 0 | awesome-app | 846 | 2024-01-28T00:41:57.771560 | MIT | true | 0c1728236c8a932ccd80fc22346463bb |
from pathlib import Path\nimport numpy as np\n\npath: Path\nd1: np.lib.npyio.DataSource\n\nd1.abspath(path) # type: ignore[arg-type]\nd1.abspath(b"...") # type: ignore[arg-type]\n\nd1.exists(path) # type: ignore[arg-type]\nd1.exists(b"...") # type: ignore[arg-type]\n\nd1.open(path, "r") # type: ignore[arg-type]\nd1.open(b"...", encoding="utf8") # type: ignore[arg-type]\nd1.open(None, newline="/n") # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\datasource.pyi | datasource.pyi | Other | 434 | 0.95 | 0 | 0 | node-utils | 302 | 2025-02-15T23:34:55.184586 | Apache-2.0 | true | 84985575163b403087208519326c0ba3 |
import numpy as np\n\nclass Test1:\n not_dtype = np.dtype(float)\n\nclass Test2:\n dtype = float\n\nnp.dtype(Test1()) # type: ignore[call-overload]\nnp.dtype(Test2()) # type: ignore[arg-type]\n\nnp.dtype( # type: ignore[call-overload]\n {\n "field1": (float, 1),\n "field2": (int, 3),\n }\n)\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\dtype.pyi | dtype.pyi | Other | 322 | 0.95 | 0.117647 | 0 | node-utils | 862 | 2025-02-22T19:38:00.480903 | Apache-2.0 | true | fc9b18eb296f3237c694462e1972713c |
import numpy as np\nimport numpy.typing as npt\n\nAR_i: npt.NDArray[np.int64]\nAR_f: npt.NDArray[np.float64]\nAR_m: npt.NDArray[np.timedelta64]\nAR_U: npt.NDArray[np.str_]\n\nnp.einsum("i,i->i", AR_i, AR_m) # type: ignore[arg-type]\nnp.einsum("i,i->i", AR_f, AR_f, dtype=np.int32) # type: ignore[arg-type]\nnp.einsum("i,i->i", AR_i, AR_i, out=AR_U) # type: ignore[type-var]\nnp.einsum("i,i->i", AR_i, AR_i, out=AR_U, casting="unsafe") # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\einsumfunc.pyi | einsumfunc.pyi | Other | 470 | 0.95 | 0 | 0 | node-utils | 195 | 2024-03-23T12:38:17.784235 | BSD-3-Clause | true | 0e29587bf32bc3bcbf618f624e0096d4 |
import numpy as np\nimport numpy._typing as npt\n\nclass Index:\n def __index__(self) -> int: ...\n\na: np.flatiter[npt.NDArray[np.float64]]\nsupports_array: npt._SupportsArray[np.dtype[np.float64]]\n\na.base = object() # type: ignore[assignment, misc]\na.coords = object() # type: ignore[assignment, misc]\na.index = object() # type: ignore[assignment, misc]\na.copy(order='C') # type: ignore[call-arg]\n\n# NOTE: Contrary to `ndarray.__getitem__` its counterpart in `flatiter`\n# does not accept objects with the `__array__` or `__index__` protocols;\n# boolean indexing is just plain broken (gh-17175)\na[np.bool()] # type: ignore[index]\na[Index()] # type: ignore[call-overload]\na[supports_array] # type: ignore[index]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\flatiter.pyi | flatiter.pyi | Other | 735 | 0.95 | 0.1 | 0.1875 | vue-tools | 211 | 2023-10-27T22:47:47.422674 | MIT | true | a7a98ecfa8294bee4daf5ce1749e751a |
"""Tests for :mod:`numpy._core.fromnumeric`."""\n\nimport numpy as np\nimport numpy.typing as npt\n\nA = np.array(True, ndmin=2, dtype=bool)\nA.setflags(write=False)\nAR_U: npt.NDArray[np.str_]\nAR_M: npt.NDArray[np.datetime64]\nAR_f4: npt.NDArray[np.float32]\n\na = np.bool(True)\n\nnp.take(a, None) # type: ignore[call-overload]\nnp.take(a, axis=1.0) # type: ignore[call-overload]\nnp.take(A, out=1) # type: ignore[call-overload]\nnp.take(A, mode="bob") # type: ignore[call-overload]\n\nnp.reshape(a, None) # type: ignore[call-overload]\nnp.reshape(A, 1, order="bob") # type: ignore[call-overload]\n\nnp.choose(a, None) # type: ignore[call-overload]\nnp.choose(a, out=1.0) # type: ignore[call-overload]\nnp.choose(A, mode="bob") # type: ignore[call-overload]\n\nnp.repeat(a, None) # type: ignore[call-overload]\nnp.repeat(A, 1, axis=1.0) # type: ignore[call-overload]\n\nnp.swapaxes(A, None, 1) # type: ignore[call-overload]\nnp.swapaxes(A, 1, [0]) # type: ignore[call-overload]\n\nnp.transpose(A, axes=1.0) # type: ignore[call-overload]\n\nnp.partition(a, None) # type: ignore[call-overload]\nnp.partition(a, 0, axis="bob") # type: ignore[call-overload]\nnp.partition(A, 0, kind="bob") # type: ignore[call-overload]\nnp.partition(A, 0, order=range(5)) # type: ignore[arg-type]\n\nnp.argpartition(a, None) # type: ignore[arg-type]\nnp.argpartition(a, 0, axis="bob") # type: ignore[arg-type]\nnp.argpartition(A, 0, kind="bob") # type: ignore[arg-type]\nnp.argpartition(A, 0, order=range(5)) # type: ignore[arg-type]\n\nnp.sort(A, axis="bob") # type: ignore[call-overload]\nnp.sort(A, kind="bob") # type: ignore[call-overload]\nnp.sort(A, order=range(5)) # type: ignore[arg-type]\n\nnp.argsort(A, axis="bob") # type: ignore[arg-type]\nnp.argsort(A, kind="bob") # type: ignore[arg-type]\nnp.argsort(A, order=range(5)) # type: ignore[arg-type]\n\nnp.argmax(A, axis="bob") # type: ignore[call-overload]\nnp.argmax(A, kind="bob") # type: ignore[call-overload]\nnp.argmax(A, out=AR_f4) # type: ignore[type-var]\n\nnp.argmin(A, axis="bob") # type: ignore[call-overload]\nnp.argmin(A, kind="bob") # type: ignore[call-overload]\nnp.argmin(A, out=AR_f4) # type: ignore[type-var]\n\nnp.searchsorted(A[0], 0, side="bob") # type: ignore[call-overload]\nnp.searchsorted(A[0], 0, sorter=1.0) # type: ignore[call-overload]\n\nnp.resize(A, 1.0) # type: ignore[call-overload]\n\nnp.squeeze(A, 1.0) # type: ignore[call-overload]\n\nnp.diagonal(A, offset=None) # type: ignore[call-overload]\nnp.diagonal(A, axis1="bob") # type: ignore[call-overload]\nnp.diagonal(A, axis2=[]) # type: ignore[call-overload]\n\nnp.trace(A, offset=None) # type: ignore[call-overload]\nnp.trace(A, axis1="bob") # type: ignore[call-overload]\nnp.trace(A, axis2=[]) # type: ignore[call-overload]\n\nnp.ravel(a, order="bob") # type: ignore[call-overload]\n\nnp.nonzero(0) # type: ignore[arg-type]\n\nnp.compress([True], A, axis=1.0) # type: ignore[call-overload]\n\nnp.clip(a, 1, 2, out=1) # type: ignore[call-overload]\n\nnp.sum(a, axis=1.0) # type: ignore[call-overload]\nnp.sum(a, keepdims=1.0) # type: ignore[call-overload]\nnp.sum(a, initial=[1]) # type: ignore[call-overload]\n\nnp.all(a, axis=1.0) # type: ignore[call-overload]\nnp.all(a, keepdims=1.0) # type: ignore[call-overload]\nnp.all(a, out=1.0) # type: ignore[call-overload]\n\nnp.any(a, axis=1.0) # type: ignore[call-overload]\nnp.any(a, keepdims=1.0) # type: ignore[call-overload]\nnp.any(a, out=1.0) # type: ignore[call-overload]\n\nnp.cumsum(a, axis=1.0) # type: ignore[call-overload]\nnp.cumsum(a, dtype=1.0) # type: ignore[call-overload]\nnp.cumsum(a, out=1.0) # type: ignore[call-overload]\n\nnp.ptp(a, axis=1.0) # type: ignore[call-overload]\nnp.ptp(a, keepdims=1.0) # type: ignore[call-overload]\nnp.ptp(a, out=1.0) # type: ignore[call-overload]\n\nnp.amax(a, axis=1.0) # type: ignore[call-overload]\nnp.amax(a, keepdims=1.0) # type: ignore[call-overload]\nnp.amax(a, out=1.0) # type: ignore[call-overload]\nnp.amax(a, initial=[1.0]) # type: ignore[call-overload]\nnp.amax(a, where=[1.0]) # type: ignore[arg-type]\n\nnp.amin(a, axis=1.0) # type: ignore[call-overload]\nnp.amin(a, keepdims=1.0) # type: ignore[call-overload]\nnp.amin(a, out=1.0) # type: ignore[call-overload]\nnp.amin(a, initial=[1.0]) # type: ignore[call-overload]\nnp.amin(a, where=[1.0]) # type: ignore[arg-type]\n\nnp.prod(a, axis=1.0) # type: ignore[call-overload]\nnp.prod(a, out=False) # type: ignore[call-overload]\nnp.prod(a, keepdims=1.0) # type: ignore[call-overload]\nnp.prod(a, initial=int) # type: ignore[call-overload]\nnp.prod(a, where=1.0) # type: ignore[call-overload]\nnp.prod(AR_U) # type: ignore[arg-type]\n\nnp.cumprod(a, axis=1.0) # type: ignore[call-overload]\nnp.cumprod(a, out=False) # type: ignore[call-overload]\nnp.cumprod(AR_U) # type: ignore[arg-type]\n\nnp.size(a, axis=1.0) # type: ignore[arg-type]\n\nnp.around(a, decimals=1.0) # type: ignore[call-overload]\nnp.around(a, out=type) # type: ignore[call-overload]\nnp.around(AR_U) # type: ignore[arg-type]\n\nnp.mean(a, axis=1.0) # type: ignore[call-overload]\nnp.mean(a, out=False) # type: ignore[call-overload]\nnp.mean(a, keepdims=1.0) # type: ignore[call-overload]\nnp.mean(AR_U) # type: ignore[arg-type]\nnp.mean(AR_M) # type: ignore[arg-type]\n\nnp.std(a, axis=1.0) # type: ignore[call-overload]\nnp.std(a, out=False) # type: ignore[call-overload]\nnp.std(a, ddof='test') # type: ignore[call-overload]\nnp.std(a, keepdims=1.0) # type: ignore[call-overload]\nnp.std(AR_U) # type: ignore[arg-type]\n\nnp.var(a, axis=1.0) # type: ignore[call-overload]\nnp.var(a, out=False) # type: ignore[call-overload]\nnp.var(a, ddof='test') # type: ignore[call-overload]\nnp.var(a, keepdims=1.0) # type: ignore[call-overload]\nnp.var(AR_U) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\fromnumeric.pyi | fromnumeric.pyi | Other | 5,833 | 0.95 | 0.006757 | 0 | vue-tools | 678 | 2024-01-11T19:03:08.852018 | Apache-2.0 | true | bfe07743898c42ffb8a7ef49059bffcf |
import numpy as np\nimport numpy.typing as npt\n\nAR_i8: npt.NDArray[np.int64]\nAR_f8: npt.NDArray[np.float64]\n\nnp.histogram_bin_edges(AR_i8, range=(0, 1, 2)) # type: ignore[arg-type]\n\nnp.histogram(AR_i8, range=(0, 1, 2)) # type: ignore[arg-type]\n\nnp.histogramdd(AR_i8, range=(0, 1)) # type: ignore[arg-type]\nnp.histogramdd(AR_i8, range=[(0, 1, 2)]) # type: ignore[list-item]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\histograms.pyi | histograms.pyi | Other | 388 | 0.95 | 0 | 0 | awesome-app | 903 | 2025-01-22T10:58:58.839105 | Apache-2.0 | true | 83470ab86859362a2928a39cbd32d20a |
import numpy as np\n\nAR_LIKE_i: list[int]\nAR_LIKE_f: list[float]\n\nnp.ndindex([1, 2, 3]) # type: ignore[call-overload]\nnp.unravel_index(AR_LIKE_f, (1, 2, 3)) # type: ignore[arg-type]\nnp.ravel_multi_index(AR_LIKE_i, (1, 2, 3), mode="bob") # type: ignore[call-overload]\nnp.mgrid[1] # type: ignore[index]\nnp.mgrid[...] # type: ignore[index]\nnp.ogrid[1] # type: ignore[index]\nnp.ogrid[...] # type: ignore[index]\nnp.fill_diagonal(AR_LIKE_f, 2) # type: ignore[arg-type]\nnp.diag_indices(1.0) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\index_tricks.pyi | index_tricks.pyi | Other | 531 | 0.95 | 0 | 0 | node-utils | 638 | 2024-04-07T21:08:51.365975 | Apache-2.0 | true | ca778147b0814b86b9b03c8b88a30590 |
from typing import Any\n\nimport numpy as np\nimport numpy.typing as npt\n\nAR_f8: npt.NDArray[np.float64]\nAR_c16: npt.NDArray[np.complex128]\nAR_m: npt.NDArray[np.timedelta64]\nAR_M: npt.NDArray[np.datetime64]\nAR_O: npt.NDArray[np.object_]\nAR_b_list: list[npt.NDArray[np.bool]]\n\ndef fn_none_i(a: None, /) -> npt.NDArray[Any]: ...\ndef fn_ar_i(a: npt.NDArray[np.float64], posarg: int, /) -> npt.NDArray[Any]: ...\n\nnp.average(AR_m) # type: ignore[arg-type]\nnp.select(1, [AR_f8]) # type: ignore[arg-type]\nnp.angle(AR_m) # type: ignore[arg-type]\nnp.unwrap(AR_m) # type: ignore[arg-type]\nnp.unwrap(AR_c16) # type: ignore[arg-type]\nnp.trim_zeros(1) # type: ignore[arg-type]\nnp.place(1, [True], 1.5) # type: ignore[arg-type]\nnp.vectorize(1) # type: ignore[arg-type]\nnp.place(AR_f8, slice(None), 5) # type: ignore[arg-type]\n\nnp.piecewise(AR_f8, True, [fn_ar_i], 42) # type: ignore[call-overload]\n# TODO: enable these once mypy actually supports ParamSpec (released in 2021)\n# NOTE: pyright correctly reports errors for these (`reportCallIssue`)\n# np.piecewise(AR_f8, AR_b_list, [fn_none_i]) # type: ignore[call-overload]s\n# np.piecewise(AR_f8, AR_b_list, [fn_ar_i]) # type: ignore[call-overload]\n# np.piecewise(AR_f8, AR_b_list, [fn_ar_i], 3.14) # type: ignore[call-overload]\n# np.piecewise(AR_f8, AR_b_list, [fn_ar_i], 42, None) # type: ignore[call-overload]\n# np.piecewise(AR_f8, AR_b_list, [fn_ar_i], 42, _=None) # type: ignore[call-overload]\n\nnp.interp(AR_f8, AR_c16, AR_f8) # type: ignore[arg-type]\nnp.interp(AR_c16, AR_f8, AR_f8) # type: ignore[arg-type]\nnp.interp(AR_f8, AR_f8, AR_f8, period=AR_c16) # type: ignore[call-overload]\nnp.interp(AR_f8, AR_f8, AR_O) # type: ignore[arg-type]\n\nnp.cov(AR_m) # type: ignore[arg-type]\nnp.cov(AR_O) # type: ignore[arg-type]\nnp.corrcoef(AR_m) # type: ignore[arg-type]\nnp.corrcoef(AR_O) # type: ignore[arg-type]\nnp.corrcoef(AR_f8, bias=True) # type: ignore[call-overload]\nnp.corrcoef(AR_f8, ddof=2) # type: ignore[call-overload]\nnp.blackman(1j) # type: ignore[arg-type]\nnp.bartlett(1j) # type: ignore[arg-type]\nnp.hanning(1j) # type: ignore[arg-type]\nnp.hamming(1j) # type: ignore[arg-type]\nnp.hamming(AR_c16) # type: ignore[arg-type]\nnp.kaiser(1j, 1) # type: ignore[arg-type]\nnp.sinc(AR_O) # type: ignore[arg-type]\nnp.median(AR_M) # type: ignore[arg-type]\n\nnp.percentile(AR_f8, 50j) # type: ignore[call-overload]\nnp.percentile(AR_f8, 50, interpolation="bob") # type: ignore[call-overload]\nnp.quantile(AR_f8, 0.5j) # type: ignore[call-overload]\nnp.quantile(AR_f8, 0.5, interpolation="bob") # type: ignore[call-overload]\nnp.meshgrid(AR_f8, AR_f8, indexing="bob") # type: ignore[call-overload]\nnp.delete(AR_f8, AR_f8) # type: ignore[arg-type]\nnp.insert(AR_f8, AR_f8, 1.5) # type: ignore[arg-type]\nnp.digitize(AR_f8, 1j) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\lib_function_base.pyi | lib_function_base.pyi | Other | 2,879 | 0.95 | 0.048387 | 0.12963 | awesome-app | 530 | 2025-04-17T13:04:55.872711 | BSD-3-Clause | true | 65c330398ae80c55853163fd94cfae0a |
import numpy as np\nimport numpy.typing as npt\n\nAR_f8: npt.NDArray[np.float64]\nAR_c16: npt.NDArray[np.complex128]\nAR_O: npt.NDArray[np.object_]\nAR_U: npt.NDArray[np.str_]\n\npoly_obj: np.poly1d\n\nnp.polymul(AR_f8, AR_U) # type: ignore[arg-type]\nnp.polydiv(AR_f8, AR_U) # type: ignore[arg-type]\n\n5**poly_obj # type: ignore[operator]\n\nnp.polyint(AR_U) # type: ignore[arg-type]\nnp.polyint(AR_f8, m=1j) # type: ignore[call-overload]\n\nnp.polyder(AR_U) # type: ignore[arg-type]\nnp.polyder(AR_f8, m=1j) # type: ignore[call-overload]\n\nnp.polyfit(AR_O, AR_f8, 1) # type: ignore[arg-type]\nnp.polyfit(AR_f8, AR_f8, 1, rcond=1j) # type: ignore[call-overload]\nnp.polyfit(AR_f8, AR_f8, 1, w=AR_c16) # type: ignore[arg-type]\nnp.polyfit(AR_f8, AR_f8, 1, cov="bob") # type: ignore[call-overload]\n\nnp.polyval(AR_f8, AR_U) # type: ignore[arg-type]\nnp.polyadd(AR_f8, AR_U) # type: ignore[arg-type]\nnp.polysub(AR_f8, AR_U) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\lib_polynomial.pyi | lib_polynomial.pyi | Other | 966 | 0.95 | 0 | 0 | react-lib | 245 | 2024-07-04T12:24:30.564358 | BSD-3-Clause | true | 768d54b2dfef8cf18eca6d35573fab76 |
import numpy.lib.array_utils as array_utils\n\narray_utils.byte_bounds(1) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\lib_utils.pyi | lib_utils.pyi | Other | 101 | 0.75 | 0 | 0 | react-lib | 427 | 2025-06-15T18:28:12.045031 | BSD-3-Clause | true | 6d6aaba091e8dfc518d6eb09942c266a |
from numpy.lib import NumpyVersion\n\nversion: NumpyVersion\n\nNumpyVersion(b"1.8.0") # type: ignore[arg-type]\nversion >= b"1.8.0" # type: ignore[operator]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\lib_version.pyi | lib_version.pyi | Other | 160 | 0.95 | 0 | 0 | node-utils | 511 | 2025-06-28T20:28:52.853233 | BSD-3-Clause | true | b7c8f99e15c7342e13b79f714d232b51 |
import numpy as np\nimport numpy.typing as npt\n\nAR_f8: npt.NDArray[np.float64]\nAR_O: npt.NDArray[np.object_]\nAR_M: npt.NDArray[np.datetime64]\n\nnp.linalg.tensorsolve(AR_O, AR_O) # type: ignore[arg-type]\n\nnp.linalg.solve(AR_O, AR_O) # type: ignore[arg-type]\n\nnp.linalg.tensorinv(AR_O) # type: ignore[arg-type]\n\nnp.linalg.inv(AR_O) # type: ignore[arg-type]\n\nnp.linalg.matrix_power(AR_M, 5) # type: ignore[arg-type]\n\nnp.linalg.cholesky(AR_O) # type: ignore[arg-type]\n\nnp.linalg.qr(AR_O) # type: ignore[arg-type]\nnp.linalg.qr(AR_f8, mode="bob") # type: ignore[call-overload]\n\nnp.linalg.eigvals(AR_O) # type: ignore[arg-type]\n\nnp.linalg.eigvalsh(AR_O) # type: ignore[arg-type]\nnp.linalg.eigvalsh(AR_O, UPLO="bob") # type: ignore[call-overload]\n\nnp.linalg.eig(AR_O) # type: ignore[arg-type]\n\nnp.linalg.eigh(AR_O) # type: ignore[arg-type]\nnp.linalg.eigh(AR_O, UPLO="bob") # type: ignore[call-overload]\n\nnp.linalg.svd(AR_O) # type: ignore[arg-type]\n\nnp.linalg.cond(AR_O) # type: ignore[arg-type]\nnp.linalg.cond(AR_f8, p="bob") # type: ignore[arg-type]\n\nnp.linalg.matrix_rank(AR_O) # type: ignore[arg-type]\n\nnp.linalg.pinv(AR_O) # type: ignore[arg-type]\n\nnp.linalg.slogdet(AR_O) # type: ignore[arg-type]\n\nnp.linalg.det(AR_O) # type: ignore[arg-type]\n\nnp.linalg.norm(AR_f8, ord="bob") # type: ignore[call-overload]\n\nnp.linalg.multi_dot([AR_M]) # type: ignore[list-item]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\linalg.pyi | linalg.pyi | Other | 1,429 | 0.95 | 0 | 0 | vue-tools | 281 | 2024-05-27T11:35:22.911213 | Apache-2.0 | true | ca228239494061c389a8536dff6be96f |
from typing import TypeAlias, TypeVar\n\nimport numpy as np\nimport numpy.typing as npt\nfrom numpy._typing import _Shape\n\n_ScalarT = TypeVar("_ScalarT", bound=np.generic)\nMaskedArray: TypeAlias = np.ma.MaskedArray[_Shape, np.dtype[_ScalarT]]\n\nMAR_1d_f8: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]]\nMAR_b: MaskedArray[np.bool]\nMAR_c: MaskedArray[np.complex128]\nMAR_td64: MaskedArray[np.timedelta64]\n\nAR_b: npt.NDArray[np.bool]\n\nMAR_1d_f8.shape = (3, 1) # type: ignore[assignment]\nMAR_1d_f8.dtype = np.bool # type: ignore[assignment]\n\nnp.ma.min(MAR_1d_f8, axis=1.0) # type: ignore[call-overload]\nnp.ma.min(MAR_1d_f8, keepdims=1.0) # type: ignore[call-overload]\nnp.ma.min(MAR_1d_f8, out=1.0) # type: ignore[call-overload]\nnp.ma.min(MAR_1d_f8, fill_value=lambda x: 27) # type: ignore[call-overload]\n\nMAR_1d_f8.min(axis=1.0) # type: ignore[call-overload]\nMAR_1d_f8.min(keepdims=1.0) # type: ignore[call-overload]\nMAR_1d_f8.min(out=1.0) # type: ignore[call-overload]\nMAR_1d_f8.min(fill_value=lambda x: 27) # type: ignore[call-overload]\n\nnp.ma.max(MAR_1d_f8, axis=1.0) # type: ignore[call-overload]\nnp.ma.max(MAR_1d_f8, keepdims=1.0) # type: ignore[call-overload]\nnp.ma.max(MAR_1d_f8, out=1.0) # type: ignore[call-overload]\nnp.ma.max(MAR_1d_f8, fill_value=lambda x: 27) # type: ignore[call-overload]\n\nMAR_1d_f8.max(axis=1.0) # type: ignore[call-overload]\nMAR_1d_f8.max(keepdims=1.0) # type: ignore[call-overload]\nMAR_1d_f8.max(out=1.0) # type: ignore[call-overload]\nMAR_1d_f8.max(fill_value=lambda x: 27) # type: ignore[call-overload]\n\nnp.ma.ptp(MAR_1d_f8, axis=1.0) # type: ignore[call-overload]\nnp.ma.ptp(MAR_1d_f8, keepdims=1.0) # type: ignore[call-overload]\nnp.ma.ptp(MAR_1d_f8, out=1.0) # type: ignore[call-overload]\nnp.ma.ptp(MAR_1d_f8, fill_value=lambda x: 27) # type: ignore[call-overload]\n\nMAR_1d_f8.ptp(axis=1.0) # type: ignore[call-overload]\nMAR_1d_f8.ptp(keepdims=1.0) # type: ignore[call-overload]\nMAR_1d_f8.ptp(out=1.0) # type: ignore[call-overload]\nMAR_1d_f8.ptp(fill_value=lambda x: 27) # type: ignore[call-overload]\n\nMAR_1d_f8.argmin(axis=1.0) # type: ignore[call-overload]\nMAR_1d_f8.argmin(keepdims=1.0) # type: ignore[call-overload]\nMAR_1d_f8.argmin(out=1.0) # type: ignore[call-overload]\nMAR_1d_f8.argmin(fill_value=lambda x: 27) # type: ignore[call-overload]\n\nnp.ma.argmin(MAR_1d_f8, axis=1.0) # type: ignore[call-overload]\nnp.ma.argmin(MAR_1d_f8, axis=(1,)) # type: ignore[call-overload]\nnp.ma.argmin(MAR_1d_f8, keepdims=1.0) # type: ignore[call-overload]\nnp.ma.argmin(MAR_1d_f8, out=1.0) # type: ignore[call-overload]\nnp.ma.argmin(MAR_1d_f8, fill_value=lambda x: 27) # type: ignore[call-overload]\n\nMAR_1d_f8.argmax(axis=1.0) # type: ignore[call-overload]\nMAR_1d_f8.argmax(keepdims=1.0) # type: ignore[call-overload]\nMAR_1d_f8.argmax(out=1.0) # type: ignore[call-overload]\nMAR_1d_f8.argmax(fill_value=lambda x: 27) # type: ignore[call-overload]\n\nnp.ma.argmax(MAR_1d_f8, axis=1.0) # type: ignore[call-overload]\nnp.ma.argmax(MAR_1d_f8, axis=(0,)) # type: ignore[call-overload]\nnp.ma.argmax(MAR_1d_f8, keepdims=1.0) # type: ignore[call-overload]\nnp.ma.argmax(MAR_1d_f8, out=1.0) # type: ignore[call-overload]\nnp.ma.argmax(MAR_1d_f8, fill_value=lambda x: 27) # type: ignore[call-overload]\n\nMAR_1d_f8.all(axis=1.0) # type: ignore[call-overload]\nMAR_1d_f8.all(keepdims=1.0) # type: ignore[call-overload]\nMAR_1d_f8.all(out=1.0) # type: ignore[call-overload]\n\nMAR_1d_f8.any(axis=1.0) # type: ignore[call-overload]\nMAR_1d_f8.any(keepdims=1.0) # type: ignore[call-overload]\nMAR_1d_f8.any(out=1.0) # type: ignore[call-overload]\n\nMAR_1d_f8.sort(axis=(0,1)) # type: ignore[arg-type]\nMAR_1d_f8.sort(axis=None) # type: ignore[arg-type]\nMAR_1d_f8.sort(kind='cabbage') # type: ignore[arg-type]\nMAR_1d_f8.sort(order=lambda: 'cabbage') # type: ignore[arg-type]\nMAR_1d_f8.sort(endwith='cabbage') # type: ignore[arg-type]\nMAR_1d_f8.sort(fill_value=lambda: 'cabbage') # type: ignore[arg-type]\nMAR_1d_f8.sort(stable='cabbage') # type: ignore[arg-type]\nMAR_1d_f8.sort(stable=True) # type: ignore[arg-type]\n\nMAR_1d_f8.take(axis=1.0) # type: ignore[call-overload]\nMAR_1d_f8.take(out=1) # type: ignore[call-overload]\nMAR_1d_f8.take(mode="bob") # type: ignore[call-overload]\n\nnp.ma.take(None) # type: ignore[call-overload]\nnp.ma.take(axis=1.0) # type: ignore[call-overload]\nnp.ma.take(out=1) # type: ignore[call-overload]\nnp.ma.take(mode="bob") # type: ignore[call-overload]\n\nMAR_1d_f8.partition(['cabbage']) # type: ignore[arg-type]\nMAR_1d_f8.partition(axis=(0,1)) # type: ignore[arg-type, call-arg]\nMAR_1d_f8.partition(kind='cabbage') # type: ignore[arg-type, call-arg]\nMAR_1d_f8.partition(order=lambda: 'cabbage') # type: ignore[arg-type, call-arg]\nMAR_1d_f8.partition(AR_b) # type: ignore[arg-type]\n\nMAR_1d_f8.argpartition(['cabbage']) # type: ignore[arg-type]\nMAR_1d_f8.argpartition(axis=(0,1)) # type: ignore[arg-type, call-arg]\nMAR_1d_f8.argpartition(kind='cabbage') # type: ignore[arg-type, call-arg]\nMAR_1d_f8.argpartition(order=lambda: 'cabbage') # type: ignore[arg-type, call-arg]\nMAR_1d_f8.argpartition(AR_b) # type: ignore[arg-type]\n\nnp.ma.ndim(lambda: 'lambda') # type: ignore[arg-type]\n\nnp.ma.size(AR_b, axis='0') # type: ignore[arg-type]\n\nMAR_1d_f8 >= (lambda x: 'mango') # type: ignore[operator]\nMAR_1d_f8 > (lambda x: 'mango') # type: ignore[operator]\nMAR_1d_f8 <= (lambda x: 'mango') # type: ignore[operator]\nMAR_1d_f8 < (lambda x: 'mango') # type: ignore[operator]\n\nMAR_1d_f8.count(axis=0.) # type: ignore[call-overload]\n\nnp.ma.count(MAR_1d_f8, axis=0.) # type: ignore[call-overload]\n\nMAR_1d_f8.put(4, 999, mode='flip') # type: ignore[arg-type]\n\nnp.ma.put(MAR_1d_f8, 4, 999, mode='flip') # type: ignore[arg-type]\n\nnp.ma.put([1,1,3], 0, 999) # type: ignore[arg-type]\n\nnp.ma.compressed(lambda: 'compress me') # type: ignore[call-overload]\n\nnp.ma.allequal(MAR_1d_f8, [1,2,3], fill_value=1.5) # type: ignore[arg-type]\n\nnp.ma.allclose(MAR_1d_f8, [1,2,3], masked_equal=4.5) # type: ignore[arg-type]\nnp.ma.allclose(MAR_1d_f8, [1,2,3], rtol='.4') # type: ignore[arg-type]\nnp.ma.allclose(MAR_1d_f8, [1,2,3], atol='.5') # type: ignore[arg-type]\n\nMAR_1d_f8.__setmask__('mask') # type: ignore[arg-type]\n\nMAR_b *= 2 # type: ignore[arg-type]\nMAR_c //= 2 # type: ignore[misc]\nMAR_td64 **= 2 # type: ignore[misc]\n\nMAR_1d_f8.swapaxes(axis1=1, axis2=0) # type: ignore[call-arg]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\ma.pyi | ma.pyi | Other | 6,507 | 0.95 | 0 | 0 | awesome-app | 489 | 2024-06-21T08:20:41.009982 | BSD-3-Clause | true | db48c28d2f2bed4140ca0ca35e0201fc |
import numpy as np\n\nwith open("file.txt", "r") as f:\n np.memmap(f) # type: ignore[call-overload]\nnp.memmap("test.txt", shape=[10, 5]) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\memmap.pyi | memmap.pyi | Other | 174 | 0.95 | 0 | 0 | awesome-app | 752 | 2024-06-29T05:09:30.013001 | GPL-3.0 | true | b6356117800b3634653310323d48067c |
import numpy as np\n\nnp.testing.bob # type: ignore[attr-defined]\nnp.bob # type: ignore[attr-defined]\n\n# Stdlib modules in the namespace by accident\nnp.warnings # type: ignore[attr-defined]\nnp.sys # type: ignore[attr-defined]\nnp.os # type: ignore[attr-defined]\nnp.math # type: ignore[attr-defined]\n\n# Public sub-modules that are not imported to their parent module by default;\n# e.g. one must first execute `import numpy.lib.recfunctions`\nnp.lib.recfunctions # type: ignore[attr-defined]\n\nnp.__deprecated_attrs__ # type: ignore[attr-defined]\nnp.__expired_functions__ # type: ignore[attr-defined]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\modules.pyi | modules.pyi | Other | 620 | 0.95 | 0 | 0.230769 | node-utils | 905 | 2023-09-13T15:36:44.817295 | Apache-2.0 | true | 732a547e42500b0cadb9127a56375bf1 |
import numpy as np\nimport numpy.typing as npt\n\ni8: np.int64\n\nAR_b: npt.NDArray[np.bool]\nAR_u1: npt.NDArray[np.uint8]\nAR_i8: npt.NDArray[np.int64]\nAR_f8: npt.NDArray[np.float64]\nAR_M: npt.NDArray[np.datetime64]\n\nM: np.datetime64\n\nAR_LIKE_f: list[float]\n\ndef func(a: int) -> None: ...\n\nnp.where(AR_b, 1) # type: ignore[call-overload]\n\nnp.can_cast(AR_f8, 1) # type: ignore[arg-type]\n\nnp.vdot(AR_M, AR_M) # type: ignore[arg-type]\n\nnp.copyto(AR_LIKE_f, AR_f8) # type: ignore[arg-type]\n\nnp.putmask(AR_LIKE_f, [True, True, False], 1.5) # type: ignore[arg-type]\n\nnp.packbits(AR_f8) # type: ignore[arg-type]\nnp.packbits(AR_u1, bitorder=">") # type: ignore[arg-type]\n\nnp.unpackbits(AR_i8) # type: ignore[arg-type]\nnp.unpackbits(AR_u1, bitorder=">") # type: ignore[arg-type]\n\nnp.shares_memory(1, 1, max_work=i8) # type: ignore[arg-type]\nnp.may_share_memory(1, 1, max_work=i8) # type: ignore[arg-type]\n\nnp.arange(stop=10) # type: ignore[call-overload]\n\nnp.datetime_data(int) # type: ignore[arg-type]\n\nnp.busday_offset("2012", 10) # type: ignore[call-overload]\n\nnp.datetime_as_string("2012") # type: ignore[call-overload]\n\nnp.char.compare_chararrays("a", b"a", "==", False) # type: ignore[call-overload]\n\nnp.nested_iters([AR_i8, AR_i8]) # type: ignore[call-arg]\nnp.nested_iters([AR_i8, AR_i8], 0) # type: ignore[arg-type]\nnp.nested_iters([AR_i8, AR_i8], [0]) # type: ignore[list-item]\nnp.nested_iters([AR_i8, AR_i8], [[0], [1]], flags=["test"]) # type: ignore[list-item]\nnp.nested_iters([AR_i8, AR_i8], [[0], [1]], op_flags=[["test"]]) # type: ignore[list-item]\nnp.nested_iters([AR_i8, AR_i8], [[0], [1]], buffersize=1.0) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\multiarray.pyi | multiarray.pyi | Other | 1,708 | 0.95 | 0.019231 | 0 | node-utils | 245 | 2024-01-02T12:02:45.775045 | BSD-3-Clause | true | 867d20c8d1d7fc5dad343bc9578afcd7 |
import numpy as np\n\n# Ban setting dtype since mutating the type of the array in place\n# makes having ndarray be generic over dtype impossible. Generally\n# users should use `ndarray.view` in this situation anyway. See\n#\n# https://github.com/numpy/numpy-stubs/issues/7\n#\n# for more context.\nfloat_array = np.array([1.0])\nfloat_array.dtype = np.bool # type: ignore[assignment, misc]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\ndarray.pyi | ndarray.pyi | Other | 392 | 0.95 | 0.090909 | 0.7 | react-lib | 921 | 2024-10-20T12:46:30.305265 | Apache-2.0 | true | fd1aaaf433ac2e59dfabe9a0ec02f15f |
"""\nTests for miscellaneous (non-magic) ``np.ndarray``/``np.generic`` methods.\n\nMore extensive tests are performed for the methods'\nfunction-based counterpart in `../from_numeric.py`.\n\n"""\n\nimport numpy as np\nimport numpy.typing as npt\n\nf8: np.float64\nAR_f8: npt.NDArray[np.float64]\nAR_M: npt.NDArray[np.datetime64]\nAR_b: npt.NDArray[np.bool]\n\nctypes_obj = AR_f8.ctypes\n\nf8.argpartition(0) # type: ignore[attr-defined]\nf8.diagonal() # type: ignore[attr-defined]\nf8.dot(1) # type: ignore[attr-defined]\nf8.nonzero() # type: ignore[attr-defined]\nf8.partition(0) # type: ignore[attr-defined]\nf8.put(0, 2) # type: ignore[attr-defined]\nf8.setfield(2, np.float64) # type: ignore[attr-defined]\nf8.sort() # type: ignore[attr-defined]\nf8.trace() # type: ignore[attr-defined]\n\nAR_M.__complex__() # type: ignore[misc]\nAR_b.__index__() # type: ignore[misc]\n\nAR_f8[1.5] # type: ignore[call-overload]\nAR_f8["field_a"] # type: ignore[call-overload]\nAR_f8[["field_a", "field_b"]] # type: ignore[index]\n\nAR_f8.__array_finalize__(object()) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\ndarray_misc.pyi | ndarray_misc.pyi | Other | 1,097 | 0.95 | 0.083333 | 0 | awesome-app | 481 | 2025-03-25T13:36:04.591933 | MIT | true | a629ddca48b001d5c939f6233581843d |
import numpy as np\n\nclass Test(np.nditer): ... # type: ignore[misc]\n\nnp.nditer([0, 1], flags=["test"]) # type: ignore[list-item]\nnp.nditer([0, 1], op_flags=[["test"]]) # type: ignore[list-item]\nnp.nditer([0, 1], itershape=(1.0,)) # type: ignore[arg-type]\nnp.nditer([0, 1], buffersize=1.0) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\nditer.pyi | nditer.pyi | Other | 327 | 0.95 | 0.125 | 0 | python-kit | 192 | 2024-10-01T15:40:42.710747 | BSD-3-Clause | true | cbd7e6bdfd01afd6ac11476b51fa88fe |
from collections.abc import Sequence\nfrom numpy._typing import _NestedSequence\n\na: Sequence[float]\nb: list[complex]\nc: tuple[str, ...]\nd: int\ne: str\n\ndef func(a: _NestedSequence[int]) -> None: ...\n\nreveal_type(func(a)) # type: ignore[arg-type, misc]\nreveal_type(func(b)) # type: ignore[arg-type, misc]\nreveal_type(func(c)) # type: ignore[arg-type, misc]\nreveal_type(func(d)) # type: ignore[arg-type, misc]\nreveal_type(func(e)) # type: ignore[arg-type, misc]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\nested_sequence.pyi | nested_sequence.pyi | Other | 479 | 0.95 | 0.0625 | 0 | vue-tools | 910 | 2024-03-09T14:54:09.873700 | Apache-2.0 | true | b708f35956f2ae8ca12bb0da6824fef1 |
import pathlib\nfrom typing import IO\n\nimport numpy.typing as npt\nimport numpy as np\n\nstr_path: str\nbytes_path: bytes\npathlib_path: pathlib.Path\nstr_file: IO[str]\nAR_i8: npt.NDArray[np.int64]\n\nnp.load(str_file) # type: ignore[arg-type]\n\nnp.save(bytes_path, AR_i8) # type: ignore[call-overload]\nnp.save(str_path, AR_i8, fix_imports=True) # type: ignore[deprecated] # pyright: ignore[reportDeprecated]\n\nnp.savez(bytes_path, AR_i8) # type: ignore[arg-type]\n\nnp.savez_compressed(bytes_path, AR_i8) # type: ignore[arg-type]\n\nnp.loadtxt(bytes_path) # type: ignore[arg-type]\n\nnp.fromregex(bytes_path, ".", np.int64) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\npyio.pyi | npyio.pyi | Other | 670 | 0.95 | 0 | 0 | react-lib | 832 | 2025-04-03T15:46:56.561656 | MIT | true | 248e2ca08f9551973c2adcb0e3863c3f |
import numpy as np\n\nnp.isdtype(1, np.int64) # type: ignore[arg-type]\n\nnp.issubdtype(1, np.int64) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\numerictypes.pyi | numerictypes.pyi | Other | 129 | 0.95 | 0 | 0 | vue-tools | 339 | 2024-07-03T18:45:44.360564 | MIT | true | c15bfe6b809739cbda529eb704ca6570 |
import numpy as np\nimport numpy.typing as npt\n\nSEED_FLOAT: float = 457.3\nSEED_ARR_FLOAT: npt.NDArray[np.float64] = np.array([1.0, 2, 3, 4])\nSEED_ARRLIKE_FLOAT: list[float] = [1.0, 2.0, 3.0, 4.0]\nSEED_SEED_SEQ: np.random.SeedSequence = np.random.SeedSequence(0)\nSEED_STR: str = "String seeding not allowed"\n\n# default rng\nnp.random.default_rng(SEED_FLOAT) # type: ignore[arg-type]\nnp.random.default_rng(SEED_ARR_FLOAT) # type: ignore[arg-type]\nnp.random.default_rng(SEED_ARRLIKE_FLOAT) # type: ignore[arg-type]\nnp.random.default_rng(SEED_STR) # type: ignore[arg-type]\n\n# Seed Sequence\nnp.random.SeedSequence(SEED_FLOAT) # type: ignore[arg-type]\nnp.random.SeedSequence(SEED_ARR_FLOAT) # type: ignore[arg-type]\nnp.random.SeedSequence(SEED_ARRLIKE_FLOAT) # type: ignore[arg-type]\nnp.random.SeedSequence(SEED_SEED_SEQ) # type: ignore[arg-type]\nnp.random.SeedSequence(SEED_STR) # type: ignore[arg-type]\n\nseed_seq: np.random.bit_generator.SeedSequence = np.random.SeedSequence()\nseed_seq.spawn(11.5) # type: ignore[arg-type]\nseed_seq.generate_state(3.14) # type: ignore[arg-type]\nseed_seq.generate_state(3, np.uint8) # type: ignore[arg-type]\nseed_seq.generate_state(3, "uint8") # type: ignore[arg-type]\nseed_seq.generate_state(3, "u1") # type: ignore[arg-type]\nseed_seq.generate_state(3, np.uint16) # type: ignore[arg-type]\nseed_seq.generate_state(3, "uint16") # type: ignore[arg-type]\nseed_seq.generate_state(3, "u2") # type: ignore[arg-type]\nseed_seq.generate_state(3, np.int32) # type: ignore[arg-type]\nseed_seq.generate_state(3, "int32") # type: ignore[arg-type]\nseed_seq.generate_state(3, "i4") # type: ignore[arg-type]\n\n# Bit Generators\nnp.random.MT19937(SEED_FLOAT) # type: ignore[arg-type]\nnp.random.MT19937(SEED_ARR_FLOAT) # type: ignore[arg-type]\nnp.random.MT19937(SEED_ARRLIKE_FLOAT) # type: ignore[arg-type]\nnp.random.MT19937(SEED_STR) # type: ignore[arg-type]\n\nnp.random.PCG64(SEED_FLOAT) # type: ignore[arg-type]\nnp.random.PCG64(SEED_ARR_FLOAT) # type: ignore[arg-type]\nnp.random.PCG64(SEED_ARRLIKE_FLOAT) # type: ignore[arg-type]\nnp.random.PCG64(SEED_STR) # type: ignore[arg-type]\n\nnp.random.Philox(SEED_FLOAT) # type: ignore[arg-type]\nnp.random.Philox(SEED_ARR_FLOAT) # type: ignore[arg-type]\nnp.random.Philox(SEED_ARRLIKE_FLOAT) # type: ignore[arg-type]\nnp.random.Philox(SEED_STR) # type: ignore[arg-type]\n\nnp.random.SFC64(SEED_FLOAT) # type: ignore[arg-type]\nnp.random.SFC64(SEED_ARR_FLOAT) # type: ignore[arg-type]\nnp.random.SFC64(SEED_ARRLIKE_FLOAT) # type: ignore[arg-type]\nnp.random.SFC64(SEED_STR) # type: ignore[arg-type]\n\n# Generator\nnp.random.Generator(None) # type: ignore[arg-type]\nnp.random.Generator(12333283902830213) # type: ignore[arg-type]\nnp.random.Generator("OxFEEDF00D") # type: ignore[arg-type]\nnp.random.Generator([123, 234]) # type: ignore[arg-type]\nnp.random.Generator(np.array([123, 234], dtype="u4")) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\random.pyi | random.pyi | Other | 2,965 | 0.95 | 0 | 0.075472 | vue-tools | 531 | 2024-09-09T02:56:29.186333 | Apache-2.0 | true | d416ba1f60f4d03aa156ae73ce057f6f |
import numpy as np\nimport numpy.typing as npt\n\nAR_i8: npt.NDArray[np.int64]\n\nnp.rec.fromarrays(1) # type: ignore[call-overload]\nnp.rec.fromarrays([1, 2, 3], dtype=[("f8", "f8")], formats=["f8", "f8"]) # type: ignore[call-overload]\n\nnp.rec.fromrecords(AR_i8) # type: ignore[arg-type]\nnp.rec.fromrecords([(1.5,)], dtype=[("f8", "f8")], formats=["f8", "f8"]) # type: ignore[call-overload]\n\nnp.rec.fromstring("string", dtype=[("f8", "f8")]) # type: ignore[call-overload]\nnp.rec.fromstring(b"bytes") # type: ignore[call-overload]\nnp.rec.fromstring(b"(1.5,)", dtype=[("f8", "f8")], formats=["f8", "f8"]) # type: ignore[call-overload]\n\nwith open("test", "r") as f:\n np.rec.fromfile(f, dtype=[("f8", "f8")]) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\rec.pyi | rec.pyi | Other | 758 | 0.95 | 0 | 0 | react-lib | 350 | 2025-01-18T19:41:40.368341 | MIT | true | a329c356461883de8c428da52adbb5be |
import sys\nimport numpy as np\n\nf2: np.float16\nf8: np.float64\nc8: np.complex64\n\n# Construction\n\nnp.float32(3j) # type: ignore[arg-type]\n\n# Technically the following examples are valid NumPy code. But they\n# are not considered a best practice, and people who wish to use the\n# stubs should instead do\n#\n# np.array([1.0, 0.0, 0.0], dtype=np.float32)\n# np.array([], dtype=np.complex64)\n#\n# See e.g. the discussion on the mailing list\n#\n# https://mail.python.org/pipermail/numpy-discussion/2020-April/080566.html\n#\n# and the issue\n#\n# https://github.com/numpy/numpy-stubs/issues/41\n#\n# for more context.\nnp.float32([1.0, 0.0, 0.0]) # type: ignore[arg-type]\nnp.complex64([]) # type: ignore[call-overload]\n\n# TODO: protocols (can't check for non-existent protocols w/ __getattr__)\n\nnp.datetime64(0) # type: ignore[call-overload]\n\nclass A:\n def __float__(self) -> float: ...\n\nnp.int8(A()) # type: ignore[arg-type]\nnp.int16(A()) # type: ignore[arg-type]\nnp.int32(A()) # type: ignore[arg-type]\nnp.int64(A()) # type: ignore[arg-type]\nnp.uint8(A()) # type: ignore[arg-type]\nnp.uint16(A()) # type: ignore[arg-type]\nnp.uint32(A()) # type: ignore[arg-type]\nnp.uint64(A()) # type: ignore[arg-type]\n\nnp.void("test") # type: ignore[call-overload]\nnp.void("test", dtype=None) # type: ignore[call-overload]\n\nnp.generic(1) # type: ignore[abstract]\nnp.number(1) # type: ignore[abstract]\nnp.integer(1) # type: ignore[abstract]\nnp.inexact(1) # type: ignore[abstract]\nnp.character("test") # type: ignore[abstract]\nnp.flexible(b"test") # type: ignore[abstract]\n\nnp.float64(value=0.0) # type: ignore[call-arg]\nnp.int64(value=0) # type: ignore[call-arg]\nnp.uint64(value=0) # type: ignore[call-arg]\nnp.complex128(value=0.0j) # type: ignore[call-overload]\nnp.str_(value='bob') # type: ignore[call-overload]\nnp.bytes_(value=b'test') # type: ignore[call-overload]\nnp.void(value=b'test') # type: ignore[call-overload]\nnp.bool(value=True) # type: ignore[call-overload]\nnp.datetime64(value="2019") # type: ignore[call-overload]\nnp.timedelta64(value=0) # type: ignore[call-overload]\n\nnp.bytes_(b"hello", encoding='utf-8') # type: ignore[call-overload]\nnp.str_("hello", encoding='utf-8') # type: ignore[call-overload]\n\nf8.item(1) # type: ignore[call-overload]\nf8.item((0, 1)) # type: ignore[arg-type]\nf8.squeeze(axis=1) # type: ignore[arg-type]\nf8.squeeze(axis=(0, 1)) # type: ignore[arg-type]\nf8.transpose(1) # type: ignore[arg-type]\n\ndef func(a: np.float32) -> None: ...\n\nfunc(f2) # type: ignore[arg-type]\nfunc(f8) # type: ignore[arg-type]\n\nc8.__getnewargs__() # type: ignore[attr-defined]\nf2.__getnewargs__() # type: ignore[attr-defined]\nf2.hex() # type: ignore[attr-defined]\nnp.float16.fromhex("0x0.0p+0") # type: ignore[attr-defined]\nf2.__trunc__() # type: ignore[attr-defined]\nf2.__getformat__("float") # type: ignore[attr-defined]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\scalars.pyi | scalars.pyi | Other | 2,936 | 0.95 | 0.057471 | 0.253521 | node-utils | 34 | 2024-08-07T00:43:03.996129 | MIT | true | a904ca05439f17579765e4af09015ab8 |
from typing import Any\nimport numpy as np\n\n# test bounds of _ShapeT_co\n\nnp.ndarray[tuple[str, str], Any] # type: ignore[type-var]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\shape.pyi | shape.pyi | Other | 137 | 0.95 | 0 | 0.25 | react-lib | 947 | 2024-04-16T16:39:10.456336 | MIT | true | 7704370b815ad7d11edb18b3c63d6a82 |
import numpy as np\n\nclass DTypeLike:\n dtype: np.dtype[np.int_]\n\ndtype_like: DTypeLike\n\nnp.expand_dims(dtype_like, (5, 10)) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\shape_base.pyi | shape_base.pyi | Other | 165 | 0.95 | 0.125 | 0 | vue-tools | 767 | 2025-06-06T14:36:32.416363 | Apache-2.0 | true | 2435f8b9506066de0577b02500b437e2 |
import numpy as np\nimport numpy.typing as npt\n\nAR_f8: npt.NDArray[np.float64]\n\nnp.lib.stride_tricks.as_strided(AR_f8, shape=8) # type: ignore[call-overload]\nnp.lib.stride_tricks.as_strided(AR_f8, strides=8) # type: ignore[call-overload]\n\nnp.lib.stride_tricks.sliding_window_view(AR_f8, axis=(1,)) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\stride_tricks.pyi | stride_tricks.pyi | Other | 339 | 0.95 | 0 | 0 | vue-tools | 497 | 2024-07-25T01:12:58.079207 | BSD-3-Clause | true | acbebd5a6db79b374d4ff76a343d5968 |
import numpy as np\nimport numpy.typing as npt\n\nAR_U: npt.NDArray[np.str_]\nAR_S: npt.NDArray[np.bytes_]\n\nnp.strings.equal(AR_U, AR_S) # type: ignore[arg-type]\nnp.strings.not_equal(AR_U, AR_S) # type: ignore[arg-type]\n\nnp.strings.greater_equal(AR_U, AR_S) # type: ignore[arg-type]\nnp.strings.less_equal(AR_U, AR_S) # type: ignore[arg-type]\nnp.strings.greater(AR_U, AR_S) # type: ignore[arg-type]\nnp.strings.less(AR_U, AR_S) # type: ignore[arg-type]\n\nnp.strings.encode(AR_S) # type: ignore[arg-type]\nnp.strings.decode(AR_U) # type: ignore[arg-type]\n\nnp.strings.lstrip(AR_U, b"a") # type: ignore[arg-type]\nnp.strings.lstrip(AR_S, "a") # type: ignore[arg-type]\nnp.strings.strip(AR_U, b"a") # type: ignore[arg-type]\nnp.strings.strip(AR_S, "a") # type: ignore[arg-type]\nnp.strings.rstrip(AR_U, b"a") # type: ignore[arg-type]\nnp.strings.rstrip(AR_S, "a") # type: ignore[arg-type]\n\nnp.strings.partition(AR_U, b"a") # type: ignore[arg-type]\nnp.strings.partition(AR_S, "a") # type: ignore[arg-type]\nnp.strings.rpartition(AR_U, b"a") # type: ignore[arg-type]\nnp.strings.rpartition(AR_S, "a") # type: ignore[arg-type]\n\nnp.strings.count(AR_U, b"a", [1, 2, 3], [1, 2, 3]) # type: ignore[arg-type]\nnp.strings.count(AR_S, "a", 0, 9) # type: ignore[arg-type]\n\nnp.strings.endswith(AR_U, b"a", [1, 2, 3], [1, 2, 3]) # type: ignore[arg-type]\nnp.strings.endswith(AR_S, "a", 0, 9) # type: ignore[arg-type]\nnp.strings.startswith(AR_U, b"a", [1, 2, 3], [1, 2, 3]) # type: ignore[arg-type]\nnp.strings.startswith(AR_S, "a", 0, 9) # type: ignore[arg-type]\n\nnp.strings.find(AR_U, b"a", [1, 2, 3], [1, 2, 3]) # type: ignore[arg-type]\nnp.strings.find(AR_S, "a", 0, 9) # type: ignore[arg-type]\nnp.strings.rfind(AR_U, b"a", [1, 2, 3], [1, 2, 3]) # type: ignore[arg-type]\nnp.strings.rfind(AR_S, "a", 0, 9) # type: ignore[arg-type]\n\nnp.strings.index(AR_U, b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nnp.strings.index(AR_S, "a", end=9) # type: ignore[arg-type]\nnp.strings.rindex(AR_U, b"a", start=[1, 2, 3]) # type: ignore[arg-type]\nnp.strings.rindex(AR_S, "a", end=9) # type: ignore[arg-type]\n\nnp.strings.isdecimal(AR_S) # type: ignore[arg-type]\nnp.strings.isnumeric(AR_S) # type: ignore[arg-type]\n\nnp.strings.replace(AR_U, b"_", b"-", 10) # type: ignore[arg-type]\nnp.strings.replace(AR_S, "_", "-", 1) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\strings.pyi | strings.pyi | Other | 2,385 | 0.95 | 0 | 0 | node-utils | 740 | 2024-04-27T11:21:11.657904 | GPL-3.0 | true | 53af87b5851381fe1987e70b520e3fc9 |
import numpy as np\nimport numpy.typing as npt\n\nAR_U: npt.NDArray[np.str_]\n\ndef func(x: object) -> bool: ...\n\nnp.testing.assert_(True, msg=1) # type: ignore[arg-type]\nnp.testing.build_err_msg(1, "test") # type: ignore[arg-type]\nnp.testing.assert_almost_equal(AR_U, AR_U) # type: ignore[arg-type]\nnp.testing.assert_approx_equal([1, 2, 3], [1, 2, 3]) # type: ignore[arg-type]\nnp.testing.assert_array_almost_equal(AR_U, AR_U) # type: ignore[arg-type]\nnp.testing.assert_array_less(AR_U, AR_U) # type: ignore[arg-type]\nnp.testing.assert_string_equal(b"a", b"a") # type: ignore[arg-type]\n\nnp.testing.assert_raises(expected_exception=TypeError, callable=func) # type: ignore[call-overload]\nnp.testing.assert_raises_regex(expected_exception=TypeError, expected_regex="T", callable=func) # type: ignore[call-overload]\n\nnp.testing.assert_allclose(AR_U, AR_U) # type: ignore[arg-type]\nnp.testing.assert_array_almost_equal_nulp(AR_U, AR_U) # type: ignore[arg-type]\nnp.testing.assert_array_max_ulp(AR_U, AR_U) # type: ignore[arg-type]\n\nnp.testing.assert_warns(RuntimeWarning, func) # type: ignore[call-overload]\nnp.testing.assert_no_warnings(func=func) # type: ignore[call-overload]\nnp.testing.assert_no_warnings(func) # type: ignore[call-overload]\nnp.testing.assert_no_warnings(func, y=None) # type: ignore[call-overload]\n\nnp.testing.assert_no_gc_cycles(func=func) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\testing.pyi | testing.pyi | Other | 1,427 | 0.95 | 0.035714 | 0 | vue-tools | 810 | 2023-12-03T15:54:22.299964 | GPL-3.0 | true | 37f172cdf953acbf7ca2b3748140ae73 |
from typing import Any, TypeVar\n\nimport numpy as np\nimport numpy.typing as npt\n\ndef func1(ar: npt.NDArray[Any], a: int) -> npt.NDArray[np.str_]: ...\n\ndef func2(ar: npt.NDArray[Any], a: float) -> float: ...\n\nAR_b: npt.NDArray[np.bool]\nAR_m: npt.NDArray[np.timedelta64]\n\nAR_LIKE_b: list[bool]\n\nnp.eye(10, M=20.0) # type: ignore[call-overload]\nnp.eye(10, k=2.5, dtype=int) # type: ignore[call-overload]\n\nnp.diag(AR_b, k=0.5) # type: ignore[call-overload]\nnp.diagflat(AR_b, k=0.5) # type: ignore[call-overload]\n\nnp.tri(10, M=20.0) # type: ignore[call-overload]\nnp.tri(10, k=2.5, dtype=int) # type: ignore[call-overload]\n\nnp.tril(AR_b, k=0.5) # type: ignore[call-overload]\nnp.triu(AR_b, k=0.5) # type: ignore[call-overload]\n\nnp.vander(AR_m) # type: ignore[arg-type]\n\nnp.histogram2d(AR_m) # type: ignore[call-overload]\n\nnp.mask_indices(10, func1) # type: ignore[arg-type]\nnp.mask_indices(10, func2, 10.5) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\twodim_base.pyi | twodim_base.pyi | Other | 968 | 0.95 | 0.0625 | 0 | react-lib | 411 | 2024-03-11T06:34:20.450220 | MIT | true | 6565af34cc72e939a63d5c2cbaf570be |
import numpy as np\nimport numpy.typing as npt\n\nDTYPE_i8: np.dtype[np.int64]\n\nnp.mintypecode(DTYPE_i8) # type: ignore[arg-type]\nnp.iscomplexobj(DTYPE_i8) # type: ignore[arg-type]\nnp.isrealobj(DTYPE_i8) # type: ignore[arg-type]\n\nnp.typename(DTYPE_i8) # type: ignore[call-overload]\nnp.typename("invalid") # type: ignore[call-overload]\n\nnp.common_type(np.timedelta64()) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\type_check.pyi | type_check.pyi | Other | 410 | 0.95 | 0 | 0 | python-kit | 269 | 2023-10-06T11:41:32.006128 | Apache-2.0 | true | e6072b9226e1432724b3ff6b8e5b92c1 |
import numpy as np\nimport numpy.typing as npt\n\nAR_c: npt.NDArray[np.complex128]\nAR_m: npt.NDArray[np.timedelta64]\nAR_M: npt.NDArray[np.datetime64]\nAR_O: npt.NDArray[np.object_]\n\nnp.fix(AR_c) # type: ignore[arg-type]\nnp.fix(AR_m) # type: ignore[arg-type]\nnp.fix(AR_M) # type: ignore[arg-type]\n\nnp.isposinf(AR_c) # type: ignore[arg-type]\nnp.isposinf(AR_m) # type: ignore[arg-type]\nnp.isposinf(AR_M) # type: ignore[arg-type]\nnp.isposinf(AR_O) # type: ignore[arg-type]\n\nnp.isneginf(AR_c) # type: ignore[arg-type]\nnp.isneginf(AR_m) # type: ignore[arg-type]\nnp.isneginf(AR_M) # type: ignore[arg-type]\nnp.isneginf(AR_O) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\ufunclike.pyi | ufunclike.pyi | Other | 670 | 0.95 | 0 | 0 | vue-tools | 357 | 2024-03-25T00:29:54.531646 | BSD-3-Clause | true | a573825ee774d1bafebe2ca935759ac5 |
import numpy as np\nimport numpy.typing as npt\n\nAR_f8: npt.NDArray[np.float64]\n\nnp.sin.nin + "foo" # type: ignore[operator]\nnp.sin(1, foo="bar") # type: ignore[call-overload]\n\nnp.abs(None) # type: ignore[call-overload]\n\nnp.add(1, 1, 1) # type: ignore[call-overload]\nnp.add(1, 1, axis=0) # type: ignore[call-overload]\n\nnp.matmul(AR_f8, AR_f8, where=True) # type: ignore[call-overload]\n\nnp.frexp(AR_f8, out=None) # type: ignore[call-overload]\nnp.frexp(AR_f8, out=AR_f8) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\ufuncs.pyi | ufuncs.pyi | Other | 522 | 0.95 | 0 | 0 | node-utils | 812 | 2024-05-01T18:48:56.038599 | MIT | true | 2127c6821791a33ef223b7764c23a805 |
"""Typing tests for `numpy._core._ufunc_config`."""\n\nimport numpy as np\n\ndef func1(a: str, b: int, c: float) -> None: ...\ndef func2(a: str, *, b: int) -> None: ...\n\nclass Write1:\n def write1(self, a: str) -> None: ...\n\nclass Write2:\n def write(self, a: str, b: str) -> None: ...\n\nclass Write3:\n def write(self, *, a: str) -> None: ...\n\nnp.seterrcall(func1) # type: ignore[arg-type]\nnp.seterrcall(func2) # type: ignore[arg-type]\nnp.seterrcall(Write1()) # type: ignore[arg-type]\nnp.seterrcall(Write2()) # type: ignore[arg-type]\nnp.seterrcall(Write3()) # type: ignore[arg-type]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\ufunc_config.pyi | ufunc_config.pyi | Other | 610 | 0.95 | 0.428571 | 0 | awesome-app | 812 | 2025-03-02T14:50:59.762074 | MIT | true | d6ff6a83ed0b1c9bb96326e3c718e658 |
import numpy.exceptions as ex\n\nex.AxisError(1.0) # type: ignore[call-overload]\nex.AxisError(1, ndim=2.0) # type: ignore[call-overload]\nex.AxisError(2, msg_prefix=404) # type: ignore[call-overload]\n | .venv\Lib\site-packages\numpy\typing\tests\data\fail\warnings_and_errors.pyi | warnings_and_errors.pyi | Other | 205 | 0.95 | 0 | 0 | awesome-app | 56 | 2023-07-31T14:26:04.368669 | GPL-3.0 | true | 9e7204dd381401ef2567beb66e3359cd |
import numpy as np\nfrom numpy._typing import _96Bit, _128Bit\n\nfrom typing import assert_type\n\nassert_type(np.float96(), np.floating[_96Bit])\nassert_type(np.float128(), np.floating[_128Bit])\nassert_type(np.complex192(), np.complexfloating[_96Bit, _96Bit])\nassert_type(np.complex256(), np.complexfloating[_128Bit, _128Bit])\n | .venv\Lib\site-packages\numpy\typing\tests\data\misc\extended_precision.pyi | extended_precision.pyi | Other | 331 | 0.85 | 0 | 0 | awesome-app | 706 | 2023-08-22T00:58:44.376241 | Apache-2.0 | true | d8cd4bab7c76d0364e0e5866608d0814 |
from __future__ import annotations\n\nfrom typing import Any, cast\nimport numpy as np\nimport numpy.typing as npt\nimport pytest\n\nc16 = np.complex128(1)\nf8 = np.float64(1)\ni8 = np.int64(1)\nu8 = np.uint64(1)\n\nc8 = np.complex64(1)\nf4 = np.float32(1)\ni4 = np.int32(1)\nu4 = np.uint32(1)\n\ndt = np.datetime64(1, "D")\ntd = np.timedelta64(1, "D")\n\nb_ = np.bool(1)\n\nb = bool(1)\nc = complex(1)\nf = float(1)\ni = int(1)\n\n\nclass Object:\n def __array__(self, dtype: np.typing.DTypeLike = None,\n copy: bool | None = None) -> np.ndarray[Any, np.dtype[np.object_]]:\n ret = np.empty((), dtype=object)\n ret[()] = self\n return ret\n\n def __sub__(self, value: Any) -> Object:\n return self\n\n def __rsub__(self, value: Any) -> Object:\n return self\n\n def __floordiv__(self, value: Any) -> Object:\n return self\n\n def __rfloordiv__(self, value: Any) -> Object:\n return self\n\n def __mul__(self, value: Any) -> Object:\n return self\n\n def __rmul__(self, value: Any) -> Object:\n return self\n\n def __pow__(self, value: Any) -> Object:\n return self\n\n def __rpow__(self, value: Any) -> Object:\n return self\n\n\nAR_b: npt.NDArray[np.bool] = np.array([True])\nAR_u: npt.NDArray[np.uint32] = np.array([1], dtype=np.uint32)\nAR_i: npt.NDArray[np.int64] = np.array([1])\nAR_integer: npt.NDArray[np.integer] = cast(npt.NDArray[np.integer], AR_i)\nAR_f: npt.NDArray[np.float64] = np.array([1.0])\nAR_c: npt.NDArray[np.complex128] = np.array([1j])\nAR_m: npt.NDArray[np.timedelta64] = np.array([np.timedelta64(1, "D")])\nAR_M: npt.NDArray[np.datetime64] = np.array([np.datetime64(1, "D")])\nAR_O: npt.NDArray[np.object_] = np.array([Object()])\n\nAR_LIKE_b = [True]\nAR_LIKE_u = [np.uint32(1)]\nAR_LIKE_i = [1]\nAR_LIKE_f = [1.0]\nAR_LIKE_c = [1j]\nAR_LIKE_m = [np.timedelta64(1, "D")]\nAR_LIKE_M = [np.datetime64(1, "D")]\nAR_LIKE_O = [Object()]\n\n# Array subtractions\n\nAR_b - AR_LIKE_u\nAR_b - AR_LIKE_i\nAR_b - AR_LIKE_f\nAR_b - AR_LIKE_c\nAR_b - AR_LIKE_m\nAR_b - AR_LIKE_O\n\nAR_LIKE_u - AR_b\nAR_LIKE_i - AR_b\nAR_LIKE_f - AR_b\nAR_LIKE_c - AR_b\nAR_LIKE_m - AR_b\nAR_LIKE_M - AR_b\nAR_LIKE_O - AR_b\n\nAR_u - AR_LIKE_b\nAR_u - AR_LIKE_u\nAR_u - AR_LIKE_i\nAR_u - AR_LIKE_f\nAR_u - AR_LIKE_c\nAR_u - AR_LIKE_m\nAR_u - AR_LIKE_O\n\nAR_LIKE_b - AR_u\nAR_LIKE_u - AR_u\nAR_LIKE_i - AR_u\nAR_LIKE_f - AR_u\nAR_LIKE_c - AR_u\nAR_LIKE_m - AR_u\nAR_LIKE_M - AR_u\nAR_LIKE_O - AR_u\n\nAR_i - AR_LIKE_b\nAR_i - AR_LIKE_u\nAR_i - AR_LIKE_i\nAR_i - AR_LIKE_f\nAR_i - AR_LIKE_c\nAR_i - AR_LIKE_m\nAR_i - AR_LIKE_O\n\nAR_LIKE_b - AR_i\nAR_LIKE_u - AR_i\nAR_LIKE_i - AR_i\nAR_LIKE_f - AR_i\nAR_LIKE_c - AR_i\nAR_LIKE_m - AR_i\nAR_LIKE_M - AR_i\nAR_LIKE_O - AR_i\n\nAR_f - AR_LIKE_b\nAR_f - AR_LIKE_u\nAR_f - AR_LIKE_i\nAR_f - AR_LIKE_f\nAR_f - AR_LIKE_c\nAR_f - AR_LIKE_O\n\nAR_LIKE_b - AR_f\nAR_LIKE_u - AR_f\nAR_LIKE_i - AR_f\nAR_LIKE_f - AR_f\nAR_LIKE_c - AR_f\nAR_LIKE_O - AR_f\n\nAR_c - AR_LIKE_b\nAR_c - AR_LIKE_u\nAR_c - AR_LIKE_i\nAR_c - AR_LIKE_f\nAR_c - AR_LIKE_c\nAR_c - AR_LIKE_O\n\nAR_LIKE_b - AR_c\nAR_LIKE_u - AR_c\nAR_LIKE_i - AR_c\nAR_LIKE_f - AR_c\nAR_LIKE_c - AR_c\nAR_LIKE_O - AR_c\n\nAR_m - AR_LIKE_b\nAR_m - AR_LIKE_u\nAR_m - AR_LIKE_i\nAR_m - AR_LIKE_m\n\nAR_LIKE_b - AR_m\nAR_LIKE_u - AR_m\nAR_LIKE_i - AR_m\nAR_LIKE_m - AR_m\nAR_LIKE_M - AR_m\n\nAR_M - AR_LIKE_b\nAR_M - AR_LIKE_u\nAR_M - AR_LIKE_i\nAR_M - AR_LIKE_m\nAR_M - AR_LIKE_M\n\nAR_LIKE_M - AR_M\n\nAR_O - AR_LIKE_b\nAR_O - AR_LIKE_u\nAR_O - AR_LIKE_i\nAR_O - AR_LIKE_f\nAR_O - AR_LIKE_c\nAR_O - AR_LIKE_O\n\nAR_LIKE_b - AR_O\nAR_LIKE_u - AR_O\nAR_LIKE_i - AR_O\nAR_LIKE_f - AR_O\nAR_LIKE_c - AR_O\nAR_LIKE_O - AR_O\n\nAR_u += AR_b\nAR_u += AR_u\nAR_u += 1 # Allowed during runtime as long as the object is 0D and >=0\n\n# Array floor division\n\nAR_b // AR_LIKE_b\nAR_b // AR_LIKE_u\nAR_b // AR_LIKE_i\nAR_b // AR_LIKE_f\nAR_b // AR_LIKE_O\n\nAR_LIKE_b // AR_b\nAR_LIKE_u // AR_b\nAR_LIKE_i // AR_b\nAR_LIKE_f // AR_b\nAR_LIKE_O // AR_b\n\nAR_u // AR_LIKE_b\nAR_u // AR_LIKE_u\nAR_u // AR_LIKE_i\nAR_u // AR_LIKE_f\nAR_u // AR_LIKE_O\n\nAR_LIKE_b // AR_u\nAR_LIKE_u // AR_u\nAR_LIKE_i // AR_u\nAR_LIKE_f // AR_u\nAR_LIKE_m // AR_u\nAR_LIKE_O // AR_u\n\nAR_i // AR_LIKE_b\nAR_i // AR_LIKE_u\nAR_i // AR_LIKE_i\nAR_i // AR_LIKE_f\nAR_i // AR_LIKE_O\n\nAR_LIKE_b // AR_i\nAR_LIKE_u // AR_i\nAR_LIKE_i // AR_i\nAR_LIKE_f // AR_i\nAR_LIKE_m // AR_i\nAR_LIKE_O // AR_i\n\nAR_f // AR_LIKE_b\nAR_f // AR_LIKE_u\nAR_f // AR_LIKE_i\nAR_f // AR_LIKE_f\nAR_f // AR_LIKE_O\n\nAR_LIKE_b // AR_f\nAR_LIKE_u // AR_f\nAR_LIKE_i // AR_f\nAR_LIKE_f // AR_f\nAR_LIKE_m // AR_f\nAR_LIKE_O // AR_f\n\nAR_m // AR_LIKE_u\nAR_m // AR_LIKE_i\nAR_m // AR_LIKE_f\nAR_m // AR_LIKE_m\n\nAR_LIKE_m // AR_m\n\nAR_m /= f\nAR_m //= f\nAR_m /= AR_f\nAR_m /= AR_LIKE_f\nAR_m //= AR_f\nAR_m //= AR_LIKE_f\n\nAR_O // AR_LIKE_b\nAR_O // AR_LIKE_u\nAR_O // AR_LIKE_i\nAR_O // AR_LIKE_f\nAR_O // AR_LIKE_O\n\nAR_LIKE_b // AR_O\nAR_LIKE_u // AR_O\nAR_LIKE_i // AR_O\nAR_LIKE_f // AR_O\nAR_LIKE_O // AR_O\n\n# Inplace multiplication\n\nAR_b *= AR_LIKE_b\n\nAR_u *= AR_LIKE_b\nAR_u *= AR_LIKE_u\n\nAR_i *= AR_LIKE_b\nAR_i *= AR_LIKE_u\nAR_i *= AR_LIKE_i\n\nAR_integer *= AR_LIKE_b\nAR_integer *= AR_LIKE_u\nAR_integer *= AR_LIKE_i\n\nAR_f *= AR_LIKE_b\nAR_f *= AR_LIKE_u\nAR_f *= AR_LIKE_i\nAR_f *= AR_LIKE_f\n\nAR_c *= AR_LIKE_b\nAR_c *= AR_LIKE_u\nAR_c *= AR_LIKE_i\nAR_c *= AR_LIKE_f\nAR_c *= AR_LIKE_c\n\nAR_m *= AR_LIKE_b\nAR_m *= AR_LIKE_u\nAR_m *= AR_LIKE_i\nAR_m *= AR_LIKE_f\n\nAR_O *= AR_LIKE_b\nAR_O *= AR_LIKE_u\nAR_O *= AR_LIKE_i\nAR_O *= AR_LIKE_f\nAR_O *= AR_LIKE_c\nAR_O *= AR_LIKE_O\n\n# Inplace power\n\nAR_u **= AR_LIKE_b\nAR_u **= AR_LIKE_u\n\nAR_i **= AR_LIKE_b\nAR_i **= AR_LIKE_u\nAR_i **= AR_LIKE_i\n\nAR_integer **= AR_LIKE_b\nAR_integer **= AR_LIKE_u\nAR_integer **= AR_LIKE_i\n\nAR_f **= AR_LIKE_b\nAR_f **= AR_LIKE_u\nAR_f **= AR_LIKE_i\nAR_f **= AR_LIKE_f\n\nAR_c **= AR_LIKE_b\nAR_c **= AR_LIKE_u\nAR_c **= AR_LIKE_i\nAR_c **= AR_LIKE_f\nAR_c **= AR_LIKE_c\n\nAR_O **= AR_LIKE_b\nAR_O **= AR_LIKE_u\nAR_O **= AR_LIKE_i\nAR_O **= AR_LIKE_f\nAR_O **= AR_LIKE_c\nAR_O **= AR_LIKE_O\n\n# unary ops\n\n-c16\n-c8\n-f8\n-f4\n-i8\n-i4\nwith pytest.warns(RuntimeWarning):\n -u8\n -u4\n-td\n-AR_f\n\n+c16\n+c8\n+f8\n+f4\n+i8\n+i4\n+u8\n+u4\n+td\n+AR_f\n\nabs(c16)\nabs(c8)\nabs(f8)\nabs(f4)\nabs(i8)\nabs(i4)\nabs(u8)\nabs(u4)\nabs(td)\nabs(b_)\nabs(AR_f)\n\n# Time structures\n\ndt + td\ndt + i\ndt + i4\ndt + i8\ndt - dt\ndt - i\ndt - i4\ndt - i8\n\ntd + td\ntd + i\ntd + i4\ntd + i8\ntd - td\ntd - i\ntd - i4\ntd - i8\ntd / f\ntd / f4\ntd / f8\ntd / td\ntd // td\ntd % td\n\n\n# boolean\n\nb_ / b\nb_ / b_\nb_ / i\nb_ / i8\nb_ / i4\nb_ / u8\nb_ / u4\nb_ / f\nb_ / f8\nb_ / f4\nb_ / c\nb_ / c16\nb_ / c8\n\nb / b_\nb_ / b_\ni / b_\ni8 / b_\ni4 / b_\nu8 / b_\nu4 / b_\nf / b_\nf8 / b_\nf4 / b_\nc / b_\nc16 / b_\nc8 / b_\n\n# Complex\n\nc16 + c16\nc16 + f8\nc16 + i8\nc16 + c8\nc16 + f4\nc16 + i4\nc16 + b_\nc16 + b\nc16 + c\nc16 + f\nc16 + i\nc16 + AR_f\n\nc16 + c16\nf8 + c16\ni8 + c16\nc8 + c16\nf4 + c16\ni4 + c16\nb_ + c16\nb + c16\nc + c16\nf + c16\ni + c16\nAR_f + c16\n\nc8 + c16\nc8 + f8\nc8 + i8\nc8 + c8\nc8 + f4\nc8 + i4\nc8 + b_\nc8 + b\nc8 + c\nc8 + f\nc8 + i\nc8 + AR_f\n\nc16 + c8\nf8 + c8\ni8 + c8\nc8 + c8\nf4 + c8\ni4 + c8\nb_ + c8\nb + c8\nc + c8\nf + c8\ni + c8\nAR_f + c8\n\n# Float\n\nf8 + f8\nf8 + i8\nf8 + f4\nf8 + i4\nf8 + b_\nf8 + b\nf8 + c\nf8 + f\nf8 + i\nf8 + AR_f\n\nf8 + f8\ni8 + f8\nf4 + f8\ni4 + f8\nb_ + f8\nb + f8\nc + f8\nf + f8\ni + f8\nAR_f + f8\n\nf4 + f8\nf4 + i8\nf4 + f4\nf4 + i4\nf4 + b_\nf4 + b\nf4 + c\nf4 + f\nf4 + i\nf4 + AR_f\n\nf8 + f4\ni8 + f4\nf4 + f4\ni4 + f4\nb_ + f4\nb + f4\nc + f4\nf + f4\ni + f4\nAR_f + f4\n\n# Int\n\ni8 + i8\ni8 + u8\ni8 + i4\ni8 + u4\ni8 + b_\ni8 + b\ni8 + c\ni8 + f\ni8 + i\ni8 + AR_f\n\nu8 + u8\nu8 + i4\nu8 + u4\nu8 + b_\nu8 + b\nu8 + c\nu8 + f\nu8 + i\nu8 + AR_f\n\ni8 + i8\nu8 + i8\ni4 + i8\nu4 + i8\nb_ + i8\nb + i8\nc + i8\nf + i8\ni + i8\nAR_f + i8\n\nu8 + u8\ni4 + u8\nu4 + u8\nb_ + u8\nb + u8\nc + u8\nf + u8\ni + u8\nAR_f + u8\n\ni4 + i8\ni4 + i4\ni4 + i\ni4 + b_\ni4 + b\ni4 + AR_f\n\nu4 + i8\nu4 + i4\nu4 + u8\nu4 + u4\nu4 + i\nu4 + b_\nu4 + b\nu4 + AR_f\n\ni8 + i4\ni4 + i4\ni + i4\nb_ + i4\nb + i4\nAR_f + i4\n\ni8 + u4\ni4 + u4\nu8 + u4\nu4 + u4\nb_ + u4\nb + u4\ni + u4\nAR_f + u4\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\arithmetic.py | arithmetic.py | Python | 8,374 | 0.95 | 0.01634 | 0.019417 | awesome-app | 854 | 2023-09-18T16:44:20.691387 | GPL-3.0 | true | d04aa909385412c4cbc1f5511bbf1a5b |
import numpy as np\n\nAR = np.arange(10)\nAR.setflags(write=False)\n\nwith np.printoptions():\n np.set_printoptions(\n precision=1,\n threshold=2,\n edgeitems=3,\n linewidth=4,\n suppress=False,\n nanstr="Bob",\n infstr="Bill",\n formatter={},\n sign="+",\n floatmode="unique",\n )\n np.get_printoptions()\n str(AR)\n\n np.array2string(\n AR,\n max_line_width=5,\n precision=2,\n suppress_small=True,\n separator=";",\n prefix="test",\n threshold=5,\n floatmode="fixed",\n suffix="?",\n legacy="1.13",\n )\n np.format_float_scientific(1, precision=5)\n np.format_float_positional(1, trim="k")\n np.array_repr(AR)\n np.array_str(AR)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\arrayprint.py | arrayprint.py | Python | 803 | 0.85 | 0 | 0 | vue-tools | 725 | 2025-01-01T17:58:27.124496 | BSD-3-Clause | true | 9c65b60e564a96576214f3024090220f |
\nfrom __future__ import annotations\n\nfrom typing import Any\nimport numpy as np\n\nAR_i8: np.ndarray[Any, np.dtype[np.int_]] = np.arange(10)\nar_iter = np.lib.Arrayterator(AR_i8)\n\nar_iter.var\nar_iter.buf_size\nar_iter.start\nar_iter.stop\nar_iter.step\nar_iter.shape\nar_iter.flat\n\nar_iter.__array__()\n\nfor i in ar_iter:\n pass\n\nar_iter[0]\nar_iter[...]\nar_iter[:]\nar_iter[0, 0, 0]\nar_iter[..., 0, :]\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\arrayterator.py | arrayterator.py | Python | 420 | 0.85 | 0.037037 | 0 | react-lib | 896 | 2023-12-03T20:50:06.764062 | GPL-3.0 | true | e65797a142e124c75ee5351ef9b58e67 |
from typing import Any\n\nimport numpy as np\nimport numpy.typing as npt\n\nclass Index:\n def __index__(self) -> int:\n return 0\n\n\nclass SubClass(npt.NDArray[np.float64]):\n pass\n\n\ndef func(i: int, j: int, **kwargs: Any) -> SubClass:\n return B\n\n\ni8 = np.int64(1)\n\nA = np.array([1])\nB = A.view(SubClass).copy()\nB_stack = np.array([[1], [1]]).view(SubClass)\nC = [1]\n\nnp.ndarray(Index())\nnp.ndarray([Index()])\n\nnp.array(1, dtype=float)\nnp.array(1, copy=None)\nnp.array(1, order='F')\nnp.array(1, order=None)\nnp.array(1, subok=True)\nnp.array(1, ndmin=3)\nnp.array(1, str, copy=True, order='C', subok=False, ndmin=2)\n\nnp.asarray(A)\nnp.asarray(B)\nnp.asarray(C)\n\nnp.asanyarray(A)\nnp.asanyarray(B)\nnp.asanyarray(B, dtype=int)\nnp.asanyarray(C)\n\nnp.ascontiguousarray(A)\nnp.ascontiguousarray(B)\nnp.ascontiguousarray(C)\n\nnp.asfortranarray(A)\nnp.asfortranarray(B)\nnp.asfortranarray(C)\n\nnp.require(A)\nnp.require(B)\nnp.require(B, dtype=int)\nnp.require(B, requirements=None)\nnp.require(B, requirements="E")\nnp.require(B, requirements=["ENSUREARRAY"])\nnp.require(B, requirements={"F", "E"})\nnp.require(B, requirements=["C", "OWNDATA"])\nnp.require(B, requirements="W")\nnp.require(B, requirements="A")\nnp.require(C)\n\nnp.linspace(0, 2)\nnp.linspace(0.5, [0, 1, 2])\nnp.linspace([0, 1, 2], 3)\nnp.linspace(0j, 2)\nnp.linspace(0, 2, num=10)\nnp.linspace(0, 2, endpoint=True)\nnp.linspace(0, 2, retstep=True)\nnp.linspace(0j, 2j, retstep=True)\nnp.linspace(0, 2, dtype=bool)\nnp.linspace([0, 1], [2, 3], axis=Index())\n\nnp.logspace(0, 2, base=2)\nnp.logspace(0, 2, base=2)\nnp.logspace(0, 2, base=[1j, 2j], num=2)\n\nnp.geomspace(1, 2)\n\nnp.zeros_like(A)\nnp.zeros_like(C)\nnp.zeros_like(B)\nnp.zeros_like(B, dtype=np.int64)\n\nnp.ones_like(A)\nnp.ones_like(C)\nnp.ones_like(B)\nnp.ones_like(B, dtype=np.int64)\n\nnp.empty_like(A)\nnp.empty_like(C)\nnp.empty_like(B)\nnp.empty_like(B, dtype=np.int64)\n\nnp.full_like(A, i8)\nnp.full_like(C, i8)\nnp.full_like(B, i8)\nnp.full_like(B, i8, dtype=np.int64)\n\nnp.ones(1)\nnp.ones([1, 1, 1])\n\nnp.full(1, i8)\nnp.full([1, 1, 1], i8)\n\nnp.indices([1, 2, 3])\nnp.indices([1, 2, 3], sparse=True)\n\nnp.fromfunction(func, (3, 5))\n\nnp.identity(10)\n\nnp.atleast_1d(C)\nnp.atleast_1d(A)\nnp.atleast_1d(C, C)\nnp.atleast_1d(C, A)\nnp.atleast_1d(A, A)\n\nnp.atleast_2d(C)\n\nnp.atleast_3d(C)\n\nnp.vstack([C, C])\nnp.vstack([C, A])\nnp.vstack([A, A])\n\nnp.hstack([C, C])\n\nnp.stack([C, C])\nnp.stack([C, C], axis=0)\nnp.stack([C, C], out=B_stack)\n\nnp.block([[C, C], [C, C]])\nnp.block(A)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\array_constructors.py | array_constructors.py | Python | 2,584 | 0.85 | 0.029197 | 0 | awesome-app | 320 | 2024-12-03T07:55:07.234632 | GPL-3.0 | true | 7a04f4caf8d171a031275938577a814c |
from __future__ import annotations\n\nfrom typing import TYPE_CHECKING\n\nimport numpy as np\n\nif TYPE_CHECKING:\n from numpy._typing import NDArray, ArrayLike, _SupportsArray\n\nx1: ArrayLike = True\nx2: ArrayLike = 5\nx3: ArrayLike = 1.0\nx4: ArrayLike = 1 + 1j\nx5: ArrayLike = np.int8(1)\nx6: ArrayLike = np.float64(1)\nx7: ArrayLike = np.complex128(1)\nx8: ArrayLike = np.array([1, 2, 3])\nx9: ArrayLike = [1, 2, 3]\nx10: ArrayLike = (1, 2, 3)\nx11: ArrayLike = "foo"\nx12: ArrayLike = memoryview(b'foo')\n\n\nclass A:\n def __array__(self, dtype: np.dtype | None = None) -> NDArray[np.float64]:\n return np.array([1.0, 2.0, 3.0])\n\n\nx13: ArrayLike = A()\n\nscalar: _SupportsArray[np.dtype[np.int64]] = np.int64(1)\nscalar.__array__()\narray: _SupportsArray[np.dtype[np.int_]] = np.array(1)\narray.__array__()\n\na: _SupportsArray[np.dtype[np.float64]] = A()\na.__array__()\na.__array__()\n\n# Escape hatch for when you mean to make something like an object\n# array.\nobject_array_scalar: object = (i for i in range(10))\nnp.array(object_array_scalar)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\array_like.py | array_like.py | Python | 1,075 | 0.95 | 0.116279 | 0.0625 | react-lib | 543 | 2025-06-27T01:25:04.360896 | Apache-2.0 | true | 6daffaa4bc0823ca38049cfb11e80c11 |
import numpy as np\n\ni8 = np.int64(1)\nu8 = np.uint64(1)\n\ni4 = np.int32(1)\nu4 = np.uint32(1)\n\nb_ = np.bool(1)\n\nb = bool(1)\ni = int(1)\n\nAR = np.array([0, 1, 2], dtype=np.int32)\nAR.setflags(write=False)\n\n\ni8 << i8\ni8 >> i8\ni8 | i8\ni8 ^ i8\ni8 & i8\n\ni << AR\ni >> AR\ni | AR\ni ^ AR\ni & AR\n\ni8 << AR\ni8 >> AR\ni8 | AR\ni8 ^ AR\ni8 & AR\n\ni4 << i4\ni4 >> i4\ni4 | i4\ni4 ^ i4\ni4 & i4\n\ni8 << i4\ni8 >> i4\ni8 | i4\ni8 ^ i4\ni8 & i4\n\ni8 << i\ni8 >> i\ni8 | i\ni8 ^ i\ni8 & i\n\ni8 << b_\ni8 >> b_\ni8 | b_\ni8 ^ b_\ni8 & b_\n\ni8 << b\ni8 >> b\ni8 | b\ni8 ^ b\ni8 & b\n\nu8 << u8\nu8 >> u8\nu8 | u8\nu8 ^ u8\nu8 & u8\n\nu4 << u4\nu4 >> u4\nu4 | u4\nu4 ^ u4\nu4 & u4\n\nu4 << i4\nu4 >> i4\nu4 | i4\nu4 ^ i4\nu4 & i4\n\nu4 << i\nu4 >> i\nu4 | i\nu4 ^ i\nu4 & i\n\nu8 << b_\nu8 >> b_\nu8 | b_\nu8 ^ b_\nu8 & b_\n\nu8 << b\nu8 >> b\nu8 | b\nu8 ^ b\nu8 & b\n\nb_ << b_\nb_ >> b_\nb_ | b_\nb_ ^ b_\nb_ & b_\n\nb_ << AR\nb_ >> AR\nb_ | AR\nb_ ^ AR\nb_ & AR\n\nb_ << b\nb_ >> b\nb_ | b\nb_ ^ b\nb_ & b\n\nb_ << i\nb_ >> i\nb_ | i\nb_ ^ i\nb_ & i\n\n~i8\n~i4\n~u8\n~u4\n~b_\n~AR\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\bitwise_ops.py | bitwise_ops.py | Python | 1,095 | 0.85 | 0 | 0 | python-kit | 720 | 2024-11-25T12:51:34.200925 | GPL-3.0 | true | 25bbed76270a1b34c60bc4f58419f090 |
from __future__ import annotations\n\nfrom typing import cast, Any\nimport numpy as np\n\nc16 = np.complex128()\nf8 = np.float64()\ni8 = np.int64()\nu8 = np.uint64()\n\nc8 = np.complex64()\nf4 = np.float32()\ni4 = np.int32()\nu4 = np.uint32()\n\ndt = np.datetime64(0, "D")\ntd = np.timedelta64(0, "D")\n\nb_ = np.bool()\n\nb = bool()\nc = complex()\nf = float()\ni = int()\n\nSEQ = (0, 1, 2, 3, 4)\n\nAR_b: np.ndarray[Any, np.dtype[np.bool]] = np.array([True])\nAR_u: np.ndarray[Any, np.dtype[np.uint32]] = np.array([1], dtype=np.uint32)\nAR_i: np.ndarray[Any, np.dtype[np.int_]] = np.array([1])\nAR_f: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0])\nAR_c: np.ndarray[Any, np.dtype[np.complex128]] = np.array([1.0j])\nAR_S: np.ndarray[Any, np.dtype[np.bytes_]] = np.array([b"a"], "S")\nAR_T = cast(np.ndarray[Any, np.dtypes.StringDType], np.array(["a"], "T"))\nAR_U: np.ndarray[Any, np.dtype[np.str_]] = np.array(["a"], "U")\nAR_m: np.ndarray[Any, np.dtype[np.timedelta64]] = np.array([np.timedelta64("1")])\nAR_M: np.ndarray[Any, np.dtype[np.datetime64]] = np.array([np.datetime64("1")])\nAR_O: np.ndarray[Any, np.dtype[np.object_]] = np.array([1], dtype=object)\n\n# Arrays\n\nAR_b > AR_b\nAR_b > AR_u\nAR_b > AR_i\nAR_b > AR_f\nAR_b > AR_c\n\nAR_u > AR_b\nAR_u > AR_u\nAR_u > AR_i\nAR_u > AR_f\nAR_u > AR_c\n\nAR_i > AR_b\nAR_i > AR_u\nAR_i > AR_i\nAR_i > AR_f\nAR_i > AR_c\n\nAR_f > AR_b\nAR_f > AR_u\nAR_f > AR_i\nAR_f > AR_f\nAR_f > AR_c\n\nAR_c > AR_b\nAR_c > AR_u\nAR_c > AR_i\nAR_c > AR_f\nAR_c > AR_c\n\nAR_S > AR_S\nAR_S > b""\n\nAR_T > AR_T\nAR_T > AR_U\nAR_T > ""\n\nAR_U > AR_U\nAR_U > AR_T\nAR_U > ""\n\nAR_m > AR_b\nAR_m > AR_u\nAR_m > AR_i\nAR_b > AR_m\nAR_u > AR_m\nAR_i > AR_m\n\nAR_M > AR_M\n\nAR_O > AR_O\n1 > AR_O\nAR_O > 1\n\n# Time structures\n\ndt > dt\n\ntd > td\ntd > i\ntd > i4\ntd > i8\ntd > AR_i\ntd > SEQ\n\n# boolean\n\nb_ > b\nb_ > b_\nb_ > i\nb_ > i8\nb_ > i4\nb_ > u8\nb_ > u4\nb_ > f\nb_ > f8\nb_ > f4\nb_ > c\nb_ > c16\nb_ > c8\nb_ > AR_i\nb_ > SEQ\n\n# Complex\n\nc16 > c16\nc16 > f8\nc16 > i8\nc16 > c8\nc16 > f4\nc16 > i4\nc16 > b_\nc16 > b\nc16 > c\nc16 > f\nc16 > i\nc16 > AR_i\nc16 > SEQ\n\nc16 > c16\nf8 > c16\ni8 > c16\nc8 > c16\nf4 > c16\ni4 > c16\nb_ > c16\nb > c16\nc > c16\nf > c16\ni > c16\nAR_i > c16\nSEQ > c16\n\nc8 > c16\nc8 > f8\nc8 > i8\nc8 > c8\nc8 > f4\nc8 > i4\nc8 > b_\nc8 > b\nc8 > c\nc8 > f\nc8 > i\nc8 > AR_i\nc8 > SEQ\n\nc16 > c8\nf8 > c8\ni8 > c8\nc8 > c8\nf4 > c8\ni4 > c8\nb_ > c8\nb > c8\nc > c8\nf > c8\ni > c8\nAR_i > c8\nSEQ > c8\n\n# Float\n\nf8 > f8\nf8 > i8\nf8 > f4\nf8 > i4\nf8 > b_\nf8 > b\nf8 > c\nf8 > f\nf8 > i\nf8 > AR_i\nf8 > SEQ\n\nf8 > f8\ni8 > f8\nf4 > f8\ni4 > f8\nb_ > f8\nb > f8\nc > f8\nf > f8\ni > f8\nAR_i > f8\nSEQ > f8\n\nf4 > f8\nf4 > i8\nf4 > f4\nf4 > i4\nf4 > b_\nf4 > b\nf4 > c\nf4 > f\nf4 > i\nf4 > AR_i\nf4 > SEQ\n\nf8 > f4\ni8 > f4\nf4 > f4\ni4 > f4\nb_ > f4\nb > f4\nc > f4\nf > f4\ni > f4\nAR_i > f4\nSEQ > f4\n\n# Int\n\ni8 > i8\ni8 > u8\ni8 > i4\ni8 > u4\ni8 > b_\ni8 > b\ni8 > c\ni8 > f\ni8 > i\ni8 > AR_i\ni8 > SEQ\n\nu8 > u8\nu8 > i4\nu8 > u4\nu8 > b_\nu8 > b\nu8 > c\nu8 > f\nu8 > i\nu8 > AR_i\nu8 > SEQ\n\ni8 > i8\nu8 > i8\ni4 > i8\nu4 > i8\nb_ > i8\nb > i8\nc > i8\nf > i8\ni > i8\nAR_i > i8\nSEQ > i8\n\nu8 > u8\ni4 > u8\nu4 > u8\nb_ > u8\nb > u8\nc > u8\nf > u8\ni > u8\nAR_i > u8\nSEQ > u8\n\ni4 > i8\ni4 > i4\ni4 > i\ni4 > b_\ni4 > b\ni4 > AR_i\ni4 > SEQ\n\nu4 > i8\nu4 > i4\nu4 > u8\nu4 > u4\nu4 > i\nu4 > b_\nu4 > b\nu4 > AR_i\nu4 > SEQ\n\ni8 > i4\ni4 > i4\ni > i4\nb_ > i4\nb > i4\nAR_i > i4\nSEQ > i4\n\ni8 > u4\ni4 > u4\nu8 > u4\nu4 > u4\nb_ > u4\nb > u4\ni > u4\nAR_i > u4\nSEQ > u4\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\comparisons.py | comparisons.py | Python | 3,613 | 0.95 | 0 | 0.02214 | vue-tools | 515 | 2024-02-27T12:11:24.519756 | MIT | true | 92b0cc528a723d72930fa1c56c3f497a |
import numpy as np\n\ndtype_obj = np.dtype(np.str_)\nvoid_dtype_obj = np.dtype([("f0", np.float64), ("f1", np.float32)])\n\nnp.dtype(dtype=np.int64)\nnp.dtype(int)\nnp.dtype("int")\nnp.dtype(None)\n\nnp.dtype((int, 2))\nnp.dtype((int, (1,)))\n\nnp.dtype({"names": ["a", "b"], "formats": [int, float]})\nnp.dtype({"names": ["a"], "formats": [int], "titles": [object]})\nnp.dtype({"names": ["a"], "formats": [int], "titles": [object()]})\n\nnp.dtype([("name", np.str_, 16), ("grades", np.float64, (2,)), ("age", "int32")])\n\nnp.dtype(\n {\n "names": ["a", "b"],\n "formats": [int, float],\n "itemsize": 9,\n "aligned": False,\n "titles": ["x", "y"],\n "offsets": [0, 1],\n }\n)\n\nnp.dtype((np.float64, float))\n\n\nclass Test:\n dtype = np.dtype(float)\n\n\nnp.dtype(Test())\n\n# Methods and attributes\ndtype_obj.base\ndtype_obj.subdtype\ndtype_obj.newbyteorder()\ndtype_obj.type\ndtype_obj.name\ndtype_obj.names\n\ndtype_obj * 0\ndtype_obj * 2\n\n0 * dtype_obj\n2 * dtype_obj\n\nvoid_dtype_obj["f0"]\nvoid_dtype_obj[0]\nvoid_dtype_obj[["f0", "f1"]]\nvoid_dtype_obj[["f0"]]\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\dtype.py | dtype.py | Python | 1,127 | 0.95 | 0.017544 | 0.02381 | python-kit | 838 | 2023-12-21T13:26:17.252245 | BSD-3-Clause | true | ff16632537603afb375dfaa1bc9c749d |
from __future__ import annotations\n\nfrom typing import Any\n\nimport numpy as np\n\nAR_LIKE_b = [True, True, True]\nAR_LIKE_u = [np.uint32(1), np.uint32(2), np.uint32(3)]\nAR_LIKE_i = [1, 2, 3]\nAR_LIKE_f = [1.0, 2.0, 3.0]\nAR_LIKE_c = [1j, 2j, 3j]\nAR_LIKE_U = ["1", "2", "3"]\n\nOUT_f: np.ndarray[Any, np.dtype[np.float64]] = np.empty(3, dtype=np.float64)\nOUT_c: np.ndarray[Any, np.dtype[np.complex128]] = np.empty(3, dtype=np.complex128)\n\nnp.einsum("i,i->i", AR_LIKE_b, AR_LIKE_b)\nnp.einsum("i,i->i", AR_LIKE_u, AR_LIKE_u)\nnp.einsum("i,i->i", AR_LIKE_i, AR_LIKE_i)\nnp.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f)\nnp.einsum("i,i->i", AR_LIKE_c, AR_LIKE_c)\nnp.einsum("i,i->i", AR_LIKE_b, AR_LIKE_i)\nnp.einsum("i,i,i,i->i", AR_LIKE_b, AR_LIKE_u, AR_LIKE_i, AR_LIKE_c)\n\nnp.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f, dtype="c16")\nnp.einsum("i,i->i", AR_LIKE_U, AR_LIKE_U, dtype=bool, casting="unsafe")\nnp.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f, out=OUT_c)\nnp.einsum("i,i->i", AR_LIKE_U, AR_LIKE_U, dtype=int, casting="unsafe", out=OUT_f)\n\nnp.einsum_path("i,i->i", AR_LIKE_b, AR_LIKE_b)\nnp.einsum_path("i,i->i", AR_LIKE_u, AR_LIKE_u)\nnp.einsum_path("i,i->i", AR_LIKE_i, AR_LIKE_i)\nnp.einsum_path("i,i->i", AR_LIKE_f, AR_LIKE_f)\nnp.einsum_path("i,i->i", AR_LIKE_c, AR_LIKE_c)\nnp.einsum_path("i,i->i", AR_LIKE_b, AR_LIKE_i)\nnp.einsum_path("i,i,i,i->i", AR_LIKE_b, AR_LIKE_u, AR_LIKE_i, AR_LIKE_c)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\einsumfunc.py | einsumfunc.py | Python | 1,406 | 0.85 | 0 | 0 | node-utils | 405 | 2024-02-24T08:06:46.995513 | Apache-2.0 | true | f57b3282f11a865b4586a75a80bdf0f6 |
import numpy as np\n\na = np.empty((2, 2)).flat\n\na.base\na.copy()\na.coords\na.index\niter(a)\nnext(a)\na[0]\na[[0, 1, 2]]\na[...]\na[:]\na.__array__()\na.__array__(np.dtype(np.float64))\n\nb = np.array([1]).flat\na[b]\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\flatiter.py | flatiter.py | Python | 222 | 0.85 | 0 | 0 | python-kit | 864 | 2024-12-27T14:08:51.989150 | Apache-2.0 | true | 176e2bccc7f766a1a1ed035e7f2b1fd4 |
"""Tests for :mod:`numpy._core.fromnumeric`."""\n\nimport numpy as np\n\nA = np.array(True, ndmin=2, dtype=bool)\nB = np.array(1.0, ndmin=2, dtype=np.float32)\nA.setflags(write=False)\nB.setflags(write=False)\n\na = np.bool(True)\nb = np.float32(1.0)\nc = 1.0\nd = np.array(1.0, dtype=np.float32) # writeable\n\nnp.take(a, 0)\nnp.take(b, 0)\nnp.take(c, 0)\nnp.take(A, 0)\nnp.take(B, 0)\nnp.take(A, [0])\nnp.take(B, [0])\n\nnp.reshape(a, 1)\nnp.reshape(b, 1)\nnp.reshape(c, 1)\nnp.reshape(A, 1)\nnp.reshape(B, 1)\n\nnp.choose(a, [True, True])\nnp.choose(A, [1.0, 1.0])\n\nnp.repeat(a, 1)\nnp.repeat(b, 1)\nnp.repeat(c, 1)\nnp.repeat(A, 1)\nnp.repeat(B, 1)\n\nnp.swapaxes(A, 0, 0)\nnp.swapaxes(B, 0, 0)\n\nnp.transpose(a)\nnp.transpose(b)\nnp.transpose(c)\nnp.transpose(A)\nnp.transpose(B)\n\nnp.partition(a, 0, axis=None)\nnp.partition(b, 0, axis=None)\nnp.partition(c, 0, axis=None)\nnp.partition(A, 0)\nnp.partition(B, 0)\n\nnp.argpartition(a, 0)\nnp.argpartition(b, 0)\nnp.argpartition(c, 0)\nnp.argpartition(A, 0)\nnp.argpartition(B, 0)\n\nnp.sort(A, 0)\nnp.sort(B, 0)\n\nnp.argsort(A, 0)\nnp.argsort(B, 0)\n\nnp.argmax(A)\nnp.argmax(B)\nnp.argmax(A, axis=0)\nnp.argmax(B, axis=0)\n\nnp.argmin(A)\nnp.argmin(B)\nnp.argmin(A, axis=0)\nnp.argmin(B, axis=0)\n\nnp.searchsorted(A[0], 0)\nnp.searchsorted(B[0], 0)\nnp.searchsorted(A[0], [0])\nnp.searchsorted(B[0], [0])\n\nnp.resize(a, (5, 5))\nnp.resize(b, (5, 5))\nnp.resize(c, (5, 5))\nnp.resize(A, (5, 5))\nnp.resize(B, (5, 5))\n\nnp.squeeze(a)\nnp.squeeze(b)\nnp.squeeze(c)\nnp.squeeze(A)\nnp.squeeze(B)\n\nnp.diagonal(A)\nnp.diagonal(B)\n\nnp.trace(A)\nnp.trace(B)\n\nnp.ravel(a)\nnp.ravel(b)\nnp.ravel(c)\nnp.ravel(A)\nnp.ravel(B)\n\nnp.nonzero(A)\nnp.nonzero(B)\n\nnp.shape(a)\nnp.shape(b)\nnp.shape(c)\nnp.shape(A)\nnp.shape(B)\n\nnp.compress([True], a)\nnp.compress([True], b)\nnp.compress([True], c)\nnp.compress([True], A)\nnp.compress([True], B)\n\nnp.clip(a, 0, 1.0)\nnp.clip(b, -1, 1)\nnp.clip(a, 0, None)\nnp.clip(b, None, 1)\nnp.clip(c, 0, 1)\nnp.clip(A, 0, 1)\nnp.clip(B, 0, 1)\nnp.clip(B, [0, 1], [1, 2])\n\nnp.sum(a)\nnp.sum(b)\nnp.sum(c)\nnp.sum(A)\nnp.sum(B)\nnp.sum(A, axis=0)\nnp.sum(B, axis=0)\n\nnp.all(a)\nnp.all(b)\nnp.all(c)\nnp.all(A)\nnp.all(B)\nnp.all(A, axis=0)\nnp.all(B, axis=0)\nnp.all(A, keepdims=True)\nnp.all(B, keepdims=True)\n\nnp.any(a)\nnp.any(b)\nnp.any(c)\nnp.any(A)\nnp.any(B)\nnp.any(A, axis=0)\nnp.any(B, axis=0)\nnp.any(A, keepdims=True)\nnp.any(B, keepdims=True)\n\nnp.cumsum(a)\nnp.cumsum(b)\nnp.cumsum(c)\nnp.cumsum(A)\nnp.cumsum(B)\n\nnp.cumulative_sum(a)\nnp.cumulative_sum(b)\nnp.cumulative_sum(c)\nnp.cumulative_sum(A, axis=0)\nnp.cumulative_sum(B, axis=0)\n\nnp.ptp(b)\nnp.ptp(c)\nnp.ptp(B)\nnp.ptp(B, axis=0)\nnp.ptp(B, keepdims=True)\n\nnp.amax(a)\nnp.amax(b)\nnp.amax(c)\nnp.amax(A)\nnp.amax(B)\nnp.amax(A, axis=0)\nnp.amax(B, axis=0)\nnp.amax(A, keepdims=True)\nnp.amax(B, keepdims=True)\n\nnp.amin(a)\nnp.amin(b)\nnp.amin(c)\nnp.amin(A)\nnp.amin(B)\nnp.amin(A, axis=0)\nnp.amin(B, axis=0)\nnp.amin(A, keepdims=True)\nnp.amin(B, keepdims=True)\n\nnp.prod(a)\nnp.prod(b)\nnp.prod(c)\nnp.prod(A)\nnp.prod(B)\nnp.prod(a, dtype=None)\nnp.prod(A, dtype=None)\nnp.prod(A, axis=0)\nnp.prod(B, axis=0)\nnp.prod(A, keepdims=True)\nnp.prod(B, keepdims=True)\nnp.prod(b, out=d)\nnp.prod(B, out=d)\n\nnp.cumprod(a)\nnp.cumprod(b)\nnp.cumprod(c)\nnp.cumprod(A)\nnp.cumprod(B)\n\nnp.cumulative_prod(a)\nnp.cumulative_prod(b)\nnp.cumulative_prod(c)\nnp.cumulative_prod(A, axis=0)\nnp.cumulative_prod(B, axis=0)\n\nnp.ndim(a)\nnp.ndim(b)\nnp.ndim(c)\nnp.ndim(A)\nnp.ndim(B)\n\nnp.size(a)\nnp.size(b)\nnp.size(c)\nnp.size(A)\nnp.size(B)\n\nnp.around(a)\nnp.around(b)\nnp.around(c)\nnp.around(A)\nnp.around(B)\n\nnp.mean(a)\nnp.mean(b)\nnp.mean(c)\nnp.mean(A)\nnp.mean(B)\nnp.mean(A, axis=0)\nnp.mean(B, axis=0)\nnp.mean(A, keepdims=True)\nnp.mean(B, keepdims=True)\nnp.mean(b, out=d)\nnp.mean(B, out=d)\n\nnp.std(a)\nnp.std(b)\nnp.std(c)\nnp.std(A)\nnp.std(B)\nnp.std(A, axis=0)\nnp.std(B, axis=0)\nnp.std(A, keepdims=True)\nnp.std(B, keepdims=True)\nnp.std(b, out=d)\nnp.std(B, out=d)\n\nnp.var(a)\nnp.var(b)\nnp.var(c)\nnp.var(A)\nnp.var(B)\nnp.var(A, axis=0)\nnp.var(B, axis=0)\nnp.var(A, keepdims=True)\nnp.var(B, keepdims=True)\nnp.var(b, out=d)\nnp.var(B, out=d)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\fromnumeric.py | fromnumeric.py | Python | 4,263 | 0.95 | 0.003676 | 0 | python-kit | 700 | 2025-06-23T15:33:43.453733 | Apache-2.0 | true | 254d917fd7c8f61addfab7e35e40db31 |
from __future__ import annotations\nfrom typing import Any\nimport numpy as np\n\nAR_LIKE_b = [[True, True], [True, True]]\nAR_LIKE_i = [[1, 2], [3, 4]]\nAR_LIKE_f = [[1.0, 2.0], [3.0, 4.0]]\nAR_LIKE_U = [["1", "2"], ["3", "4"]]\n\nAR_i8: np.ndarray[Any, np.dtype[np.int64]] = np.array(AR_LIKE_i, dtype=np.int64)\n\nnp.ndenumerate(AR_i8)\nnp.ndenumerate(AR_LIKE_f)\nnp.ndenumerate(AR_LIKE_U)\n\nnext(np.ndenumerate(AR_i8))\nnext(np.ndenumerate(AR_LIKE_f))\nnext(np.ndenumerate(AR_LIKE_U))\n\niter(np.ndenumerate(AR_i8))\niter(np.ndenumerate(AR_LIKE_f))\niter(np.ndenumerate(AR_LIKE_U))\n\niter(np.ndindex(1, 2, 3))\nnext(np.ndindex(1, 2, 3))\n\nnp.unravel_index([22, 41, 37], (7, 6))\nnp.unravel_index([31, 41, 13], (7, 6), order='F')\nnp.unravel_index(1621, (6, 7, 8, 9))\n\nnp.ravel_multi_index(AR_LIKE_i, (7, 6))\nnp.ravel_multi_index(AR_LIKE_i, (7, 6), order='F')\nnp.ravel_multi_index(AR_LIKE_i, (4, 6), mode='clip')\nnp.ravel_multi_index(AR_LIKE_i, (4, 4), mode=('clip', 'wrap'))\nnp.ravel_multi_index((3, 1, 4, 1), (6, 7, 8, 9))\n\nnp.mgrid[1:1:2]\nnp.mgrid[1:1:2, None:10]\n\nnp.ogrid[1:1:2]\nnp.ogrid[1:1:2, None:10]\n\nnp.index_exp[0:1]\nnp.index_exp[0:1, None:3]\nnp.index_exp[0, 0:1, ..., [0, 1, 3]]\n\nnp.s_[0:1]\nnp.s_[0:1, None:3]\nnp.s_[0, 0:1, ..., [0, 1, 3]]\n\nnp.ix_(AR_LIKE_b[0])\nnp.ix_(AR_LIKE_i[0], AR_LIKE_f[0])\nnp.ix_(AR_i8[0])\n\nnp.fill_diagonal(AR_i8, 5)\n\nnp.diag_indices(4)\nnp.diag_indices(2, 3)\n\nnp.diag_indices_from(AR_i8)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\index_tricks.py | index_tricks.py | Python | 1,462 | 0.85 | 0 | 0 | vue-tools | 784 | 2024-10-22T05:19:49.806703 | MIT | true | aa6a71859a07e50cf4bb1560e2150552 |
"""Based on the `if __name__ == "__main__"` test code in `lib/_user_array_impl.py`."""\n\nfrom __future__ import annotations\n\nimport numpy as np\nfrom numpy.lib.user_array import container\n\nN = 10_000\nW = H = int(N**0.5)\n\na: np.ndarray[tuple[int, int], np.dtype[np.int32]]\nua: container[tuple[int, int], np.dtype[np.int32]]\n\na = np.arange(N, dtype=np.int32).reshape(W, H)\nua = container(a)\n\nua_small: container[tuple[int, int], np.dtype[np.int32]] = ua[:3, :5]\nua_small[0, 0] = 10\n\nua_bool: container[tuple[int, int], np.dtype[np.bool]] = ua_small > 1\n\n# shape: tuple[int, int] = np.shape(ua)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\lib_user_array.py | lib_user_array.py | Python | 612 | 0.95 | 0.045455 | 0.071429 | react-lib | 355 | 2025-05-01T10:35:54.188031 | BSD-3-Clause | true | 7b6a6364e08991b5b40fc591fbd05ddf |
from __future__ import annotations\n\nfrom io import StringIO\n\nimport numpy as np\nimport numpy.lib.array_utils as array_utils\n\nFILE = StringIO()\nAR = np.arange(10, dtype=np.float64)\n\n\ndef func(a: int) -> bool:\n return True\n\n\narray_utils.byte_bounds(AR)\narray_utils.byte_bounds(np.float64())\n\nnp.info(1, output=FILE)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\lib_utils.py | lib_utils.py | Python | 336 | 0.85 | 0.052632 | 0 | react-lib | 138 | 2025-04-18T19:37:09.460637 | Apache-2.0 | true | 67f00f52373d0722b98e93deda59c6c9 |
from numpy.lib import NumpyVersion\n\nversion = NumpyVersion("1.8.0")\n\nversion.vstring\nversion.version\nversion.major\nversion.minor\nversion.bugfix\nversion.pre_release\nversion.is_devversion\n\nversion == version\nversion != version\nversion < "1.8.0"\nversion <= version\nversion > version\nversion >= "1.8.0"\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\lib_version.py | lib_version.py | Python | 317 | 0.85 | 0 | 0 | vue-tools | 564 | 2023-10-24T12:55:05.374228 | MIT | true | 2ece33de474ef57a775b66932783f8e9 |
from __future__ import annotations\n\nfrom typing import Any, TYPE_CHECKING\nfrom functools import partial\n\nimport pytest\nimport numpy as np\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\nAR = np.array(0)\nAR.setflags(write=False)\n\nKACF = frozenset({None, "K", "A", "C", "F"})\nACF = frozenset({None, "A", "C", "F"})\nCF = frozenset({None, "C", "F"})\n\norder_list: list[tuple[frozenset[str | None], Callable[..., Any]]] = [\n (KACF, AR.tobytes),\n (KACF, partial(AR.astype, int)),\n (KACF, AR.copy),\n (ACF, partial(AR.reshape, 1)),\n (KACF, AR.flatten),\n (KACF, AR.ravel),\n (KACF, partial(np.array, 1)),\n # NOTE: __call__ is needed due to mypy bugs (#17620, #17631)\n (KACF, partial(np.ndarray.__call__, 1)),\n (CF, partial(np.zeros.__call__, 1)),\n (CF, partial(np.ones.__call__, 1)),\n (CF, partial(np.empty.__call__, 1)),\n (CF, partial(np.full, 1, 1)),\n (KACF, partial(np.zeros_like, AR)),\n (KACF, partial(np.ones_like, AR)),\n (KACF, partial(np.empty_like, AR)),\n (KACF, partial(np.full_like, AR, 1)),\n (KACF, partial(np.add.__call__, 1, 1)), # i.e. np.ufunc.__call__\n (ACF, partial(np.reshape, AR, 1)),\n (KACF, partial(np.ravel, AR)),\n (KACF, partial(np.asarray, 1)),\n (KACF, partial(np.asanyarray, 1)),\n]\n\nfor order_set, func in order_list:\n for order in order_set:\n func(order=order)\n\n invalid_orders = KACF - order_set\n for order in invalid_orders:\n with pytest.raises(ValueError):\n func(order=order)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\literal.py | literal.py | Python | 1,559 | 0.95 | 0.078431 | 0.023256 | node-utils | 868 | 2025-04-06T11:47:11.951738 | GPL-3.0 | true | d0280b9b1c320814dc6dea7c1bad8529 |
from typing import Any, TypeAlias, TypeVar, cast\n\nimport numpy as np\nimport numpy.typing as npt\nfrom numpy._typing import _Shape\n\n_ScalarT = TypeVar("_ScalarT", bound=np.generic)\nMaskedArray: TypeAlias = np.ma.MaskedArray[_Shape, np.dtype[_ScalarT]]\n\nMAR_b: MaskedArray[np.bool] = np.ma.MaskedArray([True])\nMAR_u: MaskedArray[np.uint32] = np.ma.MaskedArray([1], dtype=np.uint32)\nMAR_i: MaskedArray[np.int64] = np.ma.MaskedArray([1])\nMAR_f: MaskedArray[np.float64] = np.ma.MaskedArray([1.0])\nMAR_c: MaskedArray[np.complex128] = np.ma.MaskedArray([1j])\nMAR_td64: MaskedArray[np.timedelta64] = np.ma.MaskedArray([np.timedelta64(1, "D")])\nMAR_M_dt64: MaskedArray[np.datetime64] = np.ma.MaskedArray([np.datetime64(1, "D")])\nMAR_S: MaskedArray[np.bytes_] = np.ma.MaskedArray([b'foo'], dtype=np.bytes_)\nMAR_U: MaskedArray[np.str_] = np.ma.MaskedArray(['foo'], dtype=np.str_)\nMAR_T = cast(np.ma.MaskedArray[Any, np.dtypes.StringDType],\n np.ma.MaskedArray(["a"], dtype="T"))\n\nAR_b: npt.NDArray[np.bool] = np.array([True, False, True])\n\nAR_LIKE_b = [True]\nAR_LIKE_u = [np.uint32(1)]\nAR_LIKE_i = [1]\nAR_LIKE_f = [1.0]\nAR_LIKE_c = [1j]\nAR_LIKE_m = [np.timedelta64(1, "D")]\nAR_LIKE_M = [np.datetime64(1, "D")]\n\nMAR_f.mask = AR_b\nMAR_f.mask = np.False_\n\n# Inplace addition\n\nMAR_b += AR_LIKE_b\n\nMAR_u += AR_LIKE_b\nMAR_u += AR_LIKE_u\n\nMAR_i += AR_LIKE_b\nMAR_i += 2\nMAR_i += AR_LIKE_i\n\nMAR_f += AR_LIKE_b\nMAR_f += 2\nMAR_f += AR_LIKE_u\nMAR_f += AR_LIKE_i\nMAR_f += AR_LIKE_f\n\nMAR_c += AR_LIKE_b\nMAR_c += AR_LIKE_u\nMAR_c += AR_LIKE_i\nMAR_c += AR_LIKE_f\nMAR_c += AR_LIKE_c\n\nMAR_td64 += AR_LIKE_b\nMAR_td64 += AR_LIKE_u\nMAR_td64 += AR_LIKE_i\nMAR_td64 += AR_LIKE_m\nMAR_M_dt64 += AR_LIKE_b\nMAR_M_dt64 += AR_LIKE_u\nMAR_M_dt64 += AR_LIKE_i\nMAR_M_dt64 += AR_LIKE_m\n\nMAR_S += b'snakes'\nMAR_U += 'snakes'\nMAR_T += 'snakes'\n\n# Inplace subtraction\n\nMAR_u -= AR_LIKE_b\nMAR_u -= AR_LIKE_u\n\nMAR_i -= AR_LIKE_b\nMAR_i -= AR_LIKE_i\n\nMAR_f -= AR_LIKE_b\nMAR_f -= AR_LIKE_u\nMAR_f -= AR_LIKE_i\nMAR_f -= AR_LIKE_f\n\nMAR_c -= AR_LIKE_b\nMAR_c -= AR_LIKE_u\nMAR_c -= AR_LIKE_i\nMAR_c -= AR_LIKE_f\nMAR_c -= AR_LIKE_c\n\nMAR_td64 -= AR_LIKE_b\nMAR_td64 -= AR_LIKE_u\nMAR_td64 -= AR_LIKE_i\nMAR_td64 -= AR_LIKE_m\nMAR_M_dt64 -= AR_LIKE_b\nMAR_M_dt64 -= AR_LIKE_u\nMAR_M_dt64 -= AR_LIKE_i\nMAR_M_dt64 -= AR_LIKE_m\n\n# Inplace floor division\n\nMAR_f //= AR_LIKE_b\nMAR_f //= 2\nMAR_f //= AR_LIKE_u\nMAR_f //= AR_LIKE_i\nMAR_f //= AR_LIKE_f\n\nMAR_td64 //= AR_LIKE_i\n\n# Inplace true division\n\nMAR_f /= AR_LIKE_b\nMAR_f /= 2\nMAR_f /= AR_LIKE_u\nMAR_f /= AR_LIKE_i\nMAR_f /= AR_LIKE_f\n\nMAR_c /= AR_LIKE_b\nMAR_c /= AR_LIKE_u\nMAR_c /= AR_LIKE_i\nMAR_c /= AR_LIKE_f\nMAR_c /= AR_LIKE_c\n\nMAR_td64 /= AR_LIKE_i\n\n# Inplace multiplication\n\nMAR_b *= AR_LIKE_b\n\nMAR_u *= AR_LIKE_b\nMAR_u *= AR_LIKE_u\n\nMAR_i *= AR_LIKE_b\nMAR_i *= 2\nMAR_i *= AR_LIKE_i\n\nMAR_f *= AR_LIKE_b\nMAR_f *= 2\nMAR_f *= AR_LIKE_u\nMAR_f *= AR_LIKE_i\nMAR_f *= AR_LIKE_f\n\nMAR_c *= AR_LIKE_b\nMAR_c *= AR_LIKE_u\nMAR_c *= AR_LIKE_i\nMAR_c *= AR_LIKE_f\nMAR_c *= AR_LIKE_c\n\nMAR_td64 *= AR_LIKE_b\nMAR_td64 *= AR_LIKE_u\nMAR_td64 *= AR_LIKE_i\nMAR_td64 *= AR_LIKE_f\n\nMAR_S *= 2\nMAR_U *= 2\nMAR_T *= 2\n\n# Inplace power\n\nMAR_u **= AR_LIKE_b\nMAR_u **= AR_LIKE_u\n\nMAR_i **= AR_LIKE_b\nMAR_i **= AR_LIKE_i\n\nMAR_f **= AR_LIKE_b\nMAR_f **= AR_LIKE_u\nMAR_f **= AR_LIKE_i\nMAR_f **= AR_LIKE_f\n\nMAR_c **= AR_LIKE_b\nMAR_c **= AR_LIKE_u\nMAR_c **= AR_LIKE_i\nMAR_c **= AR_LIKE_f\nMAR_c **= AR_LIKE_c\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\ma.py | ma.py | Python | 3,536 | 0.95 | 0 | 0.044776 | awesome-app | 202 | 2024-04-21T00:35:06.865727 | Apache-2.0 | true | 2cc6acbfa37f71215f08bacc06b3ce32 |
import numpy as np\n\nf8 = np.float64(1)\ni8 = np.int64(1)\nu8 = np.uint64(1)\n\nf4 = np.float32(1)\ni4 = np.int32(1)\nu4 = np.uint32(1)\n\ntd = np.timedelta64(1, "D")\nb_ = np.bool(1)\n\nb = bool(1)\nf = float(1)\ni = int(1)\n\nAR = np.array([1], dtype=np.bool)\nAR.setflags(write=False)\n\nAR2 = np.array([1], dtype=np.timedelta64)\nAR2.setflags(write=False)\n\n# Time structures\n\ntd % td\ntd % AR2\nAR2 % td\n\ndivmod(td, td)\ndivmod(td, AR2)\ndivmod(AR2, td)\n\n# Bool\n\nb_ % b\nb_ % i\nb_ % f\nb_ % b_\nb_ % i8\nb_ % u8\nb_ % f8\nb_ % AR\n\ndivmod(b_, b)\ndivmod(b_, i)\ndivmod(b_, f)\ndivmod(b_, b_)\ndivmod(b_, i8)\ndivmod(b_, u8)\ndivmod(b_, f8)\ndivmod(b_, AR)\n\nb % b_\ni % b_\nf % b_\nb_ % b_\ni8 % b_\nu8 % b_\nf8 % b_\nAR % b_\n\ndivmod(b, b_)\ndivmod(i, b_)\ndivmod(f, b_)\ndivmod(b_, b_)\ndivmod(i8, b_)\ndivmod(u8, b_)\ndivmod(f8, b_)\ndivmod(AR, b_)\n\n# int\n\ni8 % b\ni8 % i\ni8 % f\ni8 % i8\ni8 % f8\ni4 % i8\ni4 % f8\ni4 % i4\ni4 % f4\ni8 % AR\n\ndivmod(i8, b)\ndivmod(i8, i)\ndivmod(i8, f)\ndivmod(i8, i8)\ndivmod(i8, f8)\ndivmod(i8, i4)\ndivmod(i8, f4)\ndivmod(i4, i4)\ndivmod(i4, f4)\ndivmod(i8, AR)\n\nb % i8\ni % i8\nf % i8\ni8 % i8\nf8 % i8\ni8 % i4\nf8 % i4\ni4 % i4\nf4 % i4\nAR % i8\n\ndivmod(b, i8)\ndivmod(i, i8)\ndivmod(f, i8)\ndivmod(i8, i8)\ndivmod(f8, i8)\ndivmod(i4, i8)\ndivmod(f4, i8)\ndivmod(i4, i4)\ndivmod(f4, i4)\ndivmod(AR, i8)\n\n# float\n\nf8 % b\nf8 % i\nf8 % f\ni8 % f4\nf4 % f4\nf8 % AR\n\ndivmod(f8, b)\ndivmod(f8, i)\ndivmod(f8, f)\ndivmod(f8, f8)\ndivmod(f8, f4)\ndivmod(f4, f4)\ndivmod(f8, AR)\n\nb % f8\ni % f8\nf % f8\nf8 % f8\nf8 % f8\nf4 % f4\nAR % f8\n\ndivmod(b, f8)\ndivmod(i, f8)\ndivmod(f, f8)\ndivmod(f8, f8)\ndivmod(f4, f8)\ndivmod(f4, f4)\ndivmod(AR, f8)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\mod.py | mod.py | Python | 1,725 | 0.95 | 0 | 0.032 | awesome-app | 356 | 2024-05-12T03:45:24.223580 | BSD-3-Clause | true | 8d5b00dc98b62f11fc9624c94924735d |
import numpy as np\nfrom numpy import f2py\n\nnp.char\nnp.ctypeslib\nnp.emath\nnp.fft\nnp.lib\nnp.linalg\nnp.ma\nnp.matrixlib\nnp.polynomial\nnp.random\nnp.rec\nnp.strings\nnp.testing\nnp.version\n\nnp.lib.format\nnp.lib.mixins\nnp.lib.scimath\nnp.lib.stride_tricks\nnp.lib.array_utils\nnp.ma.extras\nnp.polynomial.chebyshev\nnp.polynomial.hermite\nnp.polynomial.hermite_e\nnp.polynomial.laguerre\nnp.polynomial.legendre\nnp.polynomial.polynomial\n\nnp.__path__\nnp.__version__\n\nnp.__all__\nnp.char.__all__\nnp.ctypeslib.__all__\nnp.emath.__all__\nnp.lib.__all__\nnp.ma.__all__\nnp.random.__all__\nnp.rec.__all__\nnp.strings.__all__\nnp.testing.__all__\nf2py.__all__\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\modules.py | modules.py | Python | 670 | 0.85 | 0 | 0 | vue-tools | 10 | 2024-11-12T09:16:56.441187 | GPL-3.0 | true | fd398c512035239012b5fd457739c163 |
import numpy as np\nimport numpy.typing as npt\n\nAR_f8: npt.NDArray[np.float64] = np.array([1.0])\nAR_i4 = np.array([1], dtype=np.int32)\nAR_u1 = np.array([1], dtype=np.uint8)\n\nAR_LIKE_f = [1.5]\nAR_LIKE_i = [1]\n\nb_f8 = np.broadcast(AR_f8)\nb_i4_f8_f8 = np.broadcast(AR_i4, AR_f8, AR_f8)\n\nnext(b_f8)\nb_f8.reset()\nb_f8.index\nb_f8.iters\nb_f8.nd\nb_f8.ndim\nb_f8.numiter\nb_f8.shape\nb_f8.size\n\nnext(b_i4_f8_f8)\nb_i4_f8_f8.reset()\nb_i4_f8_f8.ndim\nb_i4_f8_f8.index\nb_i4_f8_f8.iters\nb_i4_f8_f8.nd\nb_i4_f8_f8.numiter\nb_i4_f8_f8.shape\nb_i4_f8_f8.size\n\nnp.inner(AR_f8, AR_i4)\n\nnp.where([True, True, False])\nnp.where([True, True, False], 1, 0)\n\nnp.lexsort([0, 1, 2])\n\nnp.can_cast(np.dtype("i8"), int)\nnp.can_cast(AR_f8, "f8")\nnp.can_cast(AR_f8, np.complex128, casting="unsafe")\n\nnp.min_scalar_type([1])\nnp.min_scalar_type(AR_f8)\n\nnp.result_type(int, AR_i4)\nnp.result_type(AR_f8, AR_u1)\nnp.result_type(AR_f8, np.complex128)\n\nnp.dot(AR_LIKE_f, AR_i4)\nnp.dot(AR_u1, 1)\nnp.dot(1.5j, 1)\nnp.dot(AR_u1, 1, out=AR_f8)\n\nnp.vdot(AR_LIKE_f, AR_i4)\nnp.vdot(AR_u1, 1)\nnp.vdot(1.5j, 1)\n\nnp.bincount(AR_i4)\n\nnp.copyto(AR_f8, [1.6])\n\nnp.putmask(AR_f8, [True], 1.5)\n\nnp.packbits(AR_i4)\nnp.packbits(AR_u1)\n\nnp.unpackbits(AR_u1)\n\nnp.shares_memory(1, 2)\nnp.shares_memory(AR_f8, AR_f8, max_work=1)\n\nnp.may_share_memory(1, 2)\nnp.may_share_memory(AR_f8, AR_f8, max_work=1)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\multiarray.py | multiarray.py | Python | 1,407 | 0.85 | 0 | 0 | react-lib | 236 | 2024-05-10T13:40:40.909190 | Apache-2.0 | true | 321eb3c11b4ed87aae5f47640077dd89 |
import os\nimport tempfile\n\nimport numpy as np\n\nnd = np.array([[1, 2], [3, 4]])\nscalar_array = np.array(1)\n\n# item\nscalar_array.item()\nnd.item(1)\nnd.item(0, 1)\nnd.item((0, 1))\n\n# tobytes\nnd.tobytes()\nnd.tobytes("C")\nnd.tobytes(None)\n\n# tofile\nif os.name != "nt":\n with tempfile.NamedTemporaryFile(suffix=".txt") as tmp:\n nd.tofile(tmp.name)\n nd.tofile(tmp.name, "")\n nd.tofile(tmp.name, sep="")\n\n nd.tofile(tmp.name, "", "%s")\n nd.tofile(tmp.name, format="%s")\n\n nd.tofile(tmp)\n\n# dump is pretty simple\n# dumps is pretty simple\n\n# astype\nnd.astype("float")\nnd.astype(float)\n\nnd.astype(float, "K")\nnd.astype(float, order="K")\n\nnd.astype(float, "K", "unsafe")\nnd.astype(float, casting="unsafe")\n\nnd.astype(float, "K", "unsafe", True)\nnd.astype(float, subok=True)\n\nnd.astype(float, "K", "unsafe", True, True)\nnd.astype(float, copy=True)\n\n# byteswap\nnd.byteswap()\nnd.byteswap(True)\n\n# copy\nnd.copy()\nnd.copy("C")\n\n# view\nnd.view()\nnd.view(np.int64)\nnd.view(dtype=np.int64)\nnd.view(np.int64, np.matrix)\nnd.view(type=np.matrix)\n\n# getfield\ncomplex_array = np.array([[1 + 1j, 0], [0, 1 - 1j]], dtype=np.complex128)\n\ncomplex_array.getfield("float")\ncomplex_array.getfield(float)\n\ncomplex_array.getfield("float", 8)\ncomplex_array.getfield(float, offset=8)\n\n# setflags\nnd.setflags()\n\nnd.setflags(True)\nnd.setflags(write=True)\n\nnd.setflags(True, True)\nnd.setflags(write=True, align=True)\n\nnd.setflags(True, True, False)\nnd.setflags(write=True, align=True, uic=False)\n\n# fill is pretty simple\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\ndarray_conversion.py | ndarray_conversion.py | Python | 1,612 | 0.95 | 0.011494 | 0.190476 | node-utils | 680 | 2024-06-13T02:10:16.632216 | GPL-3.0 | true | 7d9c0a65217515e34e49c42131c095ce |
"""\nTests for miscellaneous (non-magic) ``np.ndarray``/``np.generic`` methods.\n\nMore extensive tests are performed for the methods'\nfunction-based counterpart in `../from_numeric.py`.\n\n"""\n\nfrom __future__ import annotations\n\nimport operator\nfrom typing import cast, Any\n\nimport numpy as np\nimport numpy.typing as npt\n\nclass SubClass(npt.NDArray[np.float64]): ...\nclass IntSubClass(npt.NDArray[np.intp]): ...\n\ni4 = np.int32(1)\nA: np.ndarray[Any, np.dtype[np.int32]] = np.array([[1]], dtype=np.int32)\nB0 = np.empty((), dtype=np.int32).view(SubClass)\nB1 = np.empty((1,), dtype=np.int32).view(SubClass)\nB2 = np.empty((1, 1), dtype=np.int32).view(SubClass)\nB_int0: IntSubClass = np.empty((), dtype=np.intp).view(IntSubClass)\nC: np.ndarray[Any, np.dtype[np.int32]] = np.array([0, 1, 2], dtype=np.int32)\nD = np.ones(3).view(SubClass)\n\nctypes_obj = A.ctypes\n\ni4.all()\nA.all()\nA.all(axis=0)\nA.all(keepdims=True)\nA.all(out=B0)\n\ni4.any()\nA.any()\nA.any(axis=0)\nA.any(keepdims=True)\nA.any(out=B0)\n\ni4.argmax()\nA.argmax()\nA.argmax(axis=0)\nA.argmax(out=B_int0)\n\ni4.argmin()\nA.argmin()\nA.argmin(axis=0)\nA.argmin(out=B_int0)\n\ni4.argsort()\nA.argsort()\n\ni4.choose([()])\n_choices = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int32)\nC.choose(_choices)\nC.choose(_choices, out=D)\n\ni4.clip(1)\nA.clip(1)\nA.clip(None, 1)\nA.clip(1, out=B2)\nA.clip(None, 1, out=B2)\n\ni4.compress([1])\nA.compress([1])\nA.compress([1], out=B1)\n\ni4.conj()\nA.conj()\nB0.conj()\n\ni4.conjugate()\nA.conjugate()\nB0.conjugate()\n\ni4.cumprod()\nA.cumprod()\nA.cumprod(out=B1)\n\ni4.cumsum()\nA.cumsum()\nA.cumsum(out=B1)\n\ni4.max()\nA.max()\nA.max(axis=0)\nA.max(keepdims=True)\nA.max(out=B0)\n\ni4.mean()\nA.mean()\nA.mean(axis=0)\nA.mean(keepdims=True)\nA.mean(out=B0)\n\ni4.min()\nA.min()\nA.min(axis=0)\nA.min(keepdims=True)\nA.min(out=B0)\n\ni4.prod()\nA.prod()\nA.prod(axis=0)\nA.prod(keepdims=True)\nA.prod(out=B0)\n\ni4.round()\nA.round()\nA.round(out=B2)\n\ni4.repeat(1)\nA.repeat(1)\nB0.repeat(1)\n\ni4.std()\nA.std()\nA.std(axis=0)\nA.std(keepdims=True)\nA.std(out=B0.astype(np.float64))\n\ni4.sum()\nA.sum()\nA.sum(axis=0)\nA.sum(keepdims=True)\nA.sum(out=B0)\n\ni4.take(0)\nA.take(0)\nA.take([0])\nA.take(0, out=B0)\nA.take([0], out=B1)\n\ni4.var()\nA.var()\nA.var(axis=0)\nA.var(keepdims=True)\nA.var(out=B0)\n\nA.argpartition([0])\n\nA.diagonal()\n\nA.dot(1)\nA.dot(1, out=B2)\n\nA.nonzero()\n\nC.searchsorted(1)\n\nA.trace()\nA.trace(out=B0)\n\nvoid = cast(np.void, np.array(1, dtype=[("f", np.float64)]).take(0))\nvoid.setfield(10, np.float64)\n\nA.item(0)\nC.item(0)\n\nA.ravel()\nC.ravel()\n\nA.flatten()\nC.flatten()\n\nA.reshape(1)\nC.reshape(3)\n\nint(np.array(1.0, dtype=np.float64))\nint(np.array("1", dtype=np.str_))\n\nfloat(np.array(1.0, dtype=np.float64))\nfloat(np.array("1", dtype=np.str_))\n\ncomplex(np.array(1.0, dtype=np.float64))\n\noperator.index(np.array(1, dtype=np.int64))\n\n# this fails on numpy 2.2.1\n# https://github.com/scipy/scipy/blob/a755ee77ec47a64849abe42c349936475a6c2f24/scipy/io/arff/tests/test_arffread.py#L41-L44\nA_float = np.array([[1, 5], [2, 4], [np.nan, np.nan]])\nA_void: npt.NDArray[np.void] = np.empty(3, [("yop", float), ("yap", float)])\nA_void["yop"] = A_float[:, 0]\nA_void["yap"] = A_float[:, 1]\n\n# deprecated\n\nwith np.testing.assert_warns(DeprecationWarning):\n ctypes_obj.get_data() # type: ignore[deprecated] # pyright: ignore[reportDeprecated]\nwith np.testing.assert_warns(DeprecationWarning):\n ctypes_obj.get_shape() # type: ignore[deprecated] # pyright: ignore[reportDeprecated]\nwith np.testing.assert_warns(DeprecationWarning):\n ctypes_obj.get_strides() # type: ignore[deprecated] # pyright: ignore[reportDeprecated]\nwith np.testing.assert_warns(DeprecationWarning):\n ctypes_obj.get_as_parameter() # type: ignore[deprecated] # pyright: ignore[reportDeprecated]\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\ndarray_misc.py | ndarray_misc.py | Python | 3,897 | 0.95 | 0.025253 | 0.02 | awesome-app | 716 | 2025-05-14T08:27:35.513158 | MIT | true | 9ccfb36400f4750239674b2b5c5d4898 |
import numpy as np\n\nnd1 = np.array([[1, 2], [3, 4]])\n\n# reshape\nnd1.reshape(4)\nnd1.reshape(2, 2)\nnd1.reshape((2, 2))\n\nnd1.reshape((2, 2), order="C")\nnd1.reshape(4, order="C")\n\n# resize\nnd1.resize()\nnd1.resize(4)\nnd1.resize(2, 2)\nnd1.resize((2, 2))\n\nnd1.resize((2, 2), refcheck=True)\nnd1.resize(4, refcheck=True)\n\nnd2 = np.array([[1, 2], [3, 4]])\n\n# transpose\nnd2.transpose()\nnd2.transpose(1, 0)\nnd2.transpose((1, 0))\n\n# swapaxes\nnd2.swapaxes(0, 1)\n\n# flatten\nnd2.flatten()\nnd2.flatten("C")\n\n# ravel\nnd2.ravel()\nnd2.ravel("C")\n\n# squeeze\nnd2.squeeze()\n\nnd3 = np.array([[1, 2]])\nnd3.squeeze(0)\n\nnd4 = np.array([[[1, 2]]])\nnd4.squeeze((0, 1))\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\ndarray_shape_manipulation.py | ndarray_shape_manipulation.py | Python | 687 | 0.95 | 0 | 0.205882 | python-kit | 335 | 2023-11-14T13:36:36.052463 | BSD-3-Clause | true | 702580b959ce646e268cd452080fba18 |
import numpy as np\n\narr = np.array([1])\nnp.nditer([arr, None])\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\nditer.py | nditer.py | Python | 67 | 0.65 | 0 | 0 | node-utils | 122 | 2023-09-27T04:38:22.131162 | BSD-3-Clause | true | a1c63aa936b8b695ac79d3b0d2676f0d |
"""\nTests for :mod:`numpy._core.numeric`.\n\nDoes not include tests which fall under ``array_constructors``.\n\n"""\n\nfrom __future__ import annotations\nfrom typing import cast\n\nimport numpy as np\nimport numpy.typing as npt\n\nclass SubClass(npt.NDArray[np.float64]): ...\n\n\ni8 = np.int64(1)\n\nA = cast(\n np.ndarray[tuple[int, int, int], np.dtype[np.intp]],\n np.arange(27).reshape(3, 3, 3),\n)\nB: list[list[list[int]]] = A.tolist()\nC = np.empty((27, 27)).view(SubClass)\n\nnp.count_nonzero(i8)\nnp.count_nonzero(A)\nnp.count_nonzero(B)\nnp.count_nonzero(A, keepdims=True)\nnp.count_nonzero(A, axis=0)\n\nnp.isfortran(i8)\nnp.isfortran(A)\n\nnp.argwhere(i8)\nnp.argwhere(A)\n\nnp.flatnonzero(i8)\nnp.flatnonzero(A)\n\nnp.correlate(B[0][0], A.ravel(), mode="valid")\nnp.correlate(A.ravel(), A.ravel(), mode="same")\n\nnp.convolve(B[0][0], A.ravel(), mode="valid")\nnp.convolve(A.ravel(), A.ravel(), mode="same")\n\nnp.outer(i8, A)\nnp.outer(B, A)\nnp.outer(A, A)\nnp.outer(A, A, out=C)\n\nnp.tensordot(B, A)\nnp.tensordot(A, A)\nnp.tensordot(A, A, axes=0)\nnp.tensordot(A, A, axes=(0, 1))\n\nnp.isscalar(i8)\nnp.isscalar(A)\nnp.isscalar(B)\n\nnp.roll(A, 1)\nnp.roll(A, (1, 2))\nnp.roll(B, 1)\n\nnp.rollaxis(A, 0, 1)\n\nnp.moveaxis(A, 0, 1)\nnp.moveaxis(A, (0, 1), (1, 2))\n\nnp.cross(B, A)\nnp.cross(A, A)\n\nnp.indices([0, 1, 2])\nnp.indices([0, 1, 2], sparse=False)\nnp.indices([0, 1, 2], sparse=True)\n\nnp.binary_repr(1)\n\nnp.base_repr(1)\n\nnp.allclose(i8, A)\nnp.allclose(B, A)\nnp.allclose(A, A)\n\nnp.isclose(i8, A)\nnp.isclose(B, A)\nnp.isclose(A, A)\n\nnp.array_equal(i8, A)\nnp.array_equal(B, A)\nnp.array_equal(A, A)\n\nnp.array_equiv(i8, A)\nnp.array_equiv(B, A)\nnp.array_equiv(A, A)\n | .venv\Lib\site-packages\numpy\typing\tests\data\pass\numeric.py | numeric.py | Python | 1,717 | 0.85 | 0.021053 | 0 | vue-tools | 999 | 2024-06-25T16:17:37.062501 | MIT | true | 34274a107072844b6dc1f6b38daa093f |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.