├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.yml │ ├── documentation.yml │ └── feature-request.yml ├── dependabot.yml ├── labeler.yml └── workflows │ ├── ci.yml │ ├── docs.yml │ └── publish-pypi.yml ├── .gitignore ├── .taplo.toml ├── .vscode ├── extensions.json └── settings.json ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── docs ├── .markdownlint.yaml ├── .nav.yml ├── dev │ ├── index.md │ └── style.md ├── index.md ├── reference.md ├── theme │ ├── img │ │ ├── favicon.ico │ │ ├── icon.svg │ │ └── logo-numtype.svg │ ├── overrides │ │ └── main.html │ └── style │ │ ├── color.css │ │ ├── font.css │ │ ├── overrides.css │ │ └── theme.css └── user │ ├── differences.md │ └── index.md ├── lefthook.yml ├── mkdocs.yml ├── pyproject.toml ├── src ├── _numtype │ ├── .ruff.toml │ ├── @test │ │ ├── .ruff.toml │ │ ├── generated │ │ │ └── test_rank.pyi │ │ ├── test_can_array_0d.pyi │ │ ├── test_nep50.pyi │ │ ├── test_rank_shape.pyi │ │ ├── test_sequence_nd.pyi │ │ └── test_to_array.pyi │ ├── __init__.pyi │ ├── _array.pyi │ ├── _dtype.pyi │ ├── _just.pyi │ ├── _nep50.pyi │ ├── _rank.pyi │ ├── _scalar.pyi │ ├── _scalar_co.pyi │ ├── _shape.pyi │ ├── op.pyi │ └── py.typed ├── numpy-stubs │ ├── .ruff.toml │ ├── @test │ │ ├── .ruff.toml │ │ ├── generated │ │ │ ├── .ruff.toml │ │ │ ├── emath.pyi │ │ │ ├── literal_bool_ops.pyi │ │ │ ├── ndarray_abs.pyi │ │ │ ├── ndarray_add.pyi │ │ │ ├── ndarray_and.pyi │ │ │ ├── ndarray_divmod.pyi │ │ │ ├── ndarray_floordiv.pyi │ │ │ ├── ndarray_invert.pyi │ │ │ ├── ndarray_lshift.pyi │ │ │ ├── ndarray_matmul.pyi │ │ │ ├── ndarray_mod.pyi │ │ │ ├── ndarray_mul.pyi │ │ │ ├── ndarray_neg.pyi │ │ │ ├── ndarray_or.pyi │ │ │ ├── ndarray_pos.pyi │ │ │ ├── ndarray_pow.pyi │ │ │ ├── ndarray_rshift.pyi │ │ │ ├── ndarray_sub.pyi │ │ │ ├── ndarray_truediv.pyi │ │ │ ├── ndarray_xor.pyi │ │ │ ├── scalar_ops_arithmetic.pyi │ │ │ ├── scalar_ops_bitwise.pyi │ │ │ ├── scalar_ops_comparison.pyi │ │ │ └── scalar_ops_modular.pyi │ │ ├── runtime │ │ │ ├── .ruff.toml │ │ │ ├── legacy │ │ │ │ ├── __init__.py │ │ │ │ ├── arithmetic.py │ │ │ │ ├── array_constructors.py │ │ │ │ ├── array_like.py │ │ │ │ ├── arrayprint.py │ │ │ │ ├── arrayterator.py │ │ │ │ ├── bitwise_ops.py │ │ │ │ ├── comparisons.py │ │ │ │ ├── dtype.py │ │ │ │ ├── einsumfunc.py │ │ │ │ ├── flatiter.py │ │ │ │ ├── fromnumeric.py │ │ │ │ ├── index_tricks.py │ │ │ │ ├── lib_user_array.py │ │ │ │ ├── lib_utils.py │ │ │ │ ├── lib_version.py │ │ │ │ ├── literal.py │ │ │ │ ├── ma.py │ │ │ │ ├── mod.py │ │ │ │ ├── modules.py │ │ │ │ ├── multiarray.py │ │ │ │ ├── ndarray_conversion.py │ │ │ │ ├── ndarray_misc.py │ │ │ │ ├── ndarray_shape_manipulation.py │ │ │ │ ├── nditer.py │ │ │ │ ├── numeric.py │ │ │ │ ├── numerictypes.py │ │ │ │ ├── random.py │ │ │ │ ├── recfunctions.py │ │ │ │ ├── scalars.py │ │ │ │ ├── shape.py │ │ │ │ ├── simple.py │ │ │ │ ├── simple_py3.py │ │ │ │ ├── ufunc_config.py │ │ │ │ ├── ufunclike.py │ │ │ │ ├── ufuncs.py │ │ │ │ └── warnings_and_errors.py │ │ │ ├── test_ctype_assumptions.py │ │ │ └── test_runtime.py │ │ └── static │ │ │ ├── .ruff.toml │ │ │ ├── accept │ │ │ ├── .ruff.toml │ │ │ ├── README.md │ │ │ ├── __init__.pyi │ │ │ ├── arithmetic.pyi │ │ │ ├── array_api_info.pyi │ │ │ ├── array_constructors.pyi │ │ │ ├── arraypad.pyi │ │ │ ├── arrayprint.pyi │ │ │ ├── arraysetops.pyi │ │ │ ├── arrayterator.pyi │ │ │ ├── bitwise_ops.pyi │ │ │ ├── char.pyi │ │ │ ├── chararray.pyi │ │ │ ├── comparisons.pyi │ │ │ ├── constants.pyi │ │ │ ├── ctypeslib.pyi │ │ │ ├── datasource.pyi │ │ │ ├── dtype.pyi │ │ │ ├── einsumfunc.pyi │ │ │ ├── emath.pyi │ │ │ ├── fft.pyi │ │ │ ├── flatiter.pyi │ │ │ ├── fromnumeric.pyi │ │ │ ├── getlimits.pyi │ │ │ ├── histograms.pyi │ │ │ ├── index_tricks.pyi │ │ │ ├── lib_function_base.pyi │ │ │ ├── lib_polynomial.pyi │ │ │ ├── lib_utils.pyi │ │ │ ├── lib_version.pyi │ │ │ ├── linalg.pyi │ │ │ ├── ma.pyi │ │ │ ├── matrix.pyi │ │ │ ├── memmap.pyi │ │ │ ├── mod.pyi │ │ │ ├── modules.pyi │ │ │ ├── multiarray.pyi │ │ │ ├── ndarray_assignability.pyi │ │ │ ├── ndarray_conversion.pyi │ │ │ ├── ndarray_misc.pyi │ │ │ ├── ndarray_shape_manipulation.pyi │ │ │ ├── nditer.pyi │ │ │ ├── nested_sequence.pyi │ │ │ ├── npyio.pyi │ │ │ ├── numeric.pyi │ │ │ ├── numerictypes.pyi │ │ │ ├── polynomial_polybase.pyi │ │ │ ├── polynomial_polyutils.pyi │ │ │ ├── polynomial_series.pyi │ │ │ ├── random.pyi │ │ │ ├── rec.pyi │ │ │ ├── scalars.pyi │ │ │ ├── shape.pyi │ │ │ ├── shape_base.pyi │ │ │ ├── stride_tricks.pyi │ │ │ ├── strings.pyi │ │ │ ├── testing.pyi │ │ │ ├── twodim_base.pyi │ │ │ ├── type_check.pyi │ │ │ ├── ufunc_config.pyi │ │ │ ├── ufunclike.pyi │ │ │ ├── ufuncs.pyi │ │ │ └── warnings_and_errors.pyi │ │ │ ├── reject │ │ │ ├── .ruff.toml │ │ │ ├── README.md │ │ │ ├── __init__.pyi │ │ │ ├── arithmetic.pyi │ │ │ ├── array_constructors.pyi │ │ │ ├── array_like.pyi │ │ │ ├── array_pad.pyi │ │ │ ├── arrayprint.pyi │ │ │ ├── arrayterator.pyi │ │ │ ├── bitwise_ops.pyi │ │ │ ├── char.pyi │ │ │ ├── chararray.pyi │ │ │ ├── comparisons.pyi │ │ │ ├── constants.pyi │ │ │ ├── datasource.pyi │ │ │ ├── dtype.pyi │ │ │ ├── einsumfunc.pyi │ │ │ ├── flatiter.pyi │ │ │ ├── fromnumeric.pyi │ │ │ ├── histograms.pyi │ │ │ ├── index_tricks.pyi │ │ │ ├── lib_function_base.pyi │ │ │ ├── lib_polynomial.pyi │ │ │ ├── lib_utils.pyi │ │ │ ├── lib_version.pyi │ │ │ ├── linalg.pyi │ │ │ ├── ma.pyi │ │ │ ├── memmap.pyi │ │ │ ├── modules.pyi │ │ │ ├── multiarray.pyi │ │ │ ├── ndarray.pyi │ │ │ ├── ndarray_misc.pyi │ │ │ ├── nditer.pyi │ │ │ ├── nested_sequence.pyi │ │ │ ├── npyio.pyi │ │ │ ├── numerictypes.pyi │ │ │ ├── random.pyi │ │ │ ├── rec.pyi │ │ │ ├── scalars.pyi │ │ │ ├── shape.pyi │ │ │ ├── shape_base.pyi │ │ │ ├── stride_tricks.pyi │ │ │ ├── strings.pyi │ │ │ ├── testing.pyi │ │ │ ├── twodim_base.pyi │ │ │ ├── type_check.pyi │ │ │ ├── ufunc_config.pyi │ │ │ ├── ufunclike.pyi │ │ │ ├── ufuncs.pyi │ │ │ └── warnings_and_errors.pyi │ │ │ └── sanity │ │ │ ├── __init__.pyi │ │ │ └── using_numtype.pyi │ ├── __config__.pyi │ ├── __init__.pyi │ ├── _array_api_info.pyi │ ├── _configtool.pyi │ ├── _core │ │ ├── __init__.pyi │ │ ├── _add_newdocs.pyi │ │ ├── _add_newdocs_scalars.pyi │ │ ├── _asarray.pyi │ │ ├── _dtype.pyi │ │ ├── _dtype_ctypes.pyi │ │ ├── _exceptions.pyi │ │ ├── _internal.pyi │ │ ├── _machar.pyi │ │ ├── _methods.pyi │ │ ├── _multiarray_umath.pyi │ │ ├── _simd.pyi │ │ ├── _string_helpers.pyi │ │ ├── _type_aliases.pyi │ │ ├── _ufunc_config.pyi │ │ ├── arrayprint.pyi │ │ ├── defchararray.pyi │ │ ├── einsumfunc.pyi │ │ ├── fromnumeric.pyi │ │ ├── function_base.pyi │ │ ├── getlimits.pyi │ │ ├── memmap.pyi │ │ ├── multiarray.pyi │ │ ├── numeric.pyi │ │ ├── numerictypes.pyi │ │ ├── overrides.pyi │ │ ├── printoptions.pyi │ │ ├── records.pyi │ │ ├── shape_base.pyi │ │ ├── strings.pyi │ │ └── umath.pyi │ ├── _distributor_init.pyi │ ├── _expired_attrs_2_0.pyi │ ├── _globals.pyi │ ├── _pyinstaller │ │ ├── __init__.pyi │ │ └── hook-numpy.pyi │ ├── _pytesttester.pyi │ ├── _typing │ │ ├── __init__.pyi │ │ ├── _array_like.pyi │ │ ├── _char_codes.pyi │ │ ├── _dtype_like.pyi │ │ ├── _nested_sequence.pyi │ │ ├── _scalars.pyi │ │ ├── _shape.pyi │ │ └── _ufunc.pyi │ ├── _utils │ │ ├── __init__.pyi │ │ ├── _convertions.pyi │ │ ├── _inspect.pyi │ │ └── _pep440.pyi │ ├── char │ │ └── __init__.pyi │ ├── compat │ │ ├── __init__.pyi │ │ └── py3k.pyi │ ├── core │ │ ├── __init__.pyi │ │ ├── _dtype.pyi │ │ ├── _dtype_ctypes.pyi │ │ ├── _internal.pyi │ │ ├── _multiarray_umath.pyi │ │ ├── _utils.pyi │ │ ├── arrayprint.pyi │ │ ├── defchararray.pyi │ │ ├── einsumfunc.pyi │ │ ├── fromnumeric.pyi │ │ ├── function_base.pyi │ │ ├── getlimits.pyi │ │ ├── multiarray.pyi │ │ ├── numeric.pyi │ │ ├── numerictypes.pyi │ │ ├── overrides.pyi │ │ ├── records.pyi │ │ ├── shape_base.pyi │ │ └── umath.pyi │ ├── ctypeslib.pyi │ ├── distutils │ │ ├── __init__.pyi │ │ ├── core.pyi │ │ ├── extension.pyi │ │ ├── misc_util.pyi │ │ └── system_info.pyi │ ├── dtypes.pyi │ ├── exceptions.pyi │ ├── f2py │ │ ├── __init__.pyi │ │ ├── __version__.pyi │ │ ├── _backends │ │ │ ├── __init__.pyi │ │ │ ├── _backend.pyi │ │ │ ├── _distutils.pyi │ │ │ └── _meson.pyi │ │ ├── _isocbind.pyi │ │ ├── _src_pyf.pyi │ │ ├── auxfuncs.pyi │ │ ├── capi_maps.pyi │ │ ├── cb_rules.pyi │ │ ├── cfuncs.pyi │ │ ├── common_rules.pyi │ │ ├── crackfortran.pyi │ │ ├── diagnose.pyi │ │ ├── f2py2e.pyi │ │ ├── f90mod_rules.pyi │ │ ├── func2subr.pyi │ │ ├── rules.pyi │ │ ├── symbolic.pyi │ │ └── use_rules.pyi │ ├── fft │ │ ├── __init__.pyi │ │ ├── _helper.pyi │ │ ├── _pocketfft.pyi │ │ └── helper.pyi │ ├── lib │ │ ├── __init__.pyi │ │ ├── _array_utils_impl.pyi │ │ ├── _arraypad_impl.pyi │ │ ├── _arraysetops_impl.pyi │ │ ├── _arrayterator_impl.pyi │ │ ├── _datasource.pyi │ │ ├── _function_base_impl.pyi │ │ ├── _histograms_impl.pyi │ │ ├── _index_tricks_impl.pyi │ │ ├── _iotools.pyi │ │ ├── _nanfunctions_impl.pyi │ │ ├── _npyio_impl.pyi │ │ ├── _polynomial_impl.pyi │ │ ├── _scimath_impl.pyi │ │ ├── _shape_base_impl.pyi │ │ ├── _stride_tricks_impl.pyi │ │ ├── _twodim_base_impl.pyi │ │ ├── _type_check_impl.pyi │ │ ├── _ufunclike_impl.pyi │ │ ├── _user_array_impl.pyi │ │ ├── _utils_impl.pyi │ │ ├── _version.pyi │ │ ├── array_utils.pyi │ │ ├── format.pyi │ │ ├── introspect.pyi │ │ ├── mixins.pyi │ │ ├── npyio.pyi │ │ ├── recfunctions.pyi │ │ ├── scimath.pyi │ │ ├── stride_tricks.pyi │ │ └── user_array.pyi │ ├── linalg │ │ ├── __init__.pyi │ │ ├── _linalg.pyi │ │ ├── _umath_linalg.pyi │ │ ├── lapack_lite.pyi │ │ └── linalg.pyi │ ├── ma │ │ ├── __init__.pyi │ │ ├── core.pyi │ │ ├── extras.pyi │ │ ├── mrecords.pyi │ │ ├── testutils.pyi │ │ └── timer_comparison.pyi │ ├── matlib.pyi │ ├── matrixlib │ │ ├── __init__.pyi │ │ └── defmatrix.pyi │ ├── polynomial │ │ ├── __init__.pyi │ │ ├── _polybase.pyi │ │ ├── chebyshev.pyi │ │ ├── hermite.pyi │ │ ├── hermite_e.pyi │ │ ├── laguerre.pyi │ │ ├── legendre.pyi │ │ ├── polynomial.pyi │ │ └── polyutils.pyi │ ├── random │ │ ├── __init__.pyi │ │ ├── _bounded_integers.pyi │ │ ├── _common.pyi │ │ ├── _generator.pyi │ │ ├── _mt19937.pyi │ │ ├── _pcg64.pyi │ │ ├── _philox.pyi │ │ ├── _pickle.pyi │ │ ├── _sfc64.pyi │ │ ├── bit_generator.pyi │ │ └── mtrand.pyi │ ├── rec │ │ └── __init__.pyi │ ├── strings │ │ └── __init__.pyi │ ├── testing │ │ ├── __init__.pyi │ │ ├── _private │ │ │ ├── __init__.pyi │ │ │ ├── extbuild.pyi │ │ │ └── utils.pyi │ │ ├── overrides.pyi │ │ └── print_coercion_tables.pyi │ ├── typing │ │ └── __init__.pyi │ └── version.pyi └── numtype │ ├── .ruff.toml │ ├── @test │ ├── .ruff.toml │ └── test_numtype.py │ ├── __init__.py │ ├── py.typed │ └── version.py ├── tool ├── .ruff.toml ├── README.md ├── __init__.py ├── _ruff.py ├── allowlists │ ├── common.txt │ ├── ge-py312.txt │ ├── lt-py312.txt │ └── simd.txt ├── format_ignores.py ├── promotion.py ├── stubtest.py ├── stubtest.py.lock ├── test │ ├── __init__.py │ └── test_format_ignores.py ├── testgen.py ├── ufunc.py ├── ufunc.py.lock └── unstub.py └── uv.lock /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | *.lock -diff merge=ours linguist-generated=true 3 | src/numpy-stubs/@test/generated/*.pyi -diff merge=ours linguist-generated=true 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.yml: -------------------------------------------------------------------------------- 1 | name: Documentation 2 | description: Report an issue related to the NumType documentation. 3 | title: "" 4 | labels: ["topic: Docs"] 5 | 6 | body: 7 | - type: textarea 8 | attributes: 9 | label: "Issue with current documentation:" 10 | description: > 11 | Please make sure to leave a reference to the document/code you're 12 | referring to. You can also check the development version of the 13 | documentation. 14 | 15 | - type: textarea 16 | attributes: 17 | label: "Idea or request for content:" 18 | description: Please describe as clearly as possible what topics you think are missing from the current documentation. 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.yml: -------------------------------------------------------------------------------- 1 | name: Feature request 2 | description: Suggest an improvement or propose a new feature. 3 | title: "" 4 | labels: ["stubs: Enhancement"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: > 9 | If you're looking to request a new feature or change in functionality, 10 | including adding or changing the meaning of arguments to an existing 11 | function. 12 | 13 | - type: textarea 14 | attributes: 15 | label: "Please describe the feature or change you would like to see:" 16 | validations: 17 | required: true 18 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | target-branch: main 6 | schedule: 7 | interval: daily 8 | allow: 9 | - dependency-type: "all" 10 | labels: 11 | - "topic: dependencies" 12 | - "tool: github-actions" 13 | commit-message: 14 | prefix: "⬆️ " 15 | 16 | - package-ecosystem: uv 17 | directory: / 18 | target-branch: main 19 | schedule: 20 | interval: daily 21 | allow: 22 | - dependency-type: "all" 23 | ignore: 24 | - dependency-name: "numpy" 25 | labels: 26 | - "topic: dependencies" 27 | - "tool: uv" 28 | commit-message: 29 | prefix: "⬆️ " 30 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: deploy docs 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | paths: 7 | - "docs/**" 8 | - ".github/workflows/docs.yml" 9 | - "CONTRIBUTING.md" 10 | - "mkdocs.yml" 11 | - "uv.lock" 12 | 13 | permissions: 14 | contents: write 15 | 16 | env: 17 | UV_FROZEN: 1 18 | 19 | jobs: 20 | deploy: 21 | runs-on: ubuntu-latest 22 | steps: 23 | - uses: actions/checkout@v4 24 | 25 | - name: Configure Git Credentials 26 | run: | 27 | git config user.name github-actions[bot] 28 | git config user.email 41898282+github-actions[bot]@users.noreply.github.com 29 | 30 | - uses: astral-sh/setup-uv@v6 31 | with: 32 | enable-cache: true 33 | 34 | - name: mkdocs gh-deploy 35 | run: uv run --only-group=docs mkdocs gh-deploy --force 36 | -------------------------------------------------------------------------------- /.github/workflows/publish-pypi.yml: -------------------------------------------------------------------------------- 1 | name: build and publish to PyPI 2 | 3 | on: 4 | workflow_dispatch: 5 | release: 6 | types: [prereleased, released] 7 | 8 | jobs: 9 | pypi-publish: 10 | name: Publish release to PyPI 11 | runs-on: ubuntu-latest 12 | timeout-minutes: 5 13 | environment: 14 | name: pypi 15 | url: https://pypi.org/p/numtype 16 | permissions: 17 | id-token: write 18 | steps: 19 | - uses: actions/checkout@v4 20 | - name: setup uv 21 | uses: astral-sh/setup-uv@v6 22 | with: 23 | python-version: "3.13" 24 | - name: uv build 25 | run: uv build 26 | - name: publish to PyPI 27 | uses: pypa/gh-action-pypi-publish@release/v1 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Python-generated files 2 | __pycache__/ 3 | *.py[oc] 4 | build/ 5 | dist/ 6 | wheels/ 7 | *.egg-info 8 | 9 | # Environment variables 10 | .env 11 | 12 | # Virtual environments 13 | .venv 14 | 15 | # Cache 16 | .cache/ 17 | .mypy_cache/ 18 | .pytest_cache/ 19 | .ruff_cache/ 20 | .tox/ 21 | 22 | # Docs 23 | site/ 24 | -------------------------------------------------------------------------------- /.taplo.toml: -------------------------------------------------------------------------------- 1 | # https://taplo.tamasfe.dev/configuration/file.html 2 | include = ["*.toml", "src/**/*.toml", "test/**/*.toml", "tool/**/*.toml"] 3 | 4 | [formatting] 5 | # https://taplo.tamasfe.dev/configuration/formatter-options.html 6 | align_entries = false 7 | align_comments = true 8 | allowed_blank_lines = 2 9 | array_auto_collapse = false 10 | array_auto_expand = true 11 | array_trailing_comma = true 12 | column_width = 88 13 | compact_arrays = true 14 | compact_inline_tables = true 15 | crlf = false 16 | indent_string = " " # 4 spaces 17 | indent_tables = true 18 | reorder_keys = false 19 | reorder_arrays = false 20 | reorder_inline_tables = false 21 | trailingNewline = true 22 | 23 | [schema] 24 | enabled = false 25 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "charliermarsh.ruff", 4 | "davidanson.vscode-markdownlint", 5 | "detachhead.basedpyright", 6 | "ms-python.mypy-type-checker", 7 | "ms-python.python", 8 | "redhat.vscode-yaml", 9 | "seatonjiang.gitmoji-vscode", 10 | "tamasfe.even-better-toml" 11 | ], 12 | "unwantedRecommendations": ["ms-pyright.pyright", "ms-python.vscode-pylance"] 13 | } 14 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[markdown]": { 3 | "editor.rulers": [ 4 | 120 5 | ] 6 | }, 7 | "[python]": { 8 | "editor.rulers": [ 9 | 88, 10 | 120 11 | ] 12 | }, 13 | "[toml]": { 14 | "editor.rulers": [88] 15 | }, 16 | "evenBetterToml.schema.enabled": false, 17 | "evenBetterToml.taplo.configFile.path": ".taplo.toml", 18 | "files.readonlyInclude": { 19 | "**/generated/*.pyi": true 20 | }, 21 | "git.branchProtection": ["main"], 22 | "markdownlint.configFile": "docs/.markdownlint.yaml", 23 | "mypy-type-checker.path": [ 24 | "uv", 25 | "run", 26 | "--no-editable", 27 | "--no-sync", 28 | "mypy" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # NumType's Contributing guidelines 2 | 3 | Welcome to the NumType community! We're excited to have you here. Whether 4 | you're new to open source or experienced, your contributions help us 5 | grow. 6 | 7 | Pull requests (PRs) are always welcome, but making a PR is just the 8 | start. Please respond to comments and requests for changes to help move 9 | the process forward. Please follow our [Code of 10 | Conduct](https://numpy.org/code-of-conduct/), which applies to all 11 | interactions, including issues and PRs. 12 | 13 | For more, please read 14 | 15 | Thank you for contributing, and happy coding! 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2025, NumPy Developers. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the copyright holder nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | NumType 7 |

8 | 9 | NumType provides experimental typing stubs for NumPy. 10 | 11 | > [!WARNING] 12 | > Under development — use at your own risk. 13 | -------------------------------------------------------------------------------- /docs/.markdownlint.yaml: -------------------------------------------------------------------------------- 1 | default: true 2 | no-hard-tabs: true 3 | 4 | MD007: 5 | indent: 2 6 | MD013: 7 | line_length: 120 8 | MD031: 9 | list_items: false 10 | MD033: 11 | allowed_elements: 12 | - h1 13 | - img 14 | - a 15 | - div 16 | MD036: false 17 | MD041: false 18 | -------------------------------------------------------------------------------- /docs/.nav.yml: -------------------------------------------------------------------------------- 1 | flatten_single_child_sections: true 2 | 3 | nav: 4 | - User Guide: user 5 | - API Reference: reference.md 6 | - Development: dev 7 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - navigation 4 | - toc 5 | --- 6 | 7 | # NumType documentation 8 | 9 | NumPy is the fundamental package for scientific computing in Python. 10 | It is a Python library that provides a multidimensional array object, various 11 | derived objects (such as masked arrays and matrices), and an assortment of 12 | routines for fast operations on arrays, including mathematical, logical, shape 13 | manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear 14 | algebra, basic statistical operations, random simulation and much more. 15 | 16 |
17 | 18 | - :material-book-open-variant:{ .lg .middle }   __User guide__ 19 | 20 | --- 21 | 22 | The user guide provides in-depth information on the key concepts of 23 | NumType with useful background information and explanation. 24 | 25 | [:octicons-arrow-right-24: To the user guide](user/index.md) 26 | 27 | - :material-code-brackets:{ .lg .middle }   __API reference__ 28 | 29 | --- 30 | 31 | The reference guide contains a detailed description of the functions, 32 | modules, and objects included in NumType. 33 | 34 | [:octicons-arrow-right-24: To the reference guide](reference.md) 35 | 36 | - :fontawesome-solid-user-plus:{ .lg .middle }   __Contributor's guide__ 37 | 38 | --- 39 | 40 | Want to add to the codebase? The contributing guidelines will guide you 41 | through the process of improving NumType. 42 | 43 | [:octicons-arrow-right-24: To the contributor's guide](dev/index.md) 44 | 45 |
46 | -------------------------------------------------------------------------------- /docs/reference.md: -------------------------------------------------------------------------------- 1 | --- 2 | hide: 3 | - navigation 4 | --- 5 | 6 | # NumType reference 7 | 8 | *coming soon* 9 | -------------------------------------------------------------------------------- /docs/theme/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numpy/numtype/83c2f491ba44a2de710bb9fbfb763a39833fb934/docs/theme/img/favicon.ico -------------------------------------------------------------------------------- /docs/theme/img/icon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/theme/overrides/main.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} {% block scripts %} 2 | 3 | {{ super() }} {% endblock %} 4 | -------------------------------------------------------------------------------- /docs/theme/style/font.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;0,900;1,400;1,700;1,900&family=Open+Sans:ital,wght@0,400;0,600;1,400;1,600"); 2 | 3 | :root { 4 | --pst-font-size-base: 1rem; 5 | --pst-font-size-milli: 0.9rem; 6 | 7 | --pst-font-size-h1: 2.625rem; 8 | --pst-font-size-h2: 2.125rem; 9 | --pst-font-size-h3: 1.75rem; 10 | --pst-font-size-h4: 1.5rem; 11 | --pst-font-size-h5: 1.25rem; 12 | --pst-font-size-h6: 1rem; 13 | 14 | --pst-sidebar-font-size: 0.9rem; 15 | --pst-sidebar-font-size-mobile: 1.1rem; 16 | --pst-sidebar-header-font-size: 1.2rem; 17 | --pst-sidebar-header-font-weight: 700; 18 | 19 | --pst-admonition-font-weight-heading: 700; 20 | 21 | --pst-font-weight-caption: 300; 22 | --pst-font-weight-heading: 700; 23 | 24 | --pst-font-family-base-system: -apple-system, "BlinkMacSystemFont", "Segoe UI", "Helvetica Neue", "Arial", sans-serif, 25 | "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; 26 | --pst-font-family-monospace-system: "SFMono-Regular", "Menlo", "Consolas", "Monaco", "Liberation Mono", 27 | "Lucida Console", monospace; 28 | --pst-font-family-base: var(--pst-font-family-base-system); 29 | --pst-font-family-heading: Lato; 30 | --pst-font-family-monospace: var(--pst-font-family-monospace-system); 31 | } 32 | 33 | body { 34 | font-family: var(--pst-font-family-base); 35 | } 36 | 37 | h1, 38 | h2 { 39 | color: var(--pst-heading-color); 40 | } 41 | 42 | h1, 43 | h2, 44 | h3, 45 | h4, 46 | h5, 47 | h6 { 48 | font-family: var(--pst-font-family-heading); 49 | font-weight: var(--pst-font-weight-heading); 50 | line-height: 1.15; 51 | margin: 2.75rem 0 1.05rem; 52 | } 53 | 54 | .md-typeset { 55 | line-height: 1.65; 56 | } 57 | -------------------------------------------------------------------------------- /docs/theme/style/overrides.css: -------------------------------------------------------------------------------- 1 | [dir="ltr"] .md-header__title { 2 | margin-left: 0; 3 | } 4 | [dir="rtl"] .md-header__title { 5 | margin-right: 0; 6 | } 7 | 8 | .md-header__button.md-logo img, 9 | .md-header__button.md-logo svg { 10 | height: 52px; 11 | } 12 | 13 | .md-header__button.md-logo, 14 | .md-header__button.md-logo { 15 | margin: 0; 16 | padding: 0; 17 | } 18 | 19 | .md-header__title:not(.md-header__title--active) span { 20 | font-weight: 900; 21 | font-size: var(--pst-sidebar-header-font-size); 22 | } 23 | 24 | a { 25 | text-underline-offset: 0.1578em; 26 | word-wrap: break-word; 27 | } 28 | 29 | a:hover { 30 | color: var(--pst-color-link-hover); 31 | text-decoration: underline; 32 | text-decoration-skip-ink: none; 33 | } 34 | 35 | p a { 36 | text-decoration: underline; 37 | } 38 | 39 | code { 40 | border: 1px solid var(--pst-color-border); 41 | border-radius: 0.25rem; 42 | padding: 0.1rem 0.25rem; 43 | } 44 | -------------------------------------------------------------------------------- /docs/user/index.md: -------------------------------------------------------------------------------- 1 | # NumType user guide 2 | 3 | This guide is an overview and explains the important features; details are found in [NumType reference](../reference.md). 4 | -------------------------------------------------------------------------------- /lefthook.yml: -------------------------------------------------------------------------------- 1 | pre-commit: 2 | parallel: true 3 | commands: 4 | ruff-check: 5 | glob: "*.{py,pyi}" 6 | run: uv run --no-sync ruff check --fix {staged_files} 7 | stage_fixed: true 8 | ruff-format: 9 | glob: "*.{py,pyi}" 10 | run: uv run --no-sync ruff format {staged_files} 11 | stage_fixed: true 12 | ignore-format: 13 | glob: "*.{py,pyi}" 14 | run: uv run --no-sync tool/format_ignores.py {staged_files} 15 | stage_fixed: true 16 | exclude: 17 | - "tool/test/test_format_ignores.py" 18 | docs-check: 19 | glob: 20 | - "docs/**" 21 | - "mkdocs.yml" 22 | - "CONTRIBUTING.md" 23 | run: uv run --no-sync mkdocs build 24 | 25 | post-checkout: 26 | commands: 27 | dependencies: 28 | glob: uv.lock 29 | run: uv sync 30 | 31 | post-merge: 32 | files: "git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD" 33 | commands: 34 | dependencies: 35 | glob: uv.lock 36 | run: uv sync 37 | -------------------------------------------------------------------------------- /src/_numtype/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../../pyproject.toml" 2 | line-length = 120 3 | 4 | [lint] 5 | extend-ignore = ["PLR2044"] # pylint/R: empty-comment 6 | -------------------------------------------------------------------------------- /src/_numtype/@test/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../.ruff.toml" 2 | 3 | [lint] 4 | extend-ignore = [ 5 | "PYI015", # flake8-pyi: assignment-default-in-stub 6 | "PYI017", # flake8-pyi: complex-assignment-in-stub 7 | ] 8 | -------------------------------------------------------------------------------- /src/_numtype/@test/test_can_array_0d.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | ### 5 | # _ToArray1_0d 6 | 7 | can_b1_0d: _nt.CanArray0D[np.bool] = np.bool() 8 | can_i1_0d: _nt.CanArray0D[np.int8] = np.int8() 9 | can_i2_0d: _nt.CanArray0D[np.int16] = np.int16() 10 | can_i4_0d: _nt.CanArray0D[np.int32] = np.int32() 11 | can_i8_0d: _nt.CanArray0D[np.int64] = np.int64() 12 | can_u1_0d: _nt.CanArray0D[np.uint8] = np.uint8() 13 | can_u2_0d: _nt.CanArray0D[np.uint16] = np.uint16() 14 | can_u4_0d: _nt.CanArray0D[np.uint32] = np.uint32() 15 | can_u8_0d: _nt.CanArray0D[np.uint64] = np.uint64() 16 | can_f2_0d: _nt.CanArray0D[np.float16] = np.float16() 17 | can_f4_0d: _nt.CanArray0D[np.float32] = np.float32() 18 | can_f8_0d: _nt.CanArray0D[np.float64] = np.float64() 19 | can_ld_0d: _nt.CanArray0D[np.longdouble] = np.longdouble() 20 | can_c8_0d: _nt.CanArray0D[np.complex64] = np.complex64() 21 | can_c16_0d: _nt.CanArray0D[np.complex128] = np.complex128() 22 | can_cld_0d: _nt.CanArray0D[np.clongdouble] = np.clongdouble() 23 | can_O_0d: _nt.CanArray0D[np.object_] = np.empty((), np.object_) 24 | can_M_0d: _nt.CanArray0D[np.datetime64] = np.datetime64(None) 25 | can_m_0d: _nt.CanArray0D[np.timedelta64] = np.timedelta64(None) 26 | can_S_0d: _nt.CanArray0D[np.bytes_] = np.bytes_(b"") 27 | can_U_0d: _nt.CanArray0D[np.str_] = np.str_("") 28 | can_V_0d: _nt.CanArray0D[np.void] = np.void(b"") 29 | -------------------------------------------------------------------------------- /src/_numtype/@test/test_rank_shape.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import _numtype as _nt 4 | 5 | # TODO: remove the `# type: ignore`s once python/mypy#19110 is fixed 6 | 7 | a0: _nt.Array0D 8 | assert_type(a0.__inner_shape__, _nt.Rank0) 9 | assert_type(a0.shape, _nt.Shape0) # type: ignore[assert-type] 10 | 11 | a1: _nt.Array1D 12 | assert_type(a1.__inner_shape__, _nt.Rank1) 13 | assert_type(a1.shape, _nt.Shape1) # type: ignore[assert-type] 14 | 15 | a2: _nt.Array2D 16 | assert_type(a2.__inner_shape__, _nt.Rank2) 17 | assert_type(a2.shape, _nt.Shape2) # type: ignore[assert-type] 18 | 19 | a3: _nt.Array3D 20 | assert_type(a3.__inner_shape__, _nt.Rank3) 21 | assert_type(a3.shape, _nt.Shape3) # type: ignore[assert-type] 22 | 23 | a4: _nt.Array4D 24 | assert_type(a4.__inner_shape__, _nt.Rank4) 25 | assert_type(a4.shape, _nt.Shape4) # type: ignore[assert-type] 26 | -------------------------------------------------------------------------------- /src/_numtype/@test/test_sequence_nd.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | 3 | class A: ... 4 | 5 | a0d: A 6 | a1d: list[A] 7 | a2d: list[list[A]] 8 | a3d: list[list[list[A]]] 9 | a4d: list[list[list[list[A]]]] 10 | 11 | ### 12 | 13 | a1nd__a_0d: _nt.Sequence1ND[A] = a0d # type: ignore[assignment] # pyright: ignore[reportAssignmentType] 14 | a1nd__a_1d: _nt.Sequence1ND[A] = a1d 15 | a1nd__a_2d: _nt.Sequence1ND[A] = a2d 16 | a1nd__a_3d: _nt.Sequence1ND[A] = a3d 17 | a1nd__a_4d: _nt.Sequence1ND[A] = a4d 18 | -------------------------------------------------------------------------------- /src/_numtype/_scalar.pyi: -------------------------------------------------------------------------------- 1 | from typing import TypeAlias 2 | 3 | import numpy as np 4 | 5 | __all__ = [ 6 | "inexact32", 7 | "inexact64", 8 | "inexact64l", 9 | "integer8", 10 | "integer16", 11 | "integer32", 12 | "integer64", 13 | "integer_l", 14 | "number16", 15 | "number32", 16 | "number64", 17 | ] 18 | 19 | ### 20 | # Sized abstract scalar type aliases. 21 | 22 | # ruff: noqa: PYI042 23 | 24 | integer8: TypeAlias = np.uint8 | np.int8 25 | integer16: TypeAlias = np.uint16 | np.int16 26 | integer32: TypeAlias = np.uint32 | np.int32 27 | integer_l: TypeAlias = np.ulong | np.long 28 | integer64: TypeAlias = np.uint64 | np.int64 29 | 30 | inexact32: TypeAlias = np.complex64 | np.float32 31 | inexact64: TypeAlias = np.complex128 | np.float64 32 | inexact64l: TypeAlias = np.clongdouble | np.longdouble 33 | 34 | number16: TypeAlias = np.float16 | integer16 35 | number32: TypeAlias = inexact32 | integer32 36 | number64: TypeAlias = inexact64 | integer64 37 | -------------------------------------------------------------------------------- /src/_numtype/_shape.pyi: -------------------------------------------------------------------------------- 1 | from typing import Any, Never, TypeAlias 2 | from typing_extensions import TypeAliasType 3 | 4 | __all__ = [ 5 | "AnyShape", 6 | "NeitherShape", 7 | "Shape", 8 | "Shape0", 9 | "Shape0N", 10 | "Shape1", 11 | "Shape1N", 12 | "Shape2", 13 | "Shape2N", 14 | "Shape3", 15 | "Shape3N", 16 | "Shape4", 17 | "Shape4N", 18 | "ShapeN", 19 | ] 20 | 21 | Shape = TypeAliasType("Shape", tuple[int, ...]) 22 | AnyShape = TypeAliasType("AnyShape", tuple[Any, ...]) 23 | NeitherShape = TypeAliasType("NeitherShape", tuple[Never, ...]) 24 | 25 | # TODO: remove `| Rank0` once python/mypy#19110 is fixed 26 | Shape0 = TypeAliasType("Shape0", tuple[()]) 27 | Shape1 = TypeAliasType("Shape1", tuple[int]) 28 | Shape2 = TypeAliasType("Shape2", tuple[int, int]) 29 | Shape3 = TypeAliasType("Shape3", tuple[int, int, int]) 30 | Shape4 = TypeAliasType("Shape4", tuple[int, int, int, int]) 31 | ShapeN: TypeAlias = Shape 32 | 33 | Shape0N: TypeAlias = Shape 34 | Shape1N = TypeAliasType("Shape1N", tuple[int, *tuple[int, ...]]) 35 | Shape2N = TypeAliasType("Shape2N", tuple[int, int, *tuple[int, ...]]) 36 | Shape3N = TypeAliasType("Shape3N", tuple[int, int, int, *tuple[int, ...]]) 37 | Shape4N = TypeAliasType("Shape4N", tuple[int, int, int, int, *tuple[int, ...]]) 38 | -------------------------------------------------------------------------------- /src/_numtype/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numpy/numtype/83c2f491ba44a2de710bb9fbfb763a39833fb934/src/_numtype/py.typed -------------------------------------------------------------------------------- /src/numpy-stubs/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../../pyproject.toml" 2 | line-length = 120 3 | 4 | [lint] 5 | extend-ignore = [ 6 | "A", # flake8-builtins 7 | "ANN401", # flake8-annotations: any-type 8 | "SLF001", # flake8-self: private-member-access 9 | "PLR2044", # pylint/R: empty-comment 10 | ] 11 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../../../pyproject.toml" 2 | line-length = 88 3 | 4 | [lint] 5 | extend-ignore = [ 6 | "D", # pydocstyle 7 | "FBT", # flake8-boolean-trap 8 | "PYI054", # flake8-pyi: numeric-literal-too-long 9 | ] 10 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/generated/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../.ruff.toml" 2 | line-length = 120 3 | 4 | [lint] 5 | extend-ignore = [ 6 | "B018", # flake8-bugbear useless-expression 7 | "PLR0124", # pylint/R: comparison-with-itself 8 | "PLC2801", # pylint/C: unnecessary-dunder-call 9 | ] 10 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/generated/ndarray_invert.pyi: -------------------------------------------------------------------------------- 1 | # @generated 2025-05-05T23:12:14Z with tool/testgen.py 2 | from typing import assert_type 3 | 4 | import _numtype as _nt 5 | import numpy as np 6 | 7 | ### 8 | 9 | b1_nd: _nt.Array[np.bool] 10 | i1_nd: _nt.Array[np.int8] 11 | i2_nd: _nt.Array[np.int16] 12 | i4_nd: _nt.Array[np.int32] 13 | i8_nd: _nt.Array[np.int64] 14 | u1_nd: _nt.Array[np.uint8] 15 | u2_nd: _nt.Array[np.uint16] 16 | u4_nd: _nt.Array[np.uint32] 17 | u8_nd: _nt.Array[np.uint64] 18 | f8_nd: _nt.Array[np.float64] 19 | c16_nd: _nt.Array[np.complex128] 20 | O_nd: _nt.Array[np.object_] 21 | i_nd: _nt.Array[np.signedinteger] 22 | u_nd: _nt.Array[np.unsignedinteger] 23 | iu_nd: _nt.Array[np.integer] 24 | 25 | ### 26 | 27 | assert_type(~b1_nd, _nt.Array[np.bool]) 28 | assert_type(~i1_nd, _nt.Array[np.int8]) 29 | assert_type(~i2_nd, _nt.Array[np.int16]) 30 | assert_type(~i4_nd, _nt.Array[np.int32]) 31 | assert_type(~i8_nd, _nt.Array[np.int64]) 32 | assert_type(~u1_nd, _nt.Array[np.uint8]) 33 | assert_type(~u2_nd, _nt.Array[np.uint16]) 34 | assert_type(~u4_nd, _nt.Array[np.uint32]) 35 | assert_type(~u8_nd, _nt.Array[np.uint64]) 36 | ~f8_nd # type: ignore[misc] # pyright: ignore[reportOperatorIssue] 37 | ~c16_nd # type: ignore[misc] # pyright: ignore[reportOperatorIssue] 38 | assert_type(~O_nd, _nt.Array[np.object_]) 39 | assert_type(~i_nd, _nt.Array[np.signedinteger]) 40 | assert_type(~u_nd, _nt.Array[np.unsignedinteger]) 41 | assert_type(~iu_nd, _nt.Array[np.integer]) 42 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../.ruff.toml" 2 | 3 | 4 | [lint] 5 | extend-ignore = [ 6 | "ARG", # flake8-unused-arguments 7 | "B015", # flake8-bugbear: useless-comparison 8 | "B018", # flake8-bugbear: useless-expression 9 | ] 10 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numpy/numtype/83c2f491ba44a2de710bb9fbfb763a39833fb934/src/numpy-stubs/@test/runtime/legacy/__init__.py -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/array_like.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from typing import TYPE_CHECKING 4 | 5 | import numpy as np 6 | 7 | if TYPE_CHECKING: 8 | from numpy._typing import ArrayLike, NDArray, _SupportsArray 9 | 10 | x1: ArrayLike = True 11 | x2: ArrayLike = 5 12 | x3: ArrayLike = 1.0 13 | x4: ArrayLike = 1 + 1j 14 | x5: ArrayLike = np.int8(1) 15 | x6: ArrayLike = np.float64(1) 16 | x7: ArrayLike = np.complex128(1) 17 | x8: ArrayLike = np.array([1, 2, 3]) 18 | x9: ArrayLike = [1, 2, 3] 19 | x10: ArrayLike = (1, 2, 3) 20 | x11: ArrayLike = "foo" 21 | x12: ArrayLike = memoryview(b"foo") 22 | 23 | 24 | class A: 25 | def __array__(self, dtype: np.dtype | None = None) -> NDArray[np.float64]: 26 | return np.array([1.0, 2.0, 3.0]) 27 | 28 | 29 | x13: ArrayLike = A() 30 | 31 | scalar: _SupportsArray[np.dtype[np.int64]] = np.int64(1) 32 | scalar.__array__() 33 | array: _SupportsArray[np.dtype[np.int_]] = np.array(1) 34 | array.__array__() 35 | 36 | a: _SupportsArray[np.dtype[np.float64]] = A() 37 | a.__array__() 38 | a.__array__() 39 | 40 | # Escape hatch for when you mean to make something like an object 41 | # array. 42 | object_array_scalar: object = (i for i in range(10)) 43 | np.array(object_array_scalar) 44 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/arrayprint.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | AR = np.arange(10) 4 | AR.setflags(write=False) 5 | 6 | with np.printoptions(): 7 | np.set_printoptions( 8 | precision=1, 9 | threshold=2, 10 | edgeitems=3, 11 | linewidth=4, 12 | suppress=False, 13 | nanstr="Bob", 14 | infstr="Bill", 15 | formatter={}, 16 | sign="+", 17 | floatmode="unique", 18 | ) 19 | np.get_printoptions() 20 | str(AR) 21 | 22 | np.array2string( 23 | AR, 24 | max_line_width=5, 25 | precision=2, 26 | suppress_small=True, 27 | separator=";", 28 | prefix="test", 29 | threshold=5, 30 | floatmode="fixed", 31 | suffix="?", 32 | legacy="1.13", 33 | ) 34 | np.format_float_scientific(1, precision=5) 35 | np.format_float_positional(1, trim="k") 36 | np.array_repr(AR) 37 | np.array_str(AR) 38 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/arrayterator.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import numpy as np 4 | import numpy.typing as npt 5 | 6 | AR_i8: npt.NDArray[np.int_] = np.arange(10) 7 | ar_iter = np.lib.Arrayterator(AR_i8) 8 | 9 | ar_iter.var 10 | ar_iter.buf_size 11 | ar_iter.start 12 | ar_iter.stop 13 | ar_iter.step 14 | ar_iter.shape 15 | ar_iter.flat 16 | 17 | ar_iter.__array__() 18 | 19 | for _ in ar_iter: 20 | pass 21 | 22 | ar_iter[0] 23 | ar_iter[...] 24 | ar_iter[:] 25 | ar_iter[0, 0, 0] 26 | ar_iter[..., 0, :] 27 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/bitwise_ops.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | i8 = np.int64(1) 4 | u8 = np.uint64(1) 5 | 6 | i4 = np.int32(1) 7 | u4 = np.uint32(1) 8 | 9 | b_ = np.bool(1) 10 | 11 | b = bool(1) 12 | i = 1 13 | 14 | AR = np.array([0, 1, 2], dtype=np.int32) 15 | AR.setflags(write=False) 16 | 17 | 18 | i8 << i8 19 | i8 >> i8 20 | i8 | i8 21 | i8 ^ i8 22 | i8 & i8 23 | 24 | i << AR 25 | i >> AR 26 | i | AR 27 | i ^ AR 28 | i & AR 29 | 30 | i8 << AR 31 | i8 >> AR 32 | i8 | AR 33 | i8 ^ AR 34 | i8 & AR 35 | 36 | i4 << i4 37 | i4 >> i4 38 | i4 | i4 39 | i4 ^ i4 40 | i4 & i4 41 | 42 | i8 << i4 43 | i8 >> i4 44 | i8 | i4 45 | i8 ^ i4 46 | i8 & i4 47 | 48 | i8 << i 49 | i8 >> i 50 | i8 | i 51 | i8 ^ i 52 | i8 & i 53 | 54 | i8 << b_ 55 | i8 >> b_ 56 | i8 | b_ 57 | i8 ^ b_ 58 | i8 & b_ 59 | 60 | i8 << b 61 | i8 >> b 62 | i8 | b 63 | i8 ^ b 64 | i8 & b 65 | 66 | u8 << u8 67 | u8 >> u8 68 | u8 | u8 69 | u8 ^ u8 70 | u8 & u8 71 | 72 | u4 << u4 73 | u4 >> u4 74 | u4 | u4 75 | u4 ^ u4 76 | u4 & u4 77 | 78 | u4 << i4 79 | u4 >> i4 80 | u4 | i4 81 | u4 ^ i4 82 | u4 & i4 83 | 84 | u4 << i 85 | u4 >> i 86 | u4 | i 87 | u4 ^ i 88 | u4 & i 89 | 90 | u8 << b_ 91 | u8 >> b_ 92 | u8 | b_ 93 | u8 ^ b_ 94 | u8 & b_ 95 | 96 | u8 << b 97 | u8 >> b 98 | u8 | b 99 | u8 ^ b 100 | u8 & b 101 | 102 | b_ << b_ 103 | b_ >> b_ 104 | b_ | b_ 105 | b_ ^ b_ 106 | b_ & b_ 107 | 108 | b_ << AR 109 | b_ >> AR 110 | b_ | AR 111 | b_ ^ AR 112 | b_ & AR 113 | 114 | b_ << b 115 | b_ >> b 116 | b_ | b 117 | b_ ^ b 118 | b_ & b 119 | 120 | b_ << i 121 | b_ >> i 122 | b_ | i 123 | b_ ^ i 124 | b_ & i 125 | 126 | ~i8 127 | ~i4 128 | ~u8 129 | ~u4 130 | ~b_ 131 | ~AR 132 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/dtype.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | dtype_obj = np.dtype(np.str_) 4 | void_dtype_obj = np.dtype([("f0", np.float64), ("f1", np.float32)]) 5 | 6 | np.dtype(dtype=np.int64) 7 | np.dtype(int) 8 | np.dtype("int") 9 | np.dtype(None) 10 | 11 | np.dtype((int, 2)) 12 | np.dtype((int, (1,))) 13 | 14 | np.dtype({"names": ["a", "b"], "formats": [int, float]}) 15 | np.dtype({"names": ["a"], "formats": [int], "titles": [object]}) 16 | np.dtype({"names": ["a"], "formats": [int], "titles": [object()]}) 17 | 18 | np.dtype([("name", np.str_, 16), ("grades", np.float64, (2,)), ("age", "int32")]) 19 | 20 | np.dtype({ 21 | "names": ["a", "b"], 22 | "formats": [int, float], 23 | "itemsize": 9, 24 | "aligned": False, 25 | "titles": ["x", "y"], 26 | "offsets": [0, 1], 27 | }) 28 | 29 | np.dtype((np.float64, float)) 30 | 31 | 32 | class Test: 33 | dtype = np.dtype(float) 34 | 35 | 36 | np.dtype(Test()) 37 | 38 | # Methods and attributes 39 | dtype_obj.base 40 | dtype_obj.subdtype 41 | dtype_obj.newbyteorder() 42 | dtype_obj.type 43 | dtype_obj.name 44 | dtype_obj.names 45 | 46 | dtype_obj * 0 47 | dtype_obj * 2 48 | 49 | 0 * dtype_obj 50 | 2 * dtype_obj 51 | 52 | void_dtype_obj["f0"] 53 | void_dtype_obj[0] 54 | void_dtype_obj[["f0", "f1"]] 55 | void_dtype_obj[["f0"]] 56 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/einsumfunc.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from typing import Any 4 | 5 | import numpy as np 6 | 7 | AR_LIKE_b = [True, True, True] 8 | AR_LIKE_u = [np.uint32(1), np.uint32(2), np.uint32(3)] 9 | AR_LIKE_i = [1, 2, 3] 10 | AR_LIKE_f = [1.0, 2.0, 3.0] 11 | AR_LIKE_c = [1j, 2j, 3j] 12 | AR_LIKE_U = ["1", "2", "3"] 13 | 14 | OUT_f: np.ndarray[Any, np.dtype[np.float64]] = np.empty(3, dtype=np.float64) 15 | OUT_c: np.ndarray[Any, np.dtype[np.complex128]] = np.empty(3, dtype=np.complex128) 16 | 17 | np.einsum("i,i->i", AR_LIKE_b, AR_LIKE_b) 18 | np.einsum("i,i->i", AR_LIKE_u, AR_LIKE_u) 19 | np.einsum("i,i->i", AR_LIKE_i, AR_LIKE_i) 20 | np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f) 21 | np.einsum("i,i->i", AR_LIKE_c, AR_LIKE_c) 22 | np.einsum("i,i->i", AR_LIKE_b, AR_LIKE_i) 23 | np.einsum("i,i,i,i->i", AR_LIKE_b, AR_LIKE_u, AR_LIKE_i, AR_LIKE_c) 24 | 25 | np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f, dtype="c16") 26 | np.einsum("i,i->i", AR_LIKE_U, AR_LIKE_U, dtype=bool, casting="unsafe") 27 | np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f, out=OUT_c) 28 | np.einsum("i,i->i", AR_LIKE_U, AR_LIKE_U, dtype=int, casting="unsafe", out=OUT_f) 29 | 30 | np.einsum_path("i,i->i", AR_LIKE_b, AR_LIKE_b) 31 | np.einsum_path("i,i->i", AR_LIKE_u, AR_LIKE_u) 32 | np.einsum_path("i,i->i", AR_LIKE_i, AR_LIKE_i) 33 | np.einsum_path("i,i->i", AR_LIKE_f, AR_LIKE_f) 34 | np.einsum_path("i,i->i", AR_LIKE_c, AR_LIKE_c) 35 | np.einsum_path("i,i->i", AR_LIKE_b, AR_LIKE_i) 36 | np.einsum_path("i,i,i,i->i", AR_LIKE_b, AR_LIKE_u, AR_LIKE_i, AR_LIKE_c) 37 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/flatiter.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a = np.empty((2, 2)).flat 4 | 5 | a.base 6 | a.copy() 7 | a.coords 8 | a.index 9 | iter(a) 10 | next(a) 11 | a[0] 12 | a[[0, 1, 2]] 13 | a[...] 14 | a[:] 15 | a.__array__() 16 | a.__array__(np.dtype(np.float64)) 17 | 18 | if np.__version__ >= "2.3": 19 | b = np.array([1]).flat 20 | a[b] 21 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/index_tricks.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from typing import Any 4 | 5 | import numpy as np 6 | 7 | AR_LIKE_b = [[True, True], [True, True]] 8 | AR_LIKE_i = [[1, 2], [3, 4]] 9 | AR_LIKE_f = [[1.0, 2.0], [3.0, 4.0]] 10 | AR_LIKE_U = [["1", "2"], ["3", "4"]] 11 | 12 | AR_i8: np.ndarray[Any, np.dtype[np.int64]] = np.array(AR_LIKE_i, dtype=np.int64) 13 | 14 | np.ndenumerate(AR_i8) 15 | np.ndenumerate(AR_LIKE_f) 16 | np.ndenumerate(AR_LIKE_U) 17 | 18 | next(np.ndenumerate(AR_i8)) 19 | next(np.ndenumerate(AR_LIKE_f)) 20 | next(np.ndenumerate(AR_LIKE_U)) 21 | 22 | iter(np.ndenumerate(AR_i8)) 23 | iter(np.ndenumerate(AR_LIKE_f)) 24 | iter(np.ndenumerate(AR_LIKE_U)) 25 | 26 | iter(np.ndindex(1, 2, 3)) 27 | next(np.ndindex(1, 2, 3)) 28 | 29 | np.unravel_index([22, 41, 37], (7, 6)) 30 | np.unravel_index([31, 41, 13], (7, 6), order="F") 31 | np.unravel_index(1621, (6, 7, 8, 9)) 32 | 33 | np.ravel_multi_index(AR_LIKE_i, (7, 6)) 34 | np.ravel_multi_index(AR_LIKE_i, (7, 6), order="F") 35 | np.ravel_multi_index(AR_LIKE_i, (4, 6), mode="clip") 36 | np.ravel_multi_index(AR_LIKE_i, (4, 4), mode=("clip", "wrap")) 37 | np.ravel_multi_index((3, 1, 4, 1), (6, 7, 8, 9)) 38 | 39 | np.mgrid[1:1:2] 40 | np.mgrid[1:1:2, None:10] 41 | 42 | np.ogrid[1:1:2] 43 | np.ogrid[1:1:2, None:10] 44 | 45 | np.index_exp[0:1] 46 | np.index_exp[0:1, None:3] 47 | np.index_exp[0, 0:1, ..., [0, 1, 3]] 48 | 49 | np.s_[0:1] 50 | np.s_[0:1, None:3] 51 | np.s_[0, 0:1, ..., [0, 1, 3]] 52 | 53 | np.ix_(AR_LIKE_b[0]) 54 | np.ix_(AR_LIKE_i[0], AR_LIKE_f[0]) 55 | np.ix_(AR_i8[0]) 56 | 57 | np.fill_diagonal(AR_i8, 5) 58 | 59 | np.diag_indices(4) 60 | np.diag_indices(2, 3) 61 | 62 | np.diag_indices_from(AR_i8) 63 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/lib_user_array.py: -------------------------------------------------------------------------------- 1 | """Base on the `if __name__ == "__main__"` test code in `lib/_user_array_impl.py`.""" 2 | 3 | from __future__ import annotations 4 | 5 | from typing import TYPE_CHECKING 6 | 7 | import numpy as np 8 | from numpy.lib.user_array import container 9 | 10 | if TYPE_CHECKING: 11 | import _numtype as _nt 12 | 13 | N = 10_000 14 | W = H = int(N**0.5) 15 | 16 | a: _nt.Array2D[np.int32] 17 | ua: container[_nt.Rank2, np.dtype[np.int32]] 18 | 19 | a = np.arange(N, dtype=np.int32).reshape(W, H) 20 | ua = container(a) 21 | 22 | ua_small: container[_nt.Rank2, np.dtype[np.int32]] = ua[:3, :5] 23 | ua_small[0, 0] = 10 24 | 25 | ua_bool: container[_nt.Rank2, np.dtype[np.bool]] = ua_small > 1 26 | 27 | shape: tuple[int, int] = np.shape(ua) 28 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/lib_utils.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from io import StringIO 4 | 5 | import numpy as np 6 | from numpy.lib import array_utils 7 | 8 | FILE = StringIO() 9 | AR = np.arange(10, dtype=np.float64) 10 | 11 | 12 | def func(a: int) -> bool: 13 | return True 14 | 15 | 16 | array_utils.byte_bounds(AR) 17 | array_utils.byte_bounds(np.float64()) 18 | 19 | np.info(1, output=FILE) 20 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/lib_version.py: -------------------------------------------------------------------------------- 1 | from numpy.lib import NumpyVersion 2 | 3 | version = NumpyVersion("1.8.0") 4 | 5 | version.vstring 6 | version.version 7 | version.major 8 | version.minor 9 | version.bugfix 10 | version.pre_release 11 | version.is_devversion 12 | 13 | # ruff: noqa: PLR0124 14 | 15 | version == version 16 | version != version 17 | version < "1.8.0" 18 | version <= version 19 | version > version 20 | version >= "1.8.0" 21 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/literal.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from functools import partial 4 | from typing import TYPE_CHECKING, Any 5 | 6 | import pytest 7 | 8 | import numpy as np 9 | 10 | if TYPE_CHECKING: 11 | from collections.abc import Callable 12 | 13 | AR = np.array(0) 14 | AR.setflags(write=False) 15 | 16 | KACF = frozenset({None, "K", "A", "C", "F"}) 17 | ACF = frozenset({None, "A", "C", "F"}) 18 | CF = frozenset({None, "C", "F"}) 19 | 20 | order_list: list[tuple[frozenset[str | None], Callable[..., Any]]] = [ 21 | (KACF, partial(np.ndarray.__call__, 1)), 22 | (KACF, AR.tobytes), 23 | (KACF, partial(AR.astype, int)), 24 | (KACF, AR.copy), 25 | (ACF, partial(AR.reshape, 1)), 26 | (KACF, AR.flatten), 27 | (KACF, AR.ravel), 28 | (KACF, partial(np.array, 1)), 29 | (CF, partial(np.zeros, 1)), 30 | (CF, partial(np.ones, 1)), 31 | (CF, partial(np.empty, 1)), 32 | (CF, partial(np.full, 1, 1)), 33 | (KACF, partial(np.zeros_like, AR)), 34 | (KACF, partial(np.ones_like, AR)), 35 | (KACF, partial(np.empty_like, AR)), 36 | (KACF, partial(np.full_like, AR, 1)), 37 | # NOTE: this false false positive caused by a bug in the `functools` mypy plugin 38 | (KACF, partial(np.add, 1, 1)), # type: ignore[misc] 39 | (ACF, partial(np.reshape, AR, 1)), 40 | (KACF, partial(np.ravel, AR)), 41 | (KACF, partial(np.asarray, 1)), 42 | (KACF, partial(np.asanyarray, 1)), 43 | ] 44 | 45 | for order_set, func in order_list: 46 | for order in order_set: 47 | func(order=order) 48 | 49 | invalid_orders = KACF - order_set 50 | for order in invalid_orders: 51 | with pytest.raises(ValueError): # noqa: PT011 52 | func(order=order) 53 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/ma.py: -------------------------------------------------------------------------------- 1 | from typing import Any 2 | 3 | import numpy as np 4 | 5 | m: np.ma.MaskedArray[Any, np.dtype[np.float64]] = np.ma.masked_array( 6 | [1.5, 2, 3], mask=[True, False, True] 7 | ) 8 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/modules.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy import f2py # noqa: ICN003 3 | 4 | np.char 5 | np.ctypeslib 6 | np.emath 7 | np.fft 8 | np.lib 9 | np.linalg 10 | np.ma 11 | np.matrixlib 12 | np.polynomial 13 | np.random 14 | np.rec 15 | np.strings 16 | np.testing 17 | np.version 18 | 19 | np.lib.format 20 | np.lib.mixins 21 | np.lib.scimath 22 | np.lib.stride_tricks 23 | np.lib.array_utils 24 | np.ma.extras 25 | np.polynomial.chebyshev 26 | np.polynomial.hermite 27 | np.polynomial.hermite_e 28 | np.polynomial.laguerre 29 | np.polynomial.legendre 30 | np.polynomial.polynomial 31 | 32 | np.__path__ 33 | np.__version__ 34 | 35 | np.__all__ 36 | np.char.__all__ 37 | np.ctypeslib.__all__ 38 | np.emath.__all__ 39 | np.lib.__all__ 40 | np.ma.__all__ 41 | np.random.__all__ 42 | np.rec.__all__ 43 | np.strings.__all__ 44 | np.testing.__all__ 45 | f2py.__all__ 46 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/multiarray.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import numpy.typing as npt 3 | 4 | AR_f8: npt.NDArray[np.float64] = np.array([1.0]) 5 | AR_i4 = np.array([1], dtype=np.int32) 6 | AR_u1 = np.array([1], dtype=np.uint8) 7 | 8 | AR_LIKE_f = [1.5] 9 | AR_LIKE_i = [1] 10 | 11 | b_f8 = np.broadcast(AR_f8) 12 | b_i4_f8_f8 = np.broadcast(AR_i4, AR_f8, AR_f8) 13 | 14 | next(b_f8) 15 | b_f8.reset() 16 | b_f8.index 17 | b_f8.iters 18 | b_f8.nd 19 | b_f8.ndim 20 | b_f8.numiter 21 | b_f8.shape 22 | b_f8.size 23 | 24 | next(b_i4_f8_f8) 25 | b_i4_f8_f8.reset() 26 | b_i4_f8_f8.ndim 27 | b_i4_f8_f8.index 28 | b_i4_f8_f8.iters 29 | b_i4_f8_f8.nd 30 | b_i4_f8_f8.numiter 31 | b_i4_f8_f8.shape 32 | b_i4_f8_f8.size 33 | 34 | np.inner(AR_f8, AR_i4) 35 | 36 | np.where([True, True, False]) 37 | np.where([True, True, False], 1, 0) 38 | 39 | np.lexsort([0, 1, 2]) 40 | 41 | np.can_cast(np.dtype("i8"), int) 42 | np.can_cast(AR_f8, "f8") 43 | np.can_cast(AR_f8, np.complex128, casting="unsafe") 44 | 45 | np.min_scalar_type([1]) 46 | np.min_scalar_type(AR_f8) 47 | 48 | np.result_type(int, AR_i4) 49 | np.result_type(AR_f8, AR_u1) 50 | np.result_type(AR_f8, np.complex128) 51 | 52 | np.dot(AR_LIKE_f, AR_i4) 53 | np.dot(AR_u1, 1) 54 | np.dot(1.5j, 1) 55 | np.dot(AR_u1, 1, out=AR_f8) 56 | 57 | np.vdot(AR_LIKE_f, AR_i4) 58 | np.vdot(AR_u1, 1) 59 | np.vdot(1.5j, 1) 60 | 61 | np.bincount(AR_i4) 62 | 63 | np.copyto(AR_f8, [1.6]) 64 | 65 | np.putmask(AR_f8, [True], 1.5) 66 | 67 | np.packbits(AR_i4) 68 | np.packbits(AR_u1) 69 | 70 | np.unpackbits(AR_u1) 71 | 72 | np.shares_memory(1, 2) 73 | np.shares_memory(AR_f8, AR_f8, max_work=1) 74 | 75 | np.may_share_memory(1, 2) 76 | np.may_share_memory(AR_f8, AR_f8, max_work=1) 77 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/ndarray_conversion.py: -------------------------------------------------------------------------------- 1 | import os 2 | import tempfile 3 | 4 | import numpy as np 5 | 6 | nd = np.array([[1, 2], [3, 4]]) 7 | scalar_array = np.array(1) 8 | 9 | # item 10 | scalar_array.item() 11 | nd.item(1) 12 | nd.item(0, 1) 13 | nd.item((0, 1)) 14 | 15 | # tobytes 16 | nd.tobytes() 17 | nd.tobytes("C") 18 | nd.tobytes(None) 19 | 20 | # tofile 21 | if os.name != "nt": 22 | with tempfile.NamedTemporaryFile(suffix=".txt") as tmp: 23 | nd.tofile(tmp.name) 24 | nd.tofile(tmp.name, "") 25 | nd.tofile(tmp.name, sep="") 26 | 27 | nd.tofile(tmp.name, "", "%s") 28 | nd.tofile(tmp.name, format="%s") 29 | 30 | nd.tofile(tmp) 31 | 32 | # dump is pretty simple 33 | # dumps is pretty simple 34 | 35 | # astype 36 | nd.astype("float") 37 | nd.astype(float) 38 | 39 | nd.astype(float, "K") 40 | nd.astype(float, order="K") 41 | 42 | nd.astype(float, "K", "unsafe") 43 | nd.astype(float, casting="unsafe") 44 | 45 | nd.astype(float, "K", "unsafe", True) 46 | nd.astype(float, subok=True) 47 | 48 | nd.astype(float, "K", "unsafe", True, True) 49 | nd.astype(float, copy=True) 50 | 51 | # byteswap 52 | nd.byteswap() 53 | nd.byteswap(True) 54 | 55 | # copy 56 | nd.copy() 57 | nd.copy("C") 58 | 59 | # view 60 | nd.view() 61 | nd.view(np.int64) 62 | nd.view(dtype=np.int64) 63 | nd.view(np.int64, np.matrix) 64 | nd.view(type=np.matrix) 65 | 66 | # getfield 67 | complex_array = np.array([[1 + 1j, 0], [0, 1 - 1j]], dtype=np.complex128) 68 | 69 | complex_array.getfield("float") 70 | complex_array.getfield(float) 71 | 72 | complex_array.getfield("float", 8) 73 | complex_array.getfield(float, offset=8) 74 | 75 | # setflags 76 | nd.setflags() 77 | 78 | nd.setflags(True) 79 | nd.setflags(write=True) 80 | 81 | nd.setflags(True, True) 82 | nd.setflags(write=True, align=True) 83 | 84 | nd.setflags(True, True, False) 85 | nd.setflags(write=True, align=True, uic=False) 86 | 87 | # fill is pretty simple 88 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/ndarray_shape_manipulation.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from typing import TYPE_CHECKING, cast 4 | 5 | import numpy as np 6 | 7 | if TYPE_CHECKING: 8 | import _numtype as _nt 9 | 10 | nd1 = cast("np.ndarray[_nt.Shape2, np.dtype[np.intp]]", np.array([[1, 2], [3, 4]])) 11 | 12 | # reshape 13 | nd1.reshape(4) 14 | nd1.reshape(2, 2) 15 | nd1.reshape((2, 2)) 16 | 17 | nd1.reshape((2, 2), order="C") 18 | nd1.reshape(4, order="C") 19 | 20 | # resize 21 | nd1.resize() 22 | nd1.resize(2, 2) 23 | nd1.resize((2, 2)) 24 | 25 | nd1.resize((2, 2), refcheck=True) 26 | nd1.resize(2, 2, refcheck=True) 27 | 28 | nd2 = np.array([[1, 2], [3, 4]]) 29 | 30 | # transpose 31 | nd2.transpose() 32 | nd2.transpose(1, 0) 33 | nd2.transpose((1, 0)) 34 | 35 | # swapaxes 36 | nd2.swapaxes(0, 1) 37 | 38 | # flatten 39 | nd2.flatten() 40 | nd2.flatten("C") 41 | 42 | # ravel 43 | nd2.ravel() 44 | nd2.ravel("C") 45 | 46 | # squeeze 47 | nd2.squeeze() 48 | 49 | nd3 = np.array([[1, 2]]) 50 | nd3.squeeze(0) 51 | 52 | nd4 = np.array([[[1, 2]]]) 53 | nd4.squeeze((0, 1)) 54 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/nditer.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([1]) 4 | np.nditer([arr, None]) 5 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/numeric.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for :mod:`numpy._core.numeric`. 3 | 4 | Does not include tests which fall under ``array_constructors``. 5 | 6 | """ 7 | 8 | from __future__ import annotations 9 | 10 | import numpy as np 11 | import numpy.typing as npt 12 | 13 | 14 | class SubClass(npt.NDArray[np.float64]): ... 15 | 16 | 17 | i8 = np.int64(1) 18 | 19 | A = np.arange(27).reshape(3, 3, 3) 20 | B: list[list[list[int]]] = A.tolist() 21 | C = np.empty((27, 27)).view(SubClass) 22 | 23 | np.count_nonzero(i8) 24 | np.count_nonzero(A) 25 | np.count_nonzero(B) 26 | np.count_nonzero(A, keepdims=True) 27 | np.count_nonzero(A, axis=0) 28 | 29 | np.isfortran(i8) 30 | np.isfortran(A) 31 | 32 | np.argwhere(i8) 33 | np.argwhere(A) 34 | 35 | np.flatnonzero(i8) 36 | np.flatnonzero(A) 37 | 38 | np.correlate(B[0][0], A.ravel(), mode="valid") 39 | np.correlate(A.ravel(), A.ravel(), mode="same") 40 | 41 | np.convolve(B[0][0], A.ravel(), mode="valid") 42 | np.convolve(A.ravel(), A.ravel(), mode="same") 43 | 44 | np.outer(i8, A) 45 | np.outer(B, A) 46 | np.outer(A, A) 47 | np.outer(A, A, out=C) 48 | 49 | np.tensordot(B, A) 50 | np.tensordot(A, A) 51 | np.tensordot(A, A, axes=0) 52 | np.tensordot(A, A, axes=(0, 1)) 53 | 54 | np.isscalar(i8) 55 | np.isscalar(A) 56 | np.isscalar(B) 57 | 58 | np.roll(A, 1) 59 | np.roll(A, (1, 2)) 60 | np.roll(B, 1) 61 | 62 | np.rollaxis(A, 0, 1) 63 | 64 | np.moveaxis(A, 0, 1) 65 | np.moveaxis(A, (0, 1), (1, 2)) 66 | 67 | np.cross(B, A) 68 | np.cross(A, A) 69 | 70 | np.indices([0, 1, 2]) 71 | np.indices([0, 1, 2], sparse=False) 72 | np.indices([0, 1, 2], sparse=True) 73 | 74 | np.binary_repr(1) 75 | 76 | np.base_repr(1) 77 | 78 | np.allclose(i8, A) 79 | np.allclose(B, A) 80 | np.allclose(A, A) 81 | 82 | np.isclose(i8, A) 83 | np.isclose(B, A) 84 | np.isclose(A, A) 85 | 86 | np.array_equal(i8, A) 87 | np.array_equal(B, A) 88 | np.array_equal(A, A) 89 | 90 | np.array_equiv(i8, A) 91 | np.array_equiv(B, A) 92 | np.array_equiv(A, A) 93 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/numerictypes.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | np.isdtype(np.float64, (np.int64, np.float64)) 4 | np.isdtype(np.int64, "signed integer") 5 | 6 | np.issubdtype("S1", np.bytes_) 7 | np.issubdtype(np.float64, np.float32) 8 | 9 | np.ScalarType 10 | np.ScalarType[0] 11 | np.ScalarType[3] 12 | np.ScalarType[8] 13 | np.ScalarType[10] 14 | 15 | np.typecodes["Character"] 16 | np.typecodes["Complex"] 17 | np.typecodes["All"] 18 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/shape.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING, Any, NamedTuple 2 | 3 | import numpy as np 4 | 5 | if TYPE_CHECKING: 6 | import _numtype as _nt 7 | 8 | 9 | # Subtype of tuple[int, int] 10 | class XYGrid(NamedTuple): 11 | x_axis: int 12 | y_axis: int 13 | 14 | 15 | # Test variance of _ShapeType_co 16 | def accepts_2d(a: "np.ndarray[_nt.Shape2, Any]") -> None: 17 | return None 18 | 19 | 20 | accepts_2d(np.empty(XYGrid(2, 2))) 21 | accepts_2d(np.zeros(XYGrid(2, 2), dtype=int)) 22 | accepts_2d(np.ones(XYGrid(2, 2), dtype=int)) 23 | accepts_2d(np.full(XYGrid(2, 2), fill_value=5, dtype=int)) 24 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/simple_py3.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | array = np.array([1, 2]) 4 | 5 | # The @ operator is not in python 2 6 | array @ array 7 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/ufunc_config.py: -------------------------------------------------------------------------------- 1 | """Typing tests for `numpy._core._ufunc_config`.""" 2 | 3 | import numpy as np 4 | 5 | 6 | def func1(a: str, b: int) -> None: 7 | return None 8 | 9 | 10 | def func2(a: str, b: int, c: float = 1.0) -> None: 11 | return None 12 | 13 | 14 | def func3(a: str, b: int) -> int: 15 | return 0 16 | 17 | 18 | # ruff: noqa: PLR6301 19 | 20 | 21 | class Write1: 22 | def write(self, a: str) -> None: 23 | return None 24 | 25 | 26 | class Write2: 27 | def write(self, a: str, b: int = 1) -> None: 28 | return None 29 | 30 | 31 | class Write3: 32 | def write(self, a: str) -> int: 33 | return 0 34 | 35 | 36 | _err_default = np.geterr() 37 | _bufsize_default = np.getbufsize() 38 | _errcall_default = np.geterrcall() 39 | 40 | try: 41 | np.seterr(all=None) 42 | np.seterr(divide="ignore") 43 | np.seterr(over="warn") 44 | np.seterr(under="call") 45 | np.seterr(invalid="raise") 46 | np.geterr() 47 | 48 | np.setbufsize(4096) 49 | np.getbufsize() 50 | 51 | np.seterrcall(func1) 52 | np.seterrcall(func2) 53 | np.seterrcall(func3) 54 | np.seterrcall(Write1()) 55 | np.seterrcall(Write2()) 56 | np.seterrcall(Write3()) 57 | np.geterrcall() 58 | 59 | with np.errstate(call=func1, all="call"): 60 | pass 61 | with np.errstate(call=Write1(), divide="log", over="log"): 62 | pass 63 | 64 | finally: 65 | np.seterr(**_err_default) 66 | np.setbufsize(_bufsize_default) 67 | np.seterrcall(_errcall_default) 68 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/ufunclike.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from typing import Any 4 | 5 | import numpy as np 6 | import numpy.typing as npt 7 | 8 | 9 | class Object: 10 | def __ceil__(self) -> Object: 11 | return self 12 | 13 | def __floor__(self) -> Object: 14 | return self 15 | 16 | def __ge__(self, value: object) -> bool: 17 | return True 18 | 19 | def __array__( 20 | self, dtype: npt.DTypeLike | None = None, copy: bool | None = None 21 | ) -> np.ndarray[Any, np.dtype[np.object_]]: 22 | ret = np.empty((), dtype=object) 23 | ret[()] = self 24 | return ret 25 | 26 | 27 | AR_LIKE_b = [True, True, False] 28 | AR_LIKE_u = [np.uint32(1), np.uint32(2), np.uint32(3)] 29 | AR_LIKE_i = [1, 2, 3] 30 | AR_LIKE_f = [1.0, 2.0, 3.0] 31 | AR_LIKE_O = [Object(), Object(), Object()] 32 | AR_U: np.ndarray[Any, np.dtype[np.str_]] = np.zeros(3, dtype="U5") 33 | 34 | np.fix(AR_LIKE_b) 35 | np.fix(AR_LIKE_u) 36 | np.fix(AR_LIKE_i) 37 | np.fix(AR_LIKE_f) 38 | np.fix(AR_LIKE_O) 39 | np.fix(AR_LIKE_f, out=AR_U) 40 | 41 | np.isposinf(AR_LIKE_b) 42 | np.isposinf(AR_LIKE_u) 43 | np.isposinf(AR_LIKE_i) 44 | np.isposinf(AR_LIKE_f) 45 | np.isposinf(AR_LIKE_f, out=AR_U) 46 | 47 | np.isneginf(AR_LIKE_b) 48 | np.isneginf(AR_LIKE_u) 49 | np.isneginf(AR_LIKE_i) 50 | np.isneginf(AR_LIKE_f) 51 | np.isneginf(AR_LIKE_f, out=AR_U) 52 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/ufuncs.py: -------------------------------------------------------------------------------- 1 | from collections.abc import Callable 2 | 3 | import numpy as np 4 | 5 | np.sin(1) 6 | np.sin([1, 2, 3]) 7 | np.sin(1, out=np.empty(1)) 8 | np.matmul(np.ones((2, 2, 2)), np.ones((2, 2, 2)), axes=[(0, 1), (0, 1), (0, 1)]) 9 | np.sin(1, signature="D->D") 10 | 11 | np.sin(1) + np.sin(1) 12 | np.sin.types[0] 13 | np.sin.__name__ 14 | np.sin.__doc__ 15 | 16 | np.abs(np.array([1])) 17 | 18 | 19 | u11: np.ufunc = np.log 20 | u11_alias: np.ufunc = np.abs 21 | u12: np.ufunc = np.modf 22 | u21: np.ufunc = np.gcd 23 | u22: np.ufunc = np.divmod 24 | gu21: np.ufunc = np.matmul 25 | 26 | f11: Callable[..., object] = np.log 27 | f11_alias: Callable[..., object] = np.abs 28 | f12: Callable[..., object] = np.modf 29 | f21: Callable[..., object] = np.gcd 30 | f22: Callable[..., object] = np.divmod 31 | gf21: Callable[..., object] = np.matmul 32 | 33 | c11: Callable[..., object] = np.log.__call__ 34 | c11_alias: Callable[..., object] = np.abs.__call__ 35 | c12: Callable[..., object] = np.modf.__call__ 36 | c21: Callable[..., object] = np.gcd.__call__ 37 | c22: Callable[..., object] = np.divmod.__call__ 38 | gc21: Callable[..., object] = np.matmul.__call__ 39 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/legacy/warnings_and_errors.py: -------------------------------------------------------------------------------- 1 | import numpy.exceptions as ex 2 | 3 | ex.AxisError("test") 4 | ex.AxisError(1, ndim=2) 5 | ex.AxisError(1, ndim=2, msg_prefix="error") 6 | ex.AxisError(1, ndim=2, msg_prefix=None) 7 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/test_ctype_assumptions.py: -------------------------------------------------------------------------------- 1 | # ruff: noqa: S101, PLR2004 2 | 3 | import ctypes as ct 4 | import sys 5 | 6 | import pytest 7 | 8 | import numpy as np 9 | 10 | WIN32 = sys.platform == "win32" 11 | SIZE_P = ct.sizeof(ct.c_ssize_t) * 8 12 | 13 | 14 | def test_maxsize_32_or_64() -> None: 15 | # assume we're either on a 32 or a 64 bit system 16 | assert SIZE_P in {32, 64} 17 | assert sys.maxsize == (1 << (SIZE_P - 1)) - 1 18 | 19 | 20 | @pytest.mark.parametrize("char", ["q", "Q"]) 21 | def test_longlong_64(char: str) -> None: 22 | assert np.dtype(char).itemsize == 8 23 | assert np.dtype(char).alignment == 8 24 | 25 | 26 | @pytest.mark.parametrize( 27 | ("name_c", "name_expect"), 28 | [ 29 | ("byte", "int8"), 30 | ("short", "int16"), 31 | ("intc", "int32"), 32 | ("long", "int32" if WIN32 else f"int{SIZE_P}"), 33 | ("intp", f"int{SIZE_P}"), 34 | ], 35 | ) 36 | def test_alias_integer(name_c: str, name_expect: str) -> None: 37 | signed_c: type[np.signedinteger] = getattr(np, name_c) 38 | signed_expect: type[np.signedinteger] = getattr(np, name_expect) 39 | assert signed_c is signed_expect 40 | 41 | unsigned_c: type[np.unsignedinteger] = getattr(np, f"u{name_c}") 42 | unsigned_expect: type[np.unsignedinteger] = getattr(np, f"u{name_expect}") 43 | assert unsigned_c is unsigned_expect 44 | 45 | 46 | @pytest.mark.parametrize( 47 | ("name_c", "name_expect"), 48 | [ 49 | ("half", "float16"), 50 | ("single", "float32"), 51 | ("double", "float64"), 52 | ("longdouble", "float96" if WIN32 else f"float{SIZE_P + 64}"), 53 | ], 54 | ) 55 | def test_alias_floating(name_c: str, name_expect: str) -> None: 56 | floating_c: type[np.floating] = getattr(np, name_c) 57 | floating_expect: type[np.floating] = getattr(np, name_expect) 58 | assert floating_c is floating_expect 59 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/runtime/test_runtime.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import sys 3 | from pathlib import Path 4 | 5 | import pytest 6 | 7 | TEST_DIR = Path(__file__).parent 8 | sys.path.insert(0, str(TEST_DIR)) 9 | 10 | 11 | @pytest.mark.parametrize( 12 | "module", 13 | [ 14 | path.stem 15 | for path in (Path(__file__).parent / "legacy").iterdir() 16 | if path.suffix == ".py" and path.stem != "__init__" 17 | ], 18 | ids="test/runtime/legacy/{}.py".format, 19 | ) 20 | def test_legacy(module: str) -> None: 21 | importlib.import_module(f"legacy.{module}") 22 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../.ruff.toml" 2 | line-length = 120 3 | 4 | [lint] 5 | extend-ignore = [ 6 | "PYI015", # flake8-pyi: assignment-default-in-stub 7 | "PYI017", # flake8-pyi: complex-assignment-in-stub 8 | "SLF001", # flake8-self: private-member-access 9 | "PTH123", # flake8-use-pathlib: builtin-open 10 | ] 11 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../.ruff.toml" 2 | 3 | [lint] 4 | extend-ignore = ["PLR0124"] # pylint/R: comparison-with-itself 5 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/README.md: -------------------------------------------------------------------------------- 1 | # Static acceptance type-tests for true negatives 2 | 3 | This mainly relies on `typing_extensions.assert_type`. 4 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/__init__.pyi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numpy/numtype/83c2f491ba44a2de710bb9fbfb763a39833fb934/src/numpy-stubs/@test/static/accept/__init__.pyi -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/arithmetic.pyi: -------------------------------------------------------------------------------- 1 | import datetime as dt 2 | from typing import assert_type 3 | 4 | import _numtype as _nt 5 | import numpy as np 6 | 7 | i: int 8 | i8: np.int64 9 | 10 | M8: np.datetime64 11 | M8_none: np.datetime64[None] 12 | date: dt.date 13 | time: dt.datetime 14 | 15 | m8: np.timedelta64 16 | m8_none: np.timedelta64[None] 17 | m8_int: np.timedelta64[int] 18 | m8_delta: np.timedelta64[dt.timedelta] 19 | delta: dt.timedelta 20 | 21 | AR_Any: _nt.Array 22 | 23 | # Time structures 24 | 25 | assert_type(m8 // m8, np.int64) 26 | assert_type(m8 % m8, np.timedelta64) 27 | assert_type(divmod(m8, m8), tuple[np.int64, np.timedelta64]) 28 | 29 | assert_type(M8_none + m8, np.datetime64[None]) 30 | assert_type(M8_none + i, np.datetime64[None]) 31 | assert_type(M8_none + i8, np.datetime64[None]) 32 | assert_type(M8_none - M8, np.timedelta64[None]) 33 | assert_type(M8_none - m8, np.datetime64[None]) 34 | assert_type(M8_none - i, np.datetime64[None]) 35 | assert_type(M8_none - i8, np.datetime64[None]) 36 | 37 | assert_type(m8_none + m8, np.timedelta64[None]) 38 | assert_type(m8_none + i, np.timedelta64[None]) 39 | assert_type(m8_none + i8, np.timedelta64[None]) 40 | assert_type(m8_none - i, np.timedelta64[None]) 41 | assert_type(m8_none - i8, np.timedelta64[None]) 42 | 43 | assert_type(m8_int + i, np.timedelta64[int]) 44 | assert_type(m8_int + m8_delta, np.timedelta64[int]) 45 | assert_type(m8_int + m8, np.timedelta64[int | None]) 46 | assert_type(m8_int - i, np.timedelta64[int]) 47 | assert_type(m8_int - m8_delta, np.timedelta64[int]) 48 | assert_type(m8_int - m8, np.timedelta64[int | None]) 49 | 50 | assert_type(m8_delta + date, dt.date) 51 | assert_type(m8_delta + time, dt.datetime) 52 | assert_type(m8_delta + delta, dt.timedelta) 53 | assert_type(m8_delta - delta, dt.timedelta) 54 | assert_type(m8_delta / delta, float) 55 | assert_type(m8_delta // delta, int) 56 | assert_type(m8_delta % delta, dt.timedelta) 57 | assert_type(divmod(m8_delta, delta), tuple[int, dt.timedelta]) 58 | 59 | # Any 60 | 61 | assert_type(AR_Any + 2, _nt.Array) 62 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/arraypad.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Mapping 2 | from typing import Any, SupportsIndex, assert_type 3 | 4 | import _numtype as _nt 5 | import numpy as np 6 | 7 | def mode_func( 8 | ar: _nt.Array[np.number], width: tuple[int, int], iaxis: SupportsIndex, kwargs: Mapping[str, Any] 9 | ) -> None: ... 10 | 11 | AR_i8: _nt.Array[np.int64] 12 | AR_f8: _nt.Array[np.float64] 13 | AR_LIKE: list[int] 14 | 15 | assert_type(np.pad(AR_i8, (2, 3), "constant"), _nt.Array[np.int64]) 16 | assert_type(np.pad(AR_LIKE, (2, 3), "constant"), _nt.Array) 17 | 18 | assert_type(np.pad(AR_f8, (2, 3), mode_func), _nt.Array[np.float64]) 19 | assert_type(np.pad(AR_f8, (2, 3), mode_func, a=1, b=2), _nt.Array[np.float64]) 20 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/arrayprint.pyi: -------------------------------------------------------------------------------- 1 | import contextlib 2 | from collections.abc import Callable 3 | from typing import assert_type 4 | 5 | import _numtype as _nt 6 | import numpy as np 7 | from numpy._core.arrayprint import _FormatOptions 8 | 9 | AR: _nt.Array[np.int64] 10 | func_float: Callable[[np.floating], str] 11 | func_int: Callable[[np.integer], str] 12 | 13 | assert_type(np.get_printoptions(), _FormatOptions) 14 | assert_type(np.array2string(AR, formatter={"float_kind": func_float, "int_kind": func_int}), str) 15 | assert_type(np.format_float_scientific(1.0), str) 16 | assert_type(np.format_float_positional(1), str) 17 | assert_type(np.array_repr(AR), str) 18 | assert_type(np.array_str(AR), str) 19 | 20 | assert_type(np.printoptions(), contextlib._GeneratorContextManager[_FormatOptions]) 21 | with np.printoptions() as dct: 22 | assert_type(dct, _FormatOptions) 23 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/arrayterator.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Generator 2 | from typing import assert_type 3 | 4 | import _numtype as _nt 5 | import numpy as np 6 | 7 | AR_i8: _nt.Array[np.int64] 8 | ar_iter: np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]] 9 | 10 | ### 11 | 12 | assert_type(ar_iter.var, _nt.Array[np.int64]) 13 | assert_type(ar_iter.buf_size, int | None) 14 | assert_type(ar_iter.start, list[int]) 15 | assert_type(ar_iter.stop, list[int]) 16 | assert_type(ar_iter.step, list[int]) 17 | assert_type(ar_iter.shape, _nt.AnyShape) 18 | assert_type(ar_iter.flat, Generator[np.int64]) 19 | 20 | assert_type(ar_iter.__array__(), _nt.Array[np.int64]) 21 | 22 | for i in ar_iter: 23 | assert_type(i, _nt.Array[np.int64]) 24 | 25 | assert_type(ar_iter[0], np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]]) 26 | assert_type(ar_iter[...], np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]]) 27 | assert_type(ar_iter[:], np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]]) 28 | assert_type(ar_iter[0, 0, 0], np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]]) 29 | assert_type(ar_iter[..., 0, :], np.lib.Arrayterator[_nt.AnyShape, np.dtype[np.int64]]) 30 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/bitwise_ops.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import numpy as np 4 | 5 | ### 6 | 7 | b1: np.bool 8 | i4: np.int32 9 | u4: np.uint32 10 | i8: np.int64 11 | u8: np.uint64 12 | 13 | ### 14 | 15 | assert_type(~b1, np.bool) 16 | assert_type(~i4, np.int32) 17 | assert_type(~u4, np.uint32) 18 | assert_type(~i8, np.int64) 19 | assert_type(~u8, np.uint64) 20 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/constants.pyi: -------------------------------------------------------------------------------- 1 | from typing import Literal, assert_type 2 | 3 | import numpy as np 4 | 5 | assert_type(np.e, float) 6 | assert_type(np.euler_gamma, float) 7 | assert_type(np.inf, float) 8 | assert_type(np.nan, float) 9 | assert_type(np.pi, float) 10 | 11 | assert_type(np.little_endian, bool) 12 | 13 | assert_type(np.True_, np.bool[Literal[True]]) 14 | assert_type(np.False_, np.bool[Literal[False]]) 15 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/datasource.pyi: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | from typing import IO, Any, assert_type 3 | 4 | import numpy as np 5 | 6 | path1: Path 7 | path2: str 8 | 9 | d1 = np.lib.npyio.DataSource(path1) 10 | d2 = np.lib.npyio.DataSource(path2) 11 | d3 = np.lib.npyio.DataSource(None) 12 | 13 | assert_type(d1.abspath("..."), str) 14 | assert_type(d2.abspath("..."), str) 15 | assert_type(d3.abspath("..."), str) 16 | 17 | assert_type(d1.exists("..."), bool) 18 | assert_type(d2.exists("..."), bool) 19 | assert_type(d3.exists("..."), bool) 20 | 21 | assert_type(d1.open("...", "r"), IO[Any]) 22 | assert_type(d2.open("...", encoding="utf8"), IO[Any]) 23 | assert_type(d3.open("...", newline="/n"), IO[Any]) 24 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/einsumfunc.pyi: -------------------------------------------------------------------------------- 1 | from typing import Any, assert_type 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | AR_LIKE_b: list[bool] 7 | AR_LIKE_u: list[np.uint32] 8 | AR_LIKE_i: list[int] 9 | AR_LIKE_f: list[float] 10 | AR_LIKE_c: list[complex] 11 | AR_LIKE_U: list[str] 12 | AR_o: _nt.Array[np.object_] 13 | 14 | OUT_f: _nt.Array[np.float64] 15 | 16 | assert_type(np.einsum("i,i->i", AR_LIKE_b, AR_LIKE_b), Any) 17 | assert_type(np.einsum("i,i->i", AR_o, AR_o), Any) 18 | assert_type(np.einsum("i,i->i", AR_LIKE_u, AR_LIKE_u), Any) 19 | assert_type(np.einsum("i,i->i", AR_LIKE_i, AR_LIKE_i), Any) 20 | assert_type(np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f), Any) 21 | assert_type(np.einsum("i,i->i", AR_LIKE_c, AR_LIKE_c), Any) 22 | assert_type(np.einsum("i,i->i", AR_LIKE_b, AR_LIKE_i), Any) 23 | assert_type(np.einsum("i,i,i,i->i", AR_LIKE_b, AR_LIKE_u, AR_LIKE_i, AR_LIKE_c), Any) 24 | 25 | assert_type(np.einsum("i,i->i", AR_LIKE_c, AR_LIKE_c, out=OUT_f), _nt.Array[np.float64]) 26 | assert_type(np.einsum("i,i->i", AR_LIKE_U, AR_LIKE_U, dtype=bool, casting="unsafe", out=OUT_f), _nt.Array[np.float64]) 27 | assert_type(np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f, dtype="c16"), Any) 28 | assert_type(np.einsum("i,i->i", AR_LIKE_U, AR_LIKE_U, dtype=bool, casting="unsafe"), Any) 29 | 30 | assert_type(np.einsum_path("i,i->i", AR_LIKE_b, AR_LIKE_b), tuple[list[Any], str]) 31 | assert_type(np.einsum_path("i,i->i", AR_LIKE_u, AR_LIKE_u), tuple[list[Any], str]) 32 | assert_type(np.einsum_path("i,i->i", AR_LIKE_i, AR_LIKE_i), tuple[list[Any], str]) 33 | assert_type(np.einsum_path("i,i->i", AR_LIKE_f, AR_LIKE_f), tuple[list[Any], str]) 34 | assert_type(np.einsum_path("i,i->i", AR_LIKE_c, AR_LIKE_c), tuple[list[Any], str]) 35 | assert_type(np.einsum_path("i,i->i", AR_LIKE_b, AR_LIKE_i), tuple[list[Any], str]) 36 | assert_type(np.einsum_path("i,i,i,i->i", AR_LIKE_b, AR_LIKE_u, AR_LIKE_i, AR_LIKE_c), tuple[list[Any], str]) 37 | 38 | assert_type(np.einsum([[1, 1], [1, 1]], AR_LIKE_i, AR_LIKE_i), Any) 39 | assert_type(np.einsum_path([[1, 1], [1, 1]], AR_LIKE_i, AR_LIKE_i), tuple[list[Any], str]) 40 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/emath.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | AR_f8: _nt.Array[np.float64] 7 | AR_c16: _nt.Array[np.complex128] 8 | f8: np.float64 9 | c16: np.complex128 10 | 11 | assert_type(np.emath.logn(f8, 2), np.inexact) 12 | assert_type(np.emath.logn(AR_f8, 4), _nt.Array[np.inexact]) 13 | assert_type(np.emath.logn(f8, 1j), np.complexfloating) 14 | assert_type(np.emath.logn(AR_c16, 1.5), _nt.Array[np.complexfloating]) 15 | 16 | assert_type(np.emath.power(f8, 2), np.inexact) 17 | assert_type(np.emath.power(AR_f8, 4), _nt.Array[np.inexact]) 18 | assert_type(np.emath.power(f8, 2j), np.complexfloating) 19 | assert_type(np.emath.power(AR_c16, 1.5), _nt.Array[np.complexfloating]) 20 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/flatiter.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | a: np.flatiter[_nt.Array[np.str_]] 7 | a_1d: np.flatiter[_nt.Array1D[np.bytes_]] 8 | 9 | assert_type(a.base, _nt.Array[np.str_]) 10 | assert_type(a.copy(), _nt.Array[np.str_]) 11 | assert_type(a.coords, tuple[int, ...]) 12 | assert_type(a.index, int) 13 | assert_type(iter(a), np.flatiter[_nt.Array[np.str_]]) 14 | assert_type(next(a), np.str_) 15 | assert_type(a[0], np.str_) 16 | assert_type(a[[0, 1, 2]], _nt.Array[np.str_]) 17 | assert_type(a[...], _nt.Array[np.str_]) 18 | assert_type(a[:], _nt.Array[np.str_]) 19 | assert_type(a[...,], _nt.Array[np.str_]) 20 | assert_type(a[0,], np.str_) 21 | 22 | assert_type(a.__array__(), _nt.Array1D[np.str_]) 23 | assert_type(a.__array__(np.dtype(np.float64)), _nt.Array1D[np.float64]) 24 | assert_type(a_1d.__array__(), _nt.Array1D[np.bytes_]) 25 | assert_type(a_1d.__array__(np.dtype(np.float64)), _nt.Array1D[np.float64]) 26 | 27 | a[0] = "a" 28 | a[:5] = "a" 29 | a[...] = "a" 30 | a[...,] = "a" 31 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/getlimits.pyi: -------------------------------------------------------------------------------- 1 | from typing import Literal, assert_type 2 | 3 | import numpy as np 4 | 5 | f: float 6 | f8: np.float64 7 | c8: np.complex64 8 | 9 | i: int 10 | i8: np.int64 11 | u4: np.uint32 12 | 13 | finfo_f8: np.finfo[np.float64] 14 | iinfo_i8: np.iinfo[np.int64] 15 | 16 | assert_type(np.finfo(f), np.finfo[np.float64]) 17 | assert_type(np.finfo(f8), np.finfo[np.float64]) 18 | assert_type(np.finfo(c8), np.finfo[np.float32]) 19 | assert_type(np.finfo("f2"), np.finfo[np.float16]) 20 | 21 | assert_type(finfo_f8.dtype, np.dtype[np.float64]) 22 | assert_type(finfo_f8.bits, Literal[2, 4, 8, 12, 16]) 23 | assert_type(finfo_f8.eps, np.float64) 24 | assert_type(finfo_f8.epsneg, np.float64) 25 | assert_type(finfo_f8.iexp, int) 26 | assert_type(finfo_f8.machep, int) 27 | assert_type(finfo_f8.max, np.float64) 28 | assert_type(finfo_f8.maxexp, int) 29 | assert_type(finfo_f8.min, np.float64) 30 | assert_type(finfo_f8.minexp, int) 31 | assert_type(finfo_f8.negep, int) 32 | assert_type(finfo_f8.nexp, int) 33 | assert_type(finfo_f8.nmant, int) 34 | assert_type(finfo_f8.precision, int) 35 | assert_type(finfo_f8.resolution, np.float64) 36 | assert_type(finfo_f8.tiny, np.float64) 37 | assert_type(finfo_f8.smallest_normal, np.float64) 38 | assert_type(finfo_f8.smallest_subnormal, np.float64) 39 | 40 | assert_type(np.iinfo(i), np.iinfo[np.int_]) 41 | assert_type(np.iinfo(i8), np.iinfo[np.int64]) 42 | assert_type(np.iinfo(u4), np.iinfo[np.uint32]) 43 | assert_type(np.iinfo("i2"), np.iinfo[np.int16]) 44 | 45 | assert_type(iinfo_i8.dtype, np.dtype[np.int64]) 46 | assert_type(iinfo_i8.kind, Literal["i", "u"]) 47 | assert_type(iinfo_i8.bits, Literal[8, 16, 32, 64]) 48 | assert_type(iinfo_i8.key, Literal["i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64"]) 49 | assert_type(iinfo_i8.min, int) 50 | assert_type(iinfo_i8.max, int) 51 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/histograms.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | AR_i8: _nt.Array[np.int64] 7 | AR_f8: _nt.Array[np.float64] 8 | 9 | assert_type(np.histogram_bin_edges(AR_i8, bins="auto"), _nt.Array) 10 | assert_type(np.histogram_bin_edges(AR_i8, bins="rice", range=(0, 3)), _nt.Array) 11 | assert_type(np.histogram_bin_edges(AR_i8, bins="scott", weights=AR_f8), _nt.Array) 12 | 13 | assert_type(np.histogram(AR_i8, bins="auto"), tuple[_nt.Array, _nt.Array]) 14 | assert_type(np.histogram(AR_i8, bins="rice", range=(0, 3)), tuple[_nt.Array, _nt.Array]) 15 | assert_type(np.histogram(AR_i8, bins="scott", weights=AR_f8), tuple[_nt.Array, _nt.Array]) 16 | assert_type(np.histogram(AR_f8, bins=1, density=True), tuple[_nt.Array, _nt.Array]) 17 | 18 | assert_type(np.histogramdd(AR_i8, bins=[1]), tuple[_nt.Array, tuple[_nt.Array, ...]]) 19 | assert_type(np.histogramdd(AR_i8, range=[(0, 3)]), tuple[_nt.Array, tuple[_nt.Array, ...]]) 20 | assert_type(np.histogramdd(AR_i8, weights=AR_f8), tuple[_nt.Array, tuple[_nt.Array, ...]]) 21 | assert_type(np.histogramdd(AR_f8, density=True), tuple[_nt.Array, tuple[_nt.Array, ...]]) 22 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/lib_utils.pyi: -------------------------------------------------------------------------------- 1 | from io import StringIO 2 | from typing import assert_type 3 | 4 | import _numtype as _nt 5 | import numpy as np 6 | from numpy.lib import array_utils 7 | 8 | AR: _nt.Array[np.float64] 9 | AR_DICT: dict[str, _nt.Array[np.float64]] 10 | FILE: StringIO 11 | 12 | def func(a: int) -> bool: ... 13 | 14 | assert_type(array_utils.byte_bounds(AR), tuple[int, int]) 15 | assert_type(array_utils.byte_bounds(np.float64()), tuple[int, int]) 16 | 17 | assert_type(np.info(1, output=FILE), None) 18 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/lib_version.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | from numpy.lib import NumpyVersion 4 | 5 | version = NumpyVersion("1.8.0") 6 | 7 | assert_type(version.vstring, str) 8 | assert_type(version.version, str) 9 | assert_type(version.major, int) 10 | assert_type(version.minor, int) 11 | assert_type(version.bugfix, int) 12 | assert_type(version.pre_release, str) 13 | assert_type(version.is_devversion, bool) 14 | 15 | assert_type(version == version, bool) 16 | assert_type(version != version, bool) 17 | assert_type(version < "1.8.0", bool) 18 | assert_type(version <= version, bool) 19 | assert_type(version > version, bool) 20 | assert_type(version >= "1.8.0", bool) 21 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/ma.pyi: -------------------------------------------------------------------------------- 1 | from typing import TypeAlias, TypeVar, assert_type 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | m: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]] 7 | 8 | assert_type(m.shape, tuple[int]) 9 | 10 | assert_type(m.dtype, np.dtype[np.float64]) 11 | 12 | assert_type(int(m), int) 13 | assert_type(float(m), float) 14 | 15 | _ScalarT_co = TypeVar("_ScalarT_co", bound=np.generic, covariant=True) 16 | MaskedNDArray: TypeAlias = _nt.MArray[_ScalarT_co] 17 | 18 | class MaskedNDArraySubclass(MaskedNDArray[np.complex128]): ... 19 | 20 | MAR_b: MaskedNDArray[np.bool] 21 | MAR_f4: MaskedNDArray[np.float32] 22 | MAR_i8: MaskedNDArray[np.int64] 23 | MAR_subclass: MaskedNDArraySubclass 24 | MAR_1d: _nt.MArray0D 25 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/memmap.pyi: -------------------------------------------------------------------------------- 1 | from typing import Any, Literal, assert_type 2 | 3 | import numpy as np 4 | 5 | memmap_obj: np.memmap[Any, np.dtype[np.str_]] 6 | 7 | assert_type(np.memmap.__array_priority__, float) 8 | assert_type(memmap_obj.__array_priority__, float) 9 | assert_type(memmap_obj.filename, str | None) 10 | assert_type(memmap_obj.offset, int) 11 | assert_type(memmap_obj.mode, Literal["r", "c", "r+", "w+"]) 12 | assert_type(memmap_obj.flush(), None) 13 | 14 | assert_type(np.memmap("file.txt", offset=5), np.memmap[Any, np.dtype[np.uint8]]) 15 | assert_type(np.memmap(b"file.txt", dtype=np.float64, shape=(10, 3)), np.memmap[Any, np.dtype[np.float64]]) 16 | with open("file.txt", "rb") as f: 17 | assert_type(np.memmap(f, dtype=float, order="K"), np.memmap) 18 | assert_type(np.memmap(f, dtype=np.float16), np.memmap[Any, np.dtype[np.float16]]) 19 | assert_type(np.memmap(f, dtype=np.dtypes.StringDType()), np.memmap[Any, np.dtypes.StringDType]) 20 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/modules.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import numpy as np 4 | import numpy.polynomial as npp 5 | from numpy._pytesttester import PytestTester 6 | 7 | assert_type(np.__file__, str) 8 | assert_type(np.char.__file__, str) 9 | assert_type(np.ctypeslib.__file__, str) 10 | assert_type(np.emath.__file__, str) 11 | assert_type(np.fft.__file__, str) 12 | assert_type(np.lib.__file__, str) 13 | assert_type(np.linalg.__file__, str) 14 | assert_type(np.ma.__file__, str) 15 | assert_type(np.matrixlib.__file__, str) 16 | assert_type(np.polynomial.__file__, str) 17 | assert_type(np.random.__file__, str) 18 | assert_type(np.rec.__file__, str) 19 | assert_type(np.testing.__file__, str) 20 | assert_type(np.version.__file__, str) 21 | assert_type(np.exceptions.__file__, str) 22 | assert_type(np.dtypes.__file__, str) 23 | 24 | assert_type(np.lib.format.__file__, str) 25 | assert_type(np.lib.mixins.__file__, str) 26 | assert_type(np.lib.scimath.__file__, str) 27 | assert_type(np.lib.stride_tricks.__file__, str) 28 | assert_type(np.ma.extras.__file__, str) 29 | assert_type(npp.chebyshev.__file__, str) 30 | assert_type(npp.hermite.__file__, str) 31 | assert_type(npp.hermite_e.__file__, str) 32 | assert_type(npp.laguerre.__file__, str) 33 | assert_type(npp.legendre.__file__, str) 34 | assert_type(npp.polynomial.__file__, str) 35 | 36 | assert_type(np.test, PytestTester) 37 | assert_type(np.test.module_name, str) 38 | 39 | assert_type(np.__all__, list[str]) 40 | assert_type(np.char.__all__, list[str]) 41 | assert_type(np.ctypeslib.__all__, list[str]) 42 | assert_type(np.emath.__all__, list[str]) 43 | assert_type(np.lib.__all__, list[str]) 44 | assert_type(np.ma.__all__, list[str]) 45 | assert_type(np.random.__all__, list[str]) 46 | assert_type(np.rec.__all__, list[str]) 47 | assert_type(np.testing.__all__, list[str]) 48 | assert_type(np.f2py.__all__, list[str]) 49 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/ndarray_shape_manipulation.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | nd: _nt.Array[np.int64] 7 | 8 | # reshape 9 | assert_type(nd.reshape(None), _nt.Array[np.int64]) 10 | assert_type(nd.reshape(4), _nt.Array1D[np.int64]) 11 | assert_type(nd.reshape((4,)), _nt.Array1D[np.int64]) 12 | assert_type(nd.reshape(2, 2), _nt.Array2D[np.int64]) 13 | assert_type(nd.reshape((2, 2)), _nt.Array2D[np.int64]) 14 | assert_type(nd.reshape((2, 2), order="C"), _nt.Array2D[np.int64]) 15 | assert_type(nd.reshape(4, order="C"), _nt.Array1D[np.int64]) 16 | 17 | # resize does not return a value 18 | 19 | # transpose 20 | assert_type(nd.transpose(), _nt.Array[np.int64]) 21 | assert_type(nd.transpose(1, 0), _nt.Array[np.int64]) 22 | assert_type(nd.transpose((1, 0)), _nt.Array[np.int64]) 23 | 24 | # swapaxes 25 | assert_type(nd.swapaxes(0, 1), _nt.Array[np.int64]) 26 | 27 | # flatten 28 | assert_type(nd.flatten(), _nt.Array1D[np.int64]) 29 | assert_type(nd.flatten("C"), _nt.Array1D[np.int64]) 30 | 31 | # ravel 32 | assert_type(nd.ravel(), _nt.Array1D[np.int64]) 33 | assert_type(nd.ravel("C"), _nt.Array1D[np.int64]) 34 | 35 | # squeeze 36 | assert_type(nd.squeeze(), _nt.Array[np.int64]) 37 | assert_type(nd.squeeze(0), _nt.Array[np.int64]) 38 | assert_type(nd.squeeze((0, 2)), _nt.Array[np.int64]) 39 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/nditer.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | nditer_obj: np.nditer 7 | 8 | assert_type(np.nditer([0, 1], flags=["c_index"]), np.nditer) 9 | assert_type(np.nditer([0, 1], op_flags=[["readonly", "readonly"]]), np.nditer) 10 | assert_type(np.nditer([0, 1], op_dtypes=np.int_), np.nditer) 11 | assert_type(np.nditer([0, 1], order="C", casting="no"), np.nditer) 12 | 13 | assert_type(nditer_obj.dtypes, tuple[np.dtype, ...]) 14 | assert_type(nditer_obj.finished, bool) 15 | assert_type(nditer_obj.has_delayed_bufalloc, bool) 16 | assert_type(nditer_obj.has_index, bool) 17 | assert_type(nditer_obj.has_multi_index, bool) 18 | assert_type(nditer_obj.index, int) 19 | assert_type(nditer_obj.iterationneedsapi, bool) 20 | assert_type(nditer_obj.iterindex, int) 21 | assert_type(nditer_obj.iterrange, tuple[int, ...]) 22 | assert_type(nditer_obj.itersize, int) 23 | assert_type(nditer_obj.itviews, tuple[_nt.Array, ...]) 24 | assert_type(nditer_obj.multi_index, tuple[int, ...]) 25 | assert_type(nditer_obj.ndim, int) 26 | assert_type(nditer_obj.nop, int) 27 | assert_type(nditer_obj.operands, tuple[_nt.Array, ...]) 28 | assert_type(nditer_obj.shape, tuple[int, ...]) 29 | assert_type(nditer_obj.value, tuple[_nt.Array, ...]) 30 | 31 | assert_type(nditer_obj.close(), None) 32 | assert_type(nditer_obj.copy(), np.nditer) 33 | assert_type(nditer_obj.debug_print(), None) 34 | assert_type(nditer_obj.enable_external_loop(), None) 35 | assert_type(nditer_obj.iternext(), bool) 36 | assert_type(nditer_obj.remove_axis(0), None) 37 | assert_type(nditer_obj.remove_multi_index(), None) 38 | assert_type(nditer_obj.reset(), None) 39 | 40 | assert_type(len(nditer_obj), int) 41 | assert_type(iter(nditer_obj), np.nditer) 42 | assert_type(next(nditer_obj), tuple[_nt.Array, ...]) 43 | assert_type(nditer_obj.__copy__(), np.nditer) # noqa: PLC2801 44 | with nditer_obj as f: 45 | assert_type(f, np.nditer) 46 | assert_type(nditer_obj[0], _nt.Array) 47 | assert_type(nditer_obj[:], tuple[_nt.Array, ...]) 48 | nditer_obj[0] = 0 49 | nditer_obj[:] = [0, 1] 50 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/nested_sequence.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Sequence 2 | from typing import Any, assert_type 3 | 4 | from numpy._typing import _NestedSequence 5 | 6 | a: Sequence[int] 7 | b: Sequence[Sequence[int]] 8 | c: Sequence[Sequence[Sequence[int]]] 9 | d: Sequence[Sequence[Sequence[Sequence[int]]]] 10 | e: Sequence[bool] 11 | f: tuple[int, ...] 12 | g: list[int] 13 | h: Sequence[Any] 14 | 15 | def func(a: _NestedSequence[int]) -> None: ... 16 | 17 | assert_type(func(a), None) 18 | assert_type(func(b), None) 19 | assert_type(func(c), None) 20 | assert_type(func(d), None) 21 | assert_type(func(e), None) 22 | assert_type(func(f), None) 23 | assert_type(func(g), None) 24 | assert_type(func(h), None) 25 | assert_type(func(range(15)), None) 26 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/numerictypes.pyi: -------------------------------------------------------------------------------- 1 | from typing import Literal, assert_type 2 | 3 | import numpy as np 4 | 5 | assert_type( 6 | np.ScalarType, 7 | tuple[ 8 | type[int], 9 | type[float], 10 | type[complex], 11 | type[bool], 12 | type[bytes], 13 | type[str], 14 | type[memoryview], 15 | type[np.bool], 16 | type[np.csingle], 17 | type[np.cdouble], 18 | type[np.clongdouble], 19 | type[np.half], 20 | type[np.single], 21 | type[np.double], 22 | type[np.longdouble], 23 | type[np.byte], 24 | type[np.short], 25 | type[np.intc], 26 | type[np.long], 27 | type[np.longlong], 28 | type[np.timedelta64], 29 | type[np.datetime64], 30 | type[np.object_], 31 | type[np.bytes_], 32 | type[np.str_], 33 | type[np.ubyte], 34 | type[np.ushort], 35 | type[np.uintc], 36 | type[np.ulong], 37 | type[np.ulonglong], 38 | type[np.void], 39 | ], 40 | ) 41 | assert_type(np.ScalarType[0], type[int]) 42 | assert_type(np.ScalarType[3], type[bool]) 43 | assert_type(np.ScalarType[8], type[np.csingle]) 44 | assert_type(np.ScalarType[10], type[np.clongdouble]) 45 | assert_type(np.bool_(object()), np.bool) 46 | 47 | assert_type(np.typecodes["Character"], Literal["c"]) 48 | assert_type(np.typecodes["Complex"], Literal["FDG"]) 49 | assert_type(np.typecodes["All"], Literal["?bhilqnpBHILQNPefdgFDGSUVOMm"]) 50 | 51 | assert_type(np.sctypeDict["uint8"], type[np.generic]) 52 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/shape.pyi: -------------------------------------------------------------------------------- 1 | from typing import Any, NamedTuple, assert_type 2 | 3 | import numpy as np 4 | 5 | # Subtype of tuple[int, int] 6 | class XYGrid(NamedTuple): 7 | x_axis: int 8 | y_axis: int 9 | 10 | arr: np.ndarray[XYGrid, Any] 11 | 12 | # NOTE(jorenham): mypy 1.15 ignores the typevar constraints, and incorrectly infers `XYGrid`` 13 | assert_type(arr.shape, tuple[int, int]) # type: ignore[assert-type] 14 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/shape_base.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | i8: np.int64 7 | f8: np.float64 8 | 9 | AR_b: _nt.Array[np.bool] 10 | AR_i8: _nt.Array[np.int64] 11 | AR_f8: _nt.Array[np.float64] 12 | 13 | AR_LIKE_f8: list[float] 14 | 15 | assert_type(np.take_along_axis(AR_f8, AR_i8, axis=1), _nt.Array[np.float64]) 16 | assert_type(np.take_along_axis(f8, AR_i8, axis=None), _nt.Array[np.float64]) 17 | 18 | assert_type(np.put_along_axis(AR_f8, AR_i8, "1.0", axis=1), None) 19 | 20 | assert_type(np.expand_dims(AR_i8, 2), _nt.Array[np.int64]) 21 | assert_type(np.expand_dims(AR_LIKE_f8, 2), _nt.Array) 22 | 23 | assert_type(np.column_stack([AR_i8]), _nt.Array[np.int64]) 24 | assert_type(np.column_stack([AR_LIKE_f8]), _nt.Array) 25 | 26 | assert_type(np.dstack([AR_i8]), _nt.Array[np.int64]) 27 | assert_type(np.dstack([AR_LIKE_f8]), _nt.Array) 28 | 29 | assert_type(np.array_split(AR_i8, [3, 5, 6, 10]), list[_nt.Array[np.int64]]) 30 | assert_type(np.array_split(AR_LIKE_f8, [3, 5, 6, 10]), list[_nt.Array]) 31 | 32 | assert_type(np.split(AR_i8, [3, 5, 6, 10]), list[_nt.Array[np.int64]]) 33 | assert_type(np.split(AR_LIKE_f8, [3, 5, 6, 10]), list[_nt.Array]) 34 | 35 | assert_type(np.hsplit(AR_i8, [3, 5, 6, 10]), list[_nt.Array[np.int64]]) 36 | assert_type(np.hsplit(AR_LIKE_f8, [3, 5, 6, 10]), list[_nt.Array]) 37 | 38 | assert_type(np.vsplit(AR_i8, [3, 5, 6, 10]), list[_nt.Array[np.int64]]) 39 | assert_type(np.vsplit(AR_LIKE_f8, [3, 5, 6, 10]), list[_nt.Array]) 40 | 41 | assert_type(np.dsplit(AR_i8, [3, 5, 6, 10]), list[_nt.Array[np.int64]]) 42 | assert_type(np.dsplit(AR_LIKE_f8, [3, 5, 6, 10]), list[_nt.Array]) 43 | 44 | assert_type(np.kron(AR_b, AR_b), _nt.Array[np.bool]) 45 | assert_type(np.kron(AR_b, AR_i8), _nt.Array[np.signedinteger]) 46 | assert_type(np.kron(AR_f8, AR_f8), _nt.Array[np.floating]) 47 | 48 | assert_type(np.tile(AR_i8, 5), _nt.Array[np.int64]) 49 | assert_type(np.tile(AR_LIKE_f8, [2, 2]), _nt.Array) 50 | 51 | assert_type(np.unstack(AR_i8, axis=0), tuple[_nt.Array[np.int64], ...]) 52 | assert_type(np.unstack(AR_LIKE_f8, axis=0), tuple[_nt.Array, ...]) 53 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/stride_tricks.pyi: -------------------------------------------------------------------------------- 1 | from typing import Any, assert_type 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | AR_f8: _nt.Array[np.float64] 7 | AR_LIKE_f: list[float] 8 | interface_dict: dict[str, Any] 9 | 10 | assert_type(np.lib.stride_tricks.as_strided(AR_f8), _nt.Array[np.float64]) 11 | assert_type(np.lib.stride_tricks.as_strided(AR_LIKE_f), _nt.Array) 12 | assert_type(np.lib.stride_tricks.as_strided(AR_f8, strides=(1, 5)), _nt.Array[np.float64]) 13 | assert_type(np.lib.stride_tricks.as_strided(AR_f8, shape=[9, 20]), _nt.Array[np.float64]) 14 | 15 | assert_type(np.lib.stride_tricks.sliding_window_view(AR_f8, 5), _nt.Array[np.float64]) 16 | assert_type(np.lib.stride_tricks.sliding_window_view(AR_LIKE_f, (1, 5)), _nt.Array) 17 | assert_type(np.lib.stride_tricks.sliding_window_view(AR_f8, [9], axis=1), _nt.Array[np.float64]) 18 | 19 | assert_type(np.broadcast_to(AR_f8, 5), _nt.Array[np.float64]) 20 | assert_type(np.broadcast_to(AR_LIKE_f, (1, 5)), _nt.Array) 21 | assert_type(np.broadcast_to(AR_f8, [4, 6], subok=True), _nt.Array[np.float64]) 22 | 23 | assert_type(np.broadcast_shapes((1, 2), [3, 1], (3, 2)), tuple[int, ...]) 24 | assert_type(np.broadcast_shapes((6, 7), (5, 6, 1), 7, (5, 1, 7)), tuple[int, ...]) 25 | 26 | assert_type(np.broadcast_arrays(AR_f8, AR_f8), tuple[_nt.Array, ...]) 27 | assert_type(np.broadcast_arrays(AR_f8, AR_LIKE_f), tuple[_nt.Array, ...]) 28 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/ufunc_config.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import SupportsWrite 2 | from collections.abc import Callable 3 | from typing import Any, assert_type 4 | 5 | import numpy as np 6 | from numpy._core._ufunc_config import _ErrDict 7 | 8 | def func(a: str, b: int) -> None: ... 9 | 10 | class Write: 11 | def write(self, value: str) -> None: ... 12 | 13 | assert_type(np.seterr(all=None), _ErrDict) 14 | assert_type(np.seterr(divide="ignore"), _ErrDict) 15 | assert_type(np.seterr(over="warn"), _ErrDict) 16 | assert_type(np.seterr(under="call"), _ErrDict) 17 | assert_type(np.seterr(invalid="raise"), _ErrDict) 18 | assert_type(np.geterr(), _ErrDict) 19 | 20 | assert_type(np.setbufsize(4096), int) 21 | assert_type(np.getbufsize(), int) 22 | 23 | assert_type(np.seterrcall(func), Callable[[str, int], Any] | SupportsWrite[str] | None) 24 | assert_type(np.seterrcall(Write()), Callable[[str, int], Any] | SupportsWrite[str] | None) 25 | assert_type(np.geterrcall(), Callable[[str, int], Any] | SupportsWrite[str] | None) 26 | 27 | assert_type(np.errstate(call=func, all="call"), np.errstate) 28 | assert_type(np.errstate(call=Write(), divide="log", over="log"), np.errstate) 29 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/ufunclike.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | AR_u4: _nt.Array[np.uint32] 7 | AR_U: _nt.Array[np.str_] 8 | AR_LIKE_b: list[bool] 9 | AR_LIKE_i: list[int] 10 | AR_LIKE_f: list[float] 11 | 12 | ### 13 | 14 | assert_type(np.fix(AR_u4), _nt.Array[np.uint32]) 15 | assert_type(np.fix(AR_LIKE_b), _nt.Array[np.bool]) 16 | assert_type(np.fix(AR_LIKE_i), _nt.Array[np.intp]) 17 | assert_type(np.fix(AR_LIKE_f), _nt.Array[np.float64]) 18 | assert_type(np.fix(AR_LIKE_f, out=AR_U), _nt.Array[np.str_]) 19 | 20 | assert_type(np.isposinf(AR_u4), _nt.Array[np.bool]) 21 | assert_type(np.isposinf(AR_LIKE_b), _nt.Array1D[np.bool]) 22 | assert_type(np.isposinf(AR_LIKE_i), _nt.Array1D[np.bool]) 23 | assert_type(np.isposinf(AR_LIKE_f), _nt.Array1D[np.bool]) 24 | assert_type(np.isposinf(AR_LIKE_f, out=AR_U), _nt.Array[np.str_]) 25 | 26 | assert_type(np.isneginf(AR_u4), _nt.Array[np.bool]) 27 | assert_type(np.isneginf(AR_LIKE_b), _nt.Array1D[np.bool]) 28 | assert_type(np.isneginf(AR_LIKE_i), _nt.Array1D[np.bool]) 29 | assert_type(np.isneginf(AR_LIKE_f), _nt.Array1D[np.bool]) 30 | assert_type(np.isneginf(AR_LIKE_f, out=AR_U), _nt.Array[np.str_]) 31 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/accept/warnings_and_errors.pyi: -------------------------------------------------------------------------------- 1 | from typing import assert_type 2 | 3 | import numpy.exceptions as ex 4 | 5 | assert_type(ex.ModuleDeprecationWarning(), ex.ModuleDeprecationWarning) 6 | assert_type(ex.VisibleDeprecationWarning(), ex.VisibleDeprecationWarning) 7 | assert_type(ex.ComplexWarning(), ex.ComplexWarning) 8 | assert_type(ex.RankWarning(), ex.RankWarning) 9 | assert_type(ex.TooHardError(), ex.TooHardError) 10 | assert_type(ex.AxisError("test"), ex.AxisError) 11 | assert_type(ex.AxisError(5, 1), ex.AxisError) 12 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../.ruff.toml" 2 | builtins = ["reveal_type"] 3 | 4 | [lint] 5 | extend-ignore = ["B015", "B018"] # flake8-bugbear: useless-{comparison,expression} 6 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/README.md: -------------------------------------------------------------------------------- 1 | # Static rejection type-tests for true positives 2 | 3 | For (based)mypy, this requires the `ignore-without-code` error code and the `warn_unused_ignores` 4 | setting to be enabled. 5 | For (based)pyright, the `enableTypeIgnoreComments` and `reportUnnecessaryTypeIgnoreComment` rules 6 | must be enabled. 7 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/__init__.pyi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numpy/numtype/83c2f491ba44a2de710bb9fbfb763a39833fb934/src/numpy-stubs/@test/static/reject/__init__.pyi -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/array_like.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy._typing import ArrayLike 3 | 4 | class A: ... 5 | 6 | x1: ArrayLike = (i for i in range(10)) # type: ignore[assignment] # pyright: ignore[reportAssignmentType] 7 | x2: ArrayLike = A() # type: ignore[assignment] # pyright: ignore[reportAssignmentType] 8 | x3: ArrayLike = {1: "foo", 2: "bar"} # type: ignore[assignment] # pyright: ignore[reportAssignmentType] 9 | 10 | scalar = np.int64(1) 11 | scalar.__array__(dtype=np.float64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 12 | array = np.array([1]) 13 | array.__array__(dtype=np.float64) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 14 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/array_pad.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | AR_i8: _nt.Array[np.int64] 5 | 6 | np.pad(AR_i8, 2, mode="bob") # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 7 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/arrayprint.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Callable 2 | from typing import Any 3 | 4 | import _numtype as _nt 5 | import numpy as np 6 | 7 | AR: _nt.Array[np.float64] 8 | func1: Callable[[Any], str] 9 | func2: Callable[[np.integer], str] 10 | 11 | np.array2string(AR, style=None) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 12 | np.array2string(AR, legacy="1.14") # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 13 | np.array2string(AR, sign="*") # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 14 | np.array2string(AR, floatmode="default") # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 15 | np.array2string(AR, formatter={"A": func1}) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 16 | np.array2string(AR, formatter={"float": func2}) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 17 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/arrayterator.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | AR_i8: _nt.Array[np.int64] 5 | ar_iter = np.lib.Arrayterator(AR_i8) 6 | 7 | np.lib.Arrayterator(np.int64()) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 8 | ar_iter.shape = (10, 5) # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] 9 | ar_iter[None] # type: ignore[index] # pyright: ignore[reportArgumentType] 10 | ar_iter[None, 1] # type: ignore[index] # pyright: ignore[reportArgumentType] 11 | ar_iter[np.intp()] # type: ignore[index] # pyright: ignore[reportArgumentType] 12 | ar_iter[np.intp(), ...] # type: ignore[index] # pyright: ignore[reportArgumentType] 13 | ar_iter[AR_i8] # type: ignore[index] # pyright: ignore[reportArgumentType] 14 | ar_iter[AR_i8, :] # type: ignore[index] # pyright: ignore[reportArgumentType] 15 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/bitwise_ops.pyi: -------------------------------------------------------------------------------- 1 | from typing import Final 2 | 3 | import numpy as np 4 | 5 | i0: Final[int] = ... 6 | 7 | b1: Final[np.bool] = ... 8 | i4: Final[np.int32] = ... 9 | i8: Final[np.int64] = ... 10 | u8: Final[np.uint64] = ... 11 | f8: Final[np.float64] = ... 12 | 13 | ### 14 | 15 | # TODO: Certain mixes like i4 << u8 go to float and thus should fail 16 | 17 | ~f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 18 | 19 | b1 >> f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 20 | f8 >> b1 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 21 | 22 | i8 << f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 23 | f8 << i8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 24 | 25 | f8 | i0 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 26 | i0 | f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 27 | 28 | f8 ^ i8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 29 | i8 ^ f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 30 | 31 | f8 & u8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 32 | u8 & f8 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 33 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/comparisons.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | AR_i: _nt.Array[np.int_] 5 | AR_f: _nt.Array[np.float64] 6 | AR_c: _nt.Array[np.complex128] 7 | AR_M: _nt.Array[np.datetime64] 8 | AR_m: _nt.Array[np.timedelta64] 9 | 10 | ### 11 | 12 | AR_i > AR_M # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 13 | AR_i > "" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 14 | AR_i > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 15 | 16 | AR_f > AR_M # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 17 | AR_f > AR_m # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 18 | AR_f > "" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 19 | AR_f > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 20 | 21 | AR_c > AR_m # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 22 | AR_c > AR_M # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 23 | AR_c > "" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 24 | AR_c > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 25 | 26 | AR_m > AR_f # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 27 | AR_m > AR_c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 28 | AR_m > AR_M # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 29 | AR_m > "" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 30 | AR_m > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 31 | 32 | # ruff: noqa: SIM300 # (flake8-simplify: yoda-conditions) 33 | 34 | AR_M > AR_i # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 35 | AR_M > AR_f # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 36 | AR_M > AR_c # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 37 | AR_M > AR_m # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 38 | AR_M > "" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 39 | AR_M > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 40 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/constants.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | np.little_endian = False # type: ignore[misc] 4 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/datasource.pyi: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import numpy as np 4 | 5 | path: Path 6 | d1: np.lib.npyio.DataSource 7 | 8 | d1.abspath(path) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 9 | d1.abspath(b"...") # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 10 | 11 | d1.exists(path) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 12 | d1.exists(b"...") # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 13 | 14 | d1.open(path, "r") # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 15 | d1.open(b"...", encoding="utf8") # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 16 | d1.open(None, newline="/n") # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 17 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/dtype.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | ### 4 | 5 | class Test1: 6 | not_dtype: np.dtype[np.float64] 7 | 8 | class Test2: 9 | dtype: type[float] 10 | 11 | ### 12 | 13 | t1: Test1 14 | t2: Test2 15 | t3: dict[str, tuple[type[int | float], int]] 16 | 17 | ### 18 | 19 | np.dtype(t1) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 20 | np.dtype(t2) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 21 | np.dtype(t3) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 22 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/einsumfunc.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | ### 5 | 6 | AR_i: _nt.Array[np.int64] 7 | AR_f: _nt.Array[np.float64] 8 | AR_m: _nt.Array[np.timedelta64] 9 | AR_U: _nt.Array[np.str_] 10 | 11 | ### 12 | 13 | np.einsum("i,i->i", AR_i, AR_m) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 14 | np.einsum("i,i->i", AR_f, AR_f, dtype=np.int32) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 15 | np.einsum("i,i->i", AR_i, AR_i, out=AR_U) # type: ignore[type-var] # pyright: ignore[reportArgumentType, reportCallIssue] 16 | np.einsum("i,i->i", AR_i, AR_i, out=AR_U, casting="unsafe") # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 17 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/flatiter.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | class Index: 5 | def __index__(self) -> int: ... 6 | 7 | ix: Index 8 | a: np.flatiter[_nt.Array[np.float64]] 9 | supports_array: _nt.CanArrayND[np.float64] 10 | 11 | ### 12 | 13 | a.base = int # type: ignore[assignment, misc] # pyright: ignore[reportAttributeAccessIssue] 14 | a.coords = () # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] 15 | a.index = 0 # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] 16 | 17 | a.copy(order="C") # type: ignore[call-arg] # pyright: ignore[reportCallIssue] 18 | 19 | a[np.True_] # type: ignore[index] # pyright: ignore[reportArgumentType, reportCallIssue] 20 | a[ix] # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 21 | a[supports_array] # type: ignore[index] # pyright: ignore[reportArgumentType, reportCallIssue] 22 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/histograms.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | AR_i8: _nt.Array[np.int64] 5 | AR_f8: _nt.Array[np.float64] 6 | 7 | np.histogram_bin_edges(AR_i8, range=(0, 1, 2)) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 8 | 9 | np.histogram(AR_i8, range=(0, 1, 2)) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 10 | 11 | np.histogramdd(AR_i8, range=(0, 1)) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 12 | np.histogramdd(AR_i8, range=[(0, 1, 2)]) # type: ignore[list-item] # pyright: ignore[reportArgumentType] 13 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/index_tricks.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | AR_LIKE_i: list[int] 4 | AR_LIKE_f: list[float] 5 | 6 | np.fill_diagonal(AR_LIKE_f, 2) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 7 | np.diag_indices(1.0) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 8 | 9 | np.ndindex([1, 2, 3]) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 10 | np.unravel_index(AR_LIKE_f, (1, 2, 3)) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 11 | np.ravel_multi_index( # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 12 | AR_LIKE_i, 13 | (1, 2, 3), 14 | mode="bob", # pyright: ignore[reportArgumentType] 15 | ) 16 | 17 | np.mgrid[1] # type: ignore[index] # pyright: ignore[reportArgumentType] 18 | np.mgrid[...] # type: ignore[index] # pyright: ignore[reportArgumentType] 19 | 20 | np.ogrid[1] # type: ignore[index] # pyright: ignore[reportArgumentType] 21 | np.ogrid[...] # type: ignore[index] # pyright: ignore[reportArgumentType] 22 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/lib_polynomial.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | AR_f8: _nt.Array[np.float64] 5 | AR_c16: _nt.Array[np.complex128] 6 | AR_O: _nt.Array[np.object_] 7 | AR_U: _nt.Array[np.str_] 8 | 9 | poly_obj: np.poly1d 10 | 11 | ### 12 | 13 | 5**poly_obj # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 14 | 15 | np.polymul(AR_f8, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 16 | np.polydiv(AR_f8, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 17 | 18 | np.polyint(AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 19 | np.polyint(AR_f8, m=1j) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 20 | 21 | np.polyder(AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 22 | np.polyder(AR_f8, m=1j) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 23 | 24 | np.polyfit(AR_O, AR_f8, 1) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 25 | np.polyfit(AR_f8, AR_f8, 1, rcond=1j) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 26 | np.polyfit(AR_f8, AR_f8, 1, w=AR_c16) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 27 | np.polyfit(AR_f8, AR_f8, 1, cov="bob") # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 28 | 29 | np.polyval(AR_f8, AR_U) # type: ignore[misc] # pyright: ignore[reportArgumentType, reportCallIssue] 30 | np.polyadd(AR_f8, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 31 | np.polysub(AR_f8, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 32 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/lib_utils.pyi: -------------------------------------------------------------------------------- 1 | from numpy.lib import array_utils 2 | 3 | array_utils.byte_bounds(1) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 4 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/lib_version.pyi: -------------------------------------------------------------------------------- 1 | from numpy.lib import NumpyVersion 2 | 3 | version: NumpyVersion 4 | 5 | version >= b"1.8.0" # type: ignore[operator] # pyright: ignore[reportOperatorIssue] 6 | NumpyVersion(b"1.8.0") # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 7 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/ma.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | m: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]] 4 | 5 | m.shape = (3, 1) # type: ignore[assignment] 6 | m.dtype = np.bool # type: ignore[assignment, misc] # pyright: ignore[reportAttributeAccessIssue] 7 | 8 | np.amin(m, axis=1.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 9 | np.amin(m, keepdims=1.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 10 | np.amin(m, out=1.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 11 | np.amin(m, fill_value=lambda x: 27) # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportUnknownLambdaType] 12 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/memmap.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | with open("file.txt", encoding="utf-8") as f: 4 | np.memmap(f) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 5 | 6 | np.memmap("test.txt", shape=[10, 5]) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 7 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/modules.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | np.bob # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue, reportUnknownMemberType] 4 | np.testing.bob # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue, reportUnknownMemberType] 5 | 6 | # Stdlib modules in the namespace by accident 7 | np.warnings # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue, reportUnknownMemberType] 8 | np.sys # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue, reportUnknownMemberType] 9 | np.os # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue, reportUnknownMemberType] 10 | np.math # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue, reportUnknownMemberType] 11 | 12 | np.__deprecated_attrs__ # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue, reportUnknownMemberType] 13 | np.__expired_functions__ # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue, reportUnknownMemberType] 14 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/ndarray.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | AR_f8: _nt.Array[np.float64] 5 | 6 | ### 7 | 8 | AR_f8.dtype = np.bool # type: ignore[assignment, misc] # pyright: ignore[reportAttributeAccessIssue] 9 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/nditer.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | class Test(np.nditer): ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] 4 | 5 | np.nditer([0, 1], flags=["test"]) # type: ignore[list-item] # pyright: ignore[reportArgumentType] 6 | np.nditer([0, 1], op_flags=[["test"]]) # type: ignore[list-item] # pyright: ignore[reportArgumentType] 7 | np.nditer([0, 1], itershape=(1.0,)) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 8 | np.nditer([0, 1], buffersize=1.0) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 9 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/nested_sequence.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Sequence 2 | 3 | from numpy._typing import _NestedSequence 4 | 5 | a: Sequence[float] 6 | b: list[complex] 7 | c: tuple[str, ...] 8 | d: int 9 | e: str 10 | 11 | def func(a: _NestedSequence[int]) -> None: ... 12 | 13 | func(a) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 14 | func(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 15 | func(c) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 16 | func(d) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 17 | func(e) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 18 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/npyio.pyi: -------------------------------------------------------------------------------- 1 | import pathlib 2 | from typing import IO 3 | 4 | import _numtype as _nt 5 | import numpy as np 6 | 7 | str_path: str 8 | bytes_path: bytes 9 | pathlib_path: pathlib.Path 10 | str_file: IO[str] 11 | AR_i8: _nt.Array[np.int64] 12 | 13 | np.save(bytes_path, AR_i8) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 14 | np.savez(bytes_path, AR_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 15 | np.savez_compressed(bytes_path, AR_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 16 | 17 | np.load(str_file) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 18 | np.loadtxt(bytes_path) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 19 | np.fromregex(bytes_path, ".", np.int64) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 20 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/numerictypes.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | np.isdtype(1, np.int64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 4 | np.issubdtype(1, np.int64) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 5 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/rec.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | AR_i8: _nt.Array[np.int64] 5 | 6 | np.rec.fromarrays(1) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 7 | np.rec.fromarrays( # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 8 | [1, 2, 3], 9 | dtype=[("f8", "f8")], 10 | formats=["f8", "f8"], # pyright: ignore[reportArgumentType] 11 | ) 12 | 13 | np.rec.fromrecords(AR_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 14 | np.rec.fromrecords( # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 15 | [(1.5,)], 16 | dtype=[("f8", "f8")], 17 | formats=["f8", "f8"], # pyright: ignore[reportArgumentType] 18 | ) 19 | 20 | np.rec.fromstring("string", dtype=[("f8", "f8")]) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 21 | np.rec.fromstring(b"bytes") # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 22 | np.rec.fromstring( # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 23 | b"(1.5,)", 24 | dtype=[("f8", "f8")], 25 | formats=["f8", "f8"], # pyright: ignore[reportArgumentType] 26 | ) 27 | 28 | with open("test", encoding="utf-8") as f: 29 | np.rec.fromfile(f, dtype=[("f8", "f8")]) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 30 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/shape.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | # test bounds of _ShapeT_co 4 | 5 | # TODO(jorenham): re-enable once python/mypy#19110 is fixed 6 | np.ndarray[tuple[str, str]] 7 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/shape_base.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | class DTypeLike: 4 | dtype: np.dtype[np.int_] 5 | 6 | dtype_like: DTypeLike 7 | 8 | np.expand_dims(dtype_like, (5, 10)) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 9 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/stride_tricks.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | from numpy.lib import stride_tricks 4 | 5 | AR_f8: _nt.Array[np.float64] 6 | 7 | ### 8 | 9 | stride_tricks.as_strided(AR_f8, shape=8) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 10 | stride_tricks.as_strided(AR_f8, strides=8) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 11 | stride_tricks.sliding_window_view(AR_f8, axis=(1,)) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 12 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/testing.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | AR_U: _nt.Array[np.str_] 5 | 6 | def func(x: object) -> bool: ... 7 | 8 | np.testing.assert_(True, msg=1) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] # noqa: PT009 9 | np.testing.build_err_msg(1, "test") # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 10 | np.testing.assert_almost_equal(AR_U, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 11 | np.testing.assert_approx_equal([1, 2, 3], [1, 2, 3]) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 12 | np.testing.assert_array_almost_equal(AR_U, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 13 | np.testing.assert_array_less(AR_U, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 14 | np.testing.assert_string_equal(b"a", b"a") # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 15 | 16 | np.testing.assert_raises(expected_exception=TypeError, callable=func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 17 | np.testing.assert_raises_regex(expected_exception=TypeError, expected_regex="T", callable=func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 18 | 19 | np.testing.assert_allclose(AR_U, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 20 | np.testing.assert_array_almost_equal_nulp(AR_U, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 21 | np.testing.assert_array_max_ulp(AR_U, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 22 | 23 | np.testing.assert_warns(RuntimeWarning, func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 24 | np.testing.assert_no_warnings(func=func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 25 | np.testing.assert_no_warnings(func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 26 | np.testing.assert_no_warnings(func, y=None) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 27 | 28 | np.testing.assert_no_gc_cycles(func=func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 29 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/twodim_base.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | def func1(ar: _nt.Array, a: int) -> _nt.Array[np.str_]: ... 5 | def func2(ar: _nt.Array, a: float) -> float: ... 6 | 7 | AR_b: _nt.Array[np.bool] 8 | AR_m: _nt.Array[np.timedelta64] 9 | 10 | AR_LIKE_b: list[bool] 11 | 12 | np.eye(10, M=20.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 13 | np.eye(10, k=2.5, dtype=int) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 14 | 15 | np.diag(AR_b, k=0.5) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 16 | np.diagflat(AR_b, k=0.5) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 17 | 18 | np.tri(10, M=20.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 19 | np.tri(10, k=2.5, dtype=int) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 20 | 21 | np.tril(AR_b, k=0.5) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 22 | np.triu(AR_b, k=0.5) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 23 | 24 | np.vander(AR_m) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 25 | 26 | np.histogram2d(AR_m) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] 27 | 28 | np.mask_indices(10, func1) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 29 | np.mask_indices(10, func2, 10.5) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 30 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/type_check.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | DTYPE_i8: np.dtype[np.int64] 4 | 5 | np.mintypecode(DTYPE_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 6 | np.iscomplexobj(DTYPE_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 7 | np.isrealobj(DTYPE_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 8 | 9 | np.typename(DTYPE_i8) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 10 | np.typename("invalid") # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 11 | 12 | np.common_type(np.timedelta64()) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 13 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/ufunc_config.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | class Write1: 4 | def write1(self, a: str) -> None: ... 5 | 6 | class Write2: 7 | def write(self, a: str, b: str) -> None: ... 8 | 9 | class Write3: 10 | def write(self, *, a: str) -> None: ... 11 | 12 | def func1(a: str, b: int, c: float) -> None: ... 13 | def func2(a: str, *, b: int) -> None: ... 14 | 15 | ### 16 | 17 | np.seterrcall(func1) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 18 | np.seterrcall(func2) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 19 | np.seterrcall(Write1()) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 20 | np.seterrcall(Write2()) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 21 | np.seterrcall(Write3()) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] 22 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/ufunclike.pyi: -------------------------------------------------------------------------------- 1 | import _numtype as _nt 2 | import numpy as np 3 | 4 | AR_c: _nt.Array[np.complex128] 5 | AR_m: _nt.Array[np.timedelta64] 6 | AR_M: _nt.Array[np.datetime64] 7 | AR_O: _nt.Array[np.object_] 8 | 9 | np.fix(AR_c) # type: ignore[type-var] # pyright: ignore[reportArgumentType, reportCallIssue] 10 | np.fix(AR_m) # type: ignore[type-var] # pyright: ignore[reportArgumentType, reportCallIssue] 11 | np.fix(AR_M) # type: ignore[type-var] # pyright: ignore[reportArgumentType, reportCallIssue] 12 | 13 | np.isposinf(AR_c) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 14 | np.isposinf(AR_m) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 15 | np.isposinf(AR_M) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 16 | np.isposinf(AR_O) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 17 | 18 | np.isneginf(AR_c) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 19 | np.isneginf(AR_m) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 20 | np.isneginf(AR_M) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 21 | np.isneginf(AR_O) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] 22 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/reject/warnings_and_errors.pyi: -------------------------------------------------------------------------------- 1 | import numpy.exceptions as ex 2 | 3 | ex.AxisError(1.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 4 | ex.AxisError(1, ndim=2.0) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] 5 | ex.AxisError(2, msg_prefix=404) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] 6 | -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/sanity/__init__.pyi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numpy/numtype/83c2f491ba44a2de710bb9fbfb763a39833fb934/src/numpy-stubs/@test/static/sanity/__init__.pyi -------------------------------------------------------------------------------- /src/numpy-stubs/@test/static/sanity/using_numtype.pyi: -------------------------------------------------------------------------------- 1 | # Ensure that mypy uses `numpy-stubs`, as opposed to the bundle `numpy` stubs. 2 | # in `uv` mypy only works. 3 | # To verify this, run `uv run --directory test static static/sanity`. 4 | 5 | from typing import Literal, assert_type 6 | 7 | import numpy as np 8 | 9 | assert_type(np.__numtype__, Literal[True]) 10 | -------------------------------------------------------------------------------- /src/numpy-stubs/_configtool.pyi: -------------------------------------------------------------------------------- 1 | def main() -> None: ... 2 | -------------------------------------------------------------------------------- /src/numpy-stubs/_core/_add_newdocs.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.overrides import get_array_function_like_doc as get_array_function_like_doc 2 | 3 | def refer_to_array_attribute(attr: str, method: bool = True) -> tuple[str, str]: ... 4 | -------------------------------------------------------------------------------- /src/numpy-stubs/_core/_add_newdocs_scalars.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Iterable 2 | from typing import Final 3 | 4 | import numpy as np 5 | 6 | possible_aliases: Final[list[tuple[type[np.number], str, str]]] = ... 7 | _system: Final[str] = ... 8 | _machine: Final[str] = ... 9 | _doc_alias_string: Final[str] = ... 10 | _bool_docstring: Final[str] = ... 11 | int_name: str = ... 12 | float_name: str = ... 13 | 14 | def numeric_type_aliases(aliases: list[tuple[str, str]]) -> list[tuple[type[np.number], str, str]]: ... 15 | def add_newdoc_for_scalar_type(obj: str, fixed_aliases: Iterable[str], doc: str) -> None: ... 16 | def _get_platform_and_machine() -> tuple[str, str]: ... 17 | -------------------------------------------------------------------------------- /src/numpy-stubs/_core/_dtype.pyi: -------------------------------------------------------------------------------- 1 | from typing import Final, Literal as L, TypeAlias, TypedDict, overload, type_check_only 2 | from typing_extensions import ReadOnly, TypeVar 3 | 4 | import numpy as np 5 | 6 | ### 7 | 8 | _T = TypeVar("_T") 9 | 10 | _Name: TypeAlias = L[ 11 | "uint", "int", "complex", "float", "bool", "void", "object", "datetime", "timedelta", "bytes", "str" 12 | ] 13 | 14 | @type_check_only 15 | class _KindToStemType(TypedDict): 16 | u: ReadOnly[L["uint"]] 17 | i: ReadOnly[L["int"]] 18 | c: ReadOnly[L["complex"]] 19 | f: ReadOnly[L["float"]] 20 | b: ReadOnly[L["bool"]] 21 | V: ReadOnly[L["void"]] 22 | O: ReadOnly[L["object"]] 23 | M: ReadOnly[L["datetime"]] 24 | m: ReadOnly[L["timedelta"]] 25 | S: ReadOnly[L["bytes"]] 26 | U: ReadOnly[L["str"]] 27 | 28 | ### 29 | 30 | _kind_to_stem: Final[_KindToStemType] = ... 31 | 32 | # 33 | def _kind_name(dtype: np.dtype) -> _Name: ... 34 | def __str__(dtype: np.dtype) -> str: ... 35 | def __repr__(dtype: np.dtype) -> str: ... 36 | 37 | # 38 | def _isunsized(dtype: np.dtype) -> bool: ... 39 | def _is_packed(dtype: np.dtype) -> bool: ... 40 | def _name_includes_bit_suffix(dtype: np.dtype) -> bool: ... 41 | 42 | # 43 | def _construction_repr(dtype: np.dtype, include_align: bool = False, short: bool = False) -> str: ... 44 | def _scalar_str(dtype: np.dtype, short: bool) -> str: ... 45 | def _byte_order_str(dtype: np.dtype) -> str: ... 46 | def _datetime_metadata_str(dtype: np.dtype) -> str: ... 47 | def _struct_dict_str(dtype: np.dtype, includealignedflag: bool) -> str: ... 48 | def _struct_list_str(dtype: np.dtype) -> str: ... 49 | def _struct_str(dtype: np.dtype, include_align: bool) -> str: ... 50 | def _subarray_str(dtype: np.dtype) -> str: ... 51 | def _name_get(dtype: np.dtype) -> str: ... 52 | 53 | # 54 | @overload 55 | def _unpack_field(dtype: np.dtype, offset: int, title: _T) -> tuple[np.dtype, int, _T]: ... 56 | @overload 57 | def _unpack_field(dtype: np.dtype, offset: int, title: None = None) -> tuple[np.dtype, int, None]: ... 58 | def _aligned_offset(offset: int, alignment: int) -> int: ... 59 | -------------------------------------------------------------------------------- /src/numpy-stubs/_core/_machar.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Callable 2 | from typing_extensions import deprecated 3 | 4 | __all__ = ["MachAr"] 5 | 6 | @deprecated("deprecated in numpy 1.22") 7 | class MachAr: 8 | ibeta: int 9 | it: int 10 | machep: int 11 | eps: float 12 | negep: int 13 | epsneg: float 14 | iexp: int 15 | minexp: int 16 | xmin: float 17 | maxexp: int 18 | xmax: float 19 | irnd: int 20 | ngrd: int 21 | epsilon: float 22 | tiny: float 23 | huge: float 24 | precision: float 25 | resolution: float 26 | smallest_normal: float 27 | smallest_subnormal: float 28 | title: str | None 29 | 30 | def __init__( 31 | self, 32 | /, 33 | float_conv: Callable[[int], float] = ..., 34 | int_conv: Callable[[float], int] = ..., 35 | float_to_float: Callable[[float], float] = ..., 36 | float_to_str: Callable[[float], str] = ..., 37 | title: str = "Python floating point number", 38 | ) -> None: ... 39 | -------------------------------------------------------------------------------- /src/numpy-stubs/_core/_methods.pyi: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy._core.umath import _Reduce2 3 | 4 | from . import _exceptions as _exceptions, umath as um 5 | 6 | bool_dt: np.dtype[np.bool] = ... 7 | umr_maximum: _Reduce2 = ... 8 | umr_minimum: _Reduce2 = ... 9 | umr_sum: _Reduce2 = ... 10 | umr_prod: _Reduce2 = ... 11 | umr_bitwise_count = um.bitwise_count 12 | umr_any: _Reduce2 = ... 13 | umr_all: _Reduce2 = ... 14 | _complex_to_float: dict[np.dtype[np.complexfloating], np.dtype[np.floating]] = ... 15 | -------------------------------------------------------------------------------- /src/numpy-stubs/_core/_simd.pyi: -------------------------------------------------------------------------------- 1 | from types import ModuleType 2 | from typing import TypedDict, type_check_only 3 | 4 | # NOTE: these 5 areonly defined on systems with an intel processor 5 | SSE42: ModuleType | None = ... 6 | FMA3: ModuleType | None = ... 7 | AVX2: ModuleType | None = ... 8 | AVX512F: ModuleType | None = ... 9 | AVX512_SKX: ModuleType | None = ... 10 | baseline: ModuleType | None = ... 11 | 12 | @type_check_only 13 | class SimdTargets(TypedDict): 14 | SSE42: ModuleType | None 15 | AVX2: ModuleType | None 16 | FMA3: ModuleType | None 17 | AVX512F: ModuleType | None 18 | AVX512_SKX: ModuleType | None 19 | baseline: ModuleType | None 20 | 21 | targets: SimdTargets = ... 22 | 23 | def clear_floatstatus() -> None: ... 24 | def get_floatstatus() -> int: ... 25 | -------------------------------------------------------------------------------- /src/numpy-stubs/_core/_string_helpers.pyi: -------------------------------------------------------------------------------- 1 | from typing import Final 2 | 3 | _all_chars: Final[tuple[str, ...]] = ... 4 | _ascii_upper: Final[tuple[str, ...]] = ... 5 | _ascii_lower: Final[tuple[str, ...]] = ... 6 | 7 | LOWER_TABLE: Final[tuple[str, ...]] = ... 8 | UPPER_TABLE: Final[tuple[str, ...]] = ... 9 | 10 | def english_lower(s: str) -> str: ... 11 | def english_upper(s: str) -> str: ... 12 | def english_capitalize(s: str) -> str: ... 13 | -------------------------------------------------------------------------------- /src/numpy-stubs/_core/_ufunc_config.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import SupportsWrite 2 | from collections.abc import Callable 3 | from types import TracebackType 4 | from typing import Any, Literal, TypeAlias, TypeVar, TypedDict, type_check_only 5 | 6 | __all__ = ["errstate", "getbufsize", "geterr", "geterrcall", "setbufsize", "seterr", "seterrcall"] 7 | 8 | _CallableT = TypeVar("_CallableT", bound=Callable[..., object]) 9 | 10 | _ErrKind: TypeAlias = Literal["ignore", "warn", "raise", "call", "print", "log"] 11 | _ErrFunc: TypeAlias = Callable[[str, int], Any] 12 | _ErrCall: TypeAlias = _ErrFunc | SupportsWrite[str] 13 | 14 | @type_check_only 15 | class _ErrDict(TypedDict): 16 | divide: _ErrKind 17 | over: _ErrKind 18 | under: _ErrKind 19 | invalid: _ErrKind 20 | 21 | ### 22 | 23 | class _unspecified: ... 24 | 25 | class errstate: 26 | __slots__ = "_all", "_call", "_divide", "_invalid", "_over", "_token", "_under" 27 | 28 | def __init__( 29 | self, 30 | /, 31 | *, 32 | call: _ErrCall | _unspecified = ..., 33 | all: _ErrKind | None = None, 34 | divide: _ErrKind | None = None, 35 | over: _ErrKind | None = None, 36 | under: _ErrKind | None = None, 37 | invalid: _ErrKind | None = None, 38 | ) -> None: ... 39 | def __call__(self, /, func: _CallableT) -> _CallableT: ... 40 | def __enter__(self) -> None: ... 41 | def __exit__( 42 | self, cls: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None, / 43 | ) -> None: ... 44 | 45 | def seterr( 46 | all: _ErrKind | None = None, 47 | divide: _ErrKind | None = None, 48 | over: _ErrKind | None = None, 49 | under: _ErrKind | None = None, 50 | invalid: _ErrKind | None = None, 51 | ) -> _ErrDict: ... 52 | def geterr() -> _ErrDict: ... 53 | def setbufsize(size: int) -> int: ... 54 | def getbufsize() -> int: ... 55 | def seterrcall(func: _ErrCall | None) -> _ErrCall | None: ... 56 | def geterrcall() -> _ErrCall | None: ... 57 | -------------------------------------------------------------------------------- /src/numpy-stubs/_core/printoptions.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Callable 2 | from contextvars import ContextVar 3 | from typing import Any, Final, TypedDict 4 | 5 | from .arrayprint import _FormatDict 6 | 7 | __all__ = ["format_options"] 8 | 9 | ### 10 | 11 | class _FormatOptionsDict(TypedDict): 12 | edgeitems: int 13 | threshold: int 14 | floatmode: str 15 | precision: int 16 | suppress: bool 17 | linewidth: int 18 | nanstr: str 19 | infstr: str 20 | sign: str 21 | formatter: _FormatDict | None 22 | legacy: int 23 | override_repr: Callable[[Any], str] | None 24 | 25 | ### 26 | 27 | default_format_options_dict: Final[_FormatOptionsDict] = ... 28 | format_options: ContextVar[_FormatOptionsDict] 29 | -------------------------------------------------------------------------------- /src/numpy-stubs/_distributor_init.pyi: -------------------------------------------------------------------------------- 1 | # intentionally left blank 2 | -------------------------------------------------------------------------------- /src/numpy-stubs/_expired_attrs_2_0.pyi: -------------------------------------------------------------------------------- 1 | from typing import Final, TypedDict, final, type_check_only 2 | 3 | @final 4 | @type_check_only 5 | class _ExpiredAttributesType(TypedDict): 6 | geterrobj: str 7 | seterrobj: str 8 | cast: str 9 | source: str 10 | lookfor: str 11 | who: str 12 | fastCopyAndTranspose: str 13 | set_numeric_ops: str 14 | NINF: str 15 | PINF: str 16 | NZERO: str 17 | PZERO: str 18 | add_newdoc: str 19 | add_docstring: str 20 | add_newdoc_ufunc: str 21 | compat: str 22 | safe_eval: str 23 | float_: str 24 | complex_: str 25 | longfloat: str 26 | singlecomplex: str 27 | cfloat: str 28 | longcomplex: str 29 | clongfloat: str 30 | string_: str 31 | unicode_: str 32 | Inf: str 33 | Infinity: str 34 | NaN: str 35 | infty: str 36 | issctype: str 37 | maximum_sctype: str 38 | obj2sctype: str 39 | sctype2char: str 40 | sctypes: str 41 | issubsctype: str 42 | set_string_function: str 43 | asfarray: str 44 | issubclass_: str 45 | tracemalloc_domain: str 46 | mat: str 47 | recfromcsv: str 48 | recfromtxt: str 49 | deprecate: str 50 | deprecate_with_doc: str 51 | disp: str 52 | find_common_type: str 53 | round_: str 54 | get_array_wrap: str 55 | DataSource: str 56 | nbytes: str 57 | byte_bounds: str 58 | compare_chararrays: str 59 | format_parser: str 60 | alltrue: str 61 | sometrue: str 62 | 63 | __expired_attributes__: Final[_ExpiredAttributesType] = ... 64 | -------------------------------------------------------------------------------- /src/numpy-stubs/_globals.pyi: -------------------------------------------------------------------------------- 1 | __all__ = ["_CopyMode", "_NoValue"] 2 | 3 | import enum 4 | from typing import Final, final 5 | 6 | @final 7 | class _CopyMode(enum.Enum): 8 | ALWAYS = True 9 | NEVER = False 10 | IF_NEEDED = 2 11 | 12 | def __bool__(self, /) -> bool: ... 13 | 14 | @final 15 | class _NoValueType: ... 16 | 17 | _NoValue: Final[_NoValueType] = ... 18 | -------------------------------------------------------------------------------- /src/numpy-stubs/_pyinstaller/__init__.pyi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numpy/numtype/83c2f491ba44a2de710bb9fbfb763a39833fb934/src/numpy-stubs/_pyinstaller/__init__.pyi -------------------------------------------------------------------------------- /src/numpy-stubs/_pyinstaller/hook-numpy.pyi: -------------------------------------------------------------------------------- 1 | from typing import Final 2 | 3 | # from `PyInstaller.compat` 4 | is_conda: Final[bool] 5 | is_pure_conda: Final[bool] 6 | 7 | # from `PyInstaller.utils.hooks` 8 | def is_module_satisfies(requirements: str, version: None = None, version_attr: None = None) -> bool: ... 9 | 10 | binaries: Final[list[tuple[str, str]]] 11 | 12 | hiddenimports: Final[list[str]] 13 | excludedimports: Final[list[str]] 14 | -------------------------------------------------------------------------------- /src/numpy-stubs/_pytesttester.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Iterable 2 | from typing import Literal as L 3 | 4 | __all__ = ["PytestTester"] 5 | 6 | class PytestTester: 7 | module_name: str 8 | def __init__(self, module_name: str) -> None: ... 9 | def __call__( 10 | self, 11 | label: L["fast", "full"] = ..., 12 | verbose: int = ..., 13 | extra_argv: Iterable[str] | None = ..., 14 | doctests: L[False] = ..., 15 | coverage: bool = ..., 16 | durations: int = ..., 17 | tests: Iterable[str] | None = ..., 18 | ) -> bool: ... 19 | -------------------------------------------------------------------------------- /src/numpy-stubs/_typing/_nested_sequence.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Iterator 2 | from typing import Any, Protocol 3 | from typing_extensions import TypeVar 4 | 5 | __all__ = ["_NestedSequence"] 6 | 7 | _T_co = TypeVar("_T_co", covariant=True) 8 | 9 | class _NestedSequence(Protocol[_T_co]): 10 | def __len__(self, /) -> int: ... 11 | def __getitem__(self, index: int, /) -> _T_co | _NestedSequence[_T_co]: ... 12 | def __contains__(self, x: object, /) -> bool: ... 13 | def __iter__(self, /) -> Iterator[_T_co | _NestedSequence[_T_co]]: ... 14 | def __reversed__(self, /) -> Iterator[_T_co | _NestedSequence[_T_co]]: ... 15 | def count(self, value: Any, /) -> int: ... 16 | def index(self, value: Any, /) -> int: ... 17 | -------------------------------------------------------------------------------- /src/numpy-stubs/_typing/_scalars.pyi: -------------------------------------------------------------------------------- 1 | # TODO(jorenham): get rid of these in favor of `_?numtype` 2 | 3 | from typing import Any, TypeAlias 4 | 5 | import numpy as np 6 | 7 | # ruff: noqa: PYI047 8 | 9 | # NOTE: `_StrLike_co` and `_BytesLike_co` are pointless, as `np.str_` and 10 | # `np.bytes_` are already subclasses of their builtin counterpart 11 | _CharLike_co: TypeAlias = str | bytes 12 | 13 | # The 6 `Like_co` type-aliases below represent all scalars that can be 14 | # coerced into `` (with the casting rule `same_kind`) 15 | _BoolLike_co: TypeAlias = bool | np.bool 16 | _UIntLike_co: TypeAlias = bool | np.unsignedinteger | np.bool 17 | _IntLike_co: TypeAlias = int | np.integer | np.bool 18 | _FloatLike_co: TypeAlias = float | np.floating | np.integer | np.bool 19 | _ComplexLike_co: TypeAlias = complex | np.number | np.bool 20 | _NumberLike_co = _ComplexLike_co 21 | _TD64Like_co: TypeAlias = _IntLike_co | np.timedelta64 22 | _ScalarLike_co: TypeAlias = complex | bytes | str | np.generic 23 | 24 | # `_VoidLike_co` is technically not a scalar, but it's close enough 25 | _VoidLike_co: TypeAlias = tuple[Any, ...] | np.void 26 | -------------------------------------------------------------------------------- /src/numpy-stubs/_typing/_shape.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Sequence 2 | from typing import SupportsIndex, TypeAlias 3 | 4 | # TODO(jorenham): https://github.com/numpy/numtype/issues/565 5 | 6 | # Anything that can be coerced to a shape tuple 7 | _ShapeLike: TypeAlias = SupportsIndex | Sequence[SupportsIndex] # noqa: PYI047 8 | -------------------------------------------------------------------------------- /src/numpy-stubs/_typing/_ufunc.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.umath import _gufunc_2_1, _ufunc_1_1, _ufunc_1_2, _ufunc_2_1, _ufunc_2_2 2 | 3 | # remnants of the at-runtime exposed old ufunc typing infrastructure of numpy 4 | 5 | _UFunc_Nin1_Nout1 = _ufunc_1_1 6 | _UFunc_Nin1_Nout2 = _ufunc_1_2 7 | _UFunc_Nin2_Nout1 = _ufunc_2_1 8 | _UFunc_Nin2_Nout2 = _ufunc_2_2 9 | _GUFunc_Nin2_Nout1 = _gufunc_2_1 10 | -------------------------------------------------------------------------------- /src/numpy-stubs/_utils/__init__.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import IdentityFunction 2 | from collections.abc import Callable, Iterable 3 | from typing import Protocol, overload, type_check_only 4 | from typing_extensions import TypeVar 5 | 6 | from ._convertions import asbytes as asbytes, asunicode as asunicode 7 | 8 | ### 9 | 10 | _T = TypeVar("_T") 11 | _HasModuleT = TypeVar("_HasModuleT", bound=_HasModule) 12 | 13 | @type_check_only 14 | class _HasModule(Protocol): 15 | __module__: str 16 | 17 | ### 18 | 19 | @overload 20 | def set_module(module: None) -> IdentityFunction: ... 21 | @overload 22 | def set_module(module: _HasModuleT) -> _HasModuleT: ... 23 | 24 | # 25 | def _rename_parameter( 26 | old_names: Iterable[str], new_names: Iterable[str], dep_version: str | None = None 27 | ) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... 28 | -------------------------------------------------------------------------------- /src/numpy-stubs/_utils/_convertions.pyi: -------------------------------------------------------------------------------- 1 | __all__ = ["asbytes", "asunicode"] 2 | 3 | def asunicode(s: bytes | str) -> str: ... 4 | def asbytes(s: bytes | str) -> str: ... 5 | -------------------------------------------------------------------------------- /src/numpy-stubs/char/__init__.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.defchararray import ( 2 | add, 3 | array, 4 | asarray, 5 | capitalize, 6 | center, 7 | chararray, 8 | compare_chararrays, 9 | count, 10 | decode, 11 | encode, 12 | endswith, 13 | equal, 14 | expandtabs, 15 | find, 16 | greater, 17 | greater_equal, 18 | index, 19 | isalnum, 20 | isalpha, 21 | isdecimal, 22 | isdigit, 23 | islower, 24 | isnumeric, 25 | isspace, 26 | istitle, 27 | isupper, 28 | join, 29 | less, 30 | less_equal, 31 | ljust, 32 | lower, 33 | lstrip, 34 | mod, 35 | multiply, 36 | not_equal, 37 | partition, 38 | replace, 39 | rfind, 40 | rindex, 41 | rjust, 42 | rpartition, 43 | rsplit, 44 | rstrip, 45 | split, 46 | splitlines, 47 | startswith, 48 | str_len, 49 | strip, 50 | swapcase, 51 | title, 52 | translate, 53 | upper, 54 | zfill, 55 | ) 56 | 57 | __all__ = [ 58 | "add", 59 | "array", 60 | "asarray", 61 | "capitalize", 62 | "center", 63 | "chararray", 64 | "compare_chararrays", 65 | "count", 66 | "decode", 67 | "encode", 68 | "endswith", 69 | "equal", 70 | "expandtabs", 71 | "find", 72 | "greater", 73 | "greater_equal", 74 | "index", 75 | "isalnum", 76 | "isalpha", 77 | "isdecimal", 78 | "isdigit", 79 | "islower", 80 | "isnumeric", 81 | "isspace", 82 | "istitle", 83 | "isupper", 84 | "join", 85 | "less", 86 | "less_equal", 87 | "ljust", 88 | "lower", 89 | "lstrip", 90 | "mod", 91 | "multiply", 92 | "not_equal", 93 | "partition", 94 | "replace", 95 | "rfind", 96 | "rindex", 97 | "rjust", 98 | "rpartition", 99 | "rsplit", 100 | "rstrip", 101 | "split", 102 | "splitlines", 103 | "startswith", 104 | "str_len", 105 | "strip", 106 | "swapcase", 107 | "title", 108 | "translate", 109 | "upper", 110 | "zfill", 111 | ] 112 | -------------------------------------------------------------------------------- /src/numpy-stubs/compat/__init__.pyi: -------------------------------------------------------------------------------- 1 | # NOTE: numpy.compat is deprecated since 1.26.0 2 | 3 | from numpy._utils._inspect import formatargspec, getargspec 4 | 5 | from .py3k import ( 6 | Path, 7 | asbytes, 8 | asbytes_nested, 9 | asstr, 10 | asunicode, 11 | asunicode_nested, 12 | basestring, 13 | bytes, 14 | contextlib_nullcontext, 15 | getexception, 16 | integer_types, 17 | is_pathlib_path, 18 | isfileobj, 19 | long, 20 | npy_load_module, 21 | open_latin1, 22 | os_PathLike, 23 | os_fspath, 24 | pickle, 25 | sixu, 26 | strchar, 27 | unicode, 28 | ) 29 | 30 | __all__ = [ 31 | "Path", 32 | "asbytes", 33 | "asbytes_nested", 34 | "asstr", 35 | "asunicode", 36 | "asunicode_nested", 37 | "basestring", 38 | "bytes", 39 | "contextlib_nullcontext", 40 | "formatargspec", 41 | "getargspec", 42 | "getexception", 43 | "integer_types", 44 | "is_pathlib_path", 45 | "isfileobj", 46 | "long", 47 | "npy_load_module", 48 | "open_latin1", 49 | "os_PathLike", 50 | "os_fspath", 51 | "pickle", 52 | "sixu", 53 | "strchar", 54 | "unicode", 55 | ] 56 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/__init__.pyi: -------------------------------------------------------------------------------- 1 | from numpy import _core as _core # noqa: ICN003 2 | from numpy._core import ( 3 | _dtype, 4 | _dtype_ctypes, 5 | _internal, 6 | _multiarray_umath, 7 | arrayprint, 8 | defchararray, 9 | einsumfunc, 10 | fromnumeric, 11 | function_base, 12 | getlimits, 13 | multiarray, 14 | numeric, 15 | numerictypes, 16 | overrides, 17 | records, 18 | shape_base, 19 | umath, 20 | ) 21 | 22 | __all__ = [ 23 | "_dtype", 24 | "_dtype_ctypes", 25 | "_internal", 26 | "_multiarray_umath", 27 | "arrayprint", 28 | "defchararray", 29 | "einsumfunc", 30 | "fromnumeric", 31 | "function_base", 32 | "getlimits", 33 | "multiarray", 34 | "numeric", 35 | "numerictypes", 36 | "overrides", 37 | "records", 38 | "shape_base", 39 | "umath", 40 | ] 41 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/_dtype.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core._dtype import ( 2 | _aligned_offset as _aligned_offset, 3 | _byte_order_str as _byte_order_str, 4 | _construction_repr as _construction_repr, 5 | _datetime_metadata_str as _datetime_metadata_str, 6 | _is_packed as _is_packed, 7 | _isunsized as _isunsized, 8 | _kind_name as _kind_name, 9 | _kind_to_stem as _kind_to_stem, 10 | _name_get as _name_get, 11 | _name_includes_bit_suffix as _name_includes_bit_suffix, 12 | _scalar_str as _scalar_str, 13 | _struct_dict_str as _struct_dict_str, 14 | _struct_list_str as _struct_list_str, 15 | _struct_str as _struct_str, 16 | _subarray_str as _subarray_str, 17 | _unpack_field as _unpack_field, 18 | ) 19 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/_dtype_ctypes.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core._dtype_ctypes import ( 2 | _from_ctypes_array as _from_ctypes_array, 3 | _from_ctypes_scalar as _from_ctypes_scalar, 4 | _from_ctypes_structure as _from_ctypes_structure, 5 | _from_ctypes_union as _from_ctypes_union, 6 | dtype_from_ctypes_type as dtype_from_ctypes_type, 7 | ) 8 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/_internal.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core._internal import ( 2 | IS_PYPY as IS_PYPY, 3 | _ctypes as _ctypes, 4 | array_function_errmsg_formatter as array_function_errmsg_formatter, 5 | array_ufunc_errmsg_formatter as array_ufunc_errmsg_formatter, 6 | dummy_ctype as dummy_ctype, 7 | format_re as format_re, 8 | npy_ctypes_check as npy_ctypes_check, 9 | sep_re as sep_re, 10 | space_re as space_re, 11 | ) 12 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/_utils.pyi: -------------------------------------------------------------------------------- 1 | def _raise_warning(attr: str, submodule: str | None = None) -> None: ... 2 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/arrayprint.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.arrayprint import ( 2 | array2string, 3 | array_repr, 4 | array_str, 5 | format_float_positional, 6 | format_float_scientific, 7 | get_printoptions, 8 | printoptions, 9 | set_printoptions, 10 | ) 11 | 12 | __all__ = [ 13 | "array2string", 14 | "array_repr", 15 | "array_str", 16 | "format_float_positional", 17 | "format_float_scientific", 18 | "get_printoptions", 19 | "printoptions", 20 | "set_printoptions", 21 | ] 22 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/defchararray.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.defchararray import ( 2 | add, 3 | array, 4 | asarray, 5 | capitalize, 6 | center, 7 | chararray, 8 | compare_chararrays, 9 | count, 10 | decode, 11 | encode, 12 | endswith, 13 | equal, 14 | expandtabs, 15 | find, 16 | greater, 17 | greater_equal, 18 | index, 19 | isalnum, 20 | isalpha, 21 | isdecimal, 22 | isdigit, 23 | islower, 24 | isnumeric, 25 | isspace, 26 | istitle, 27 | isupper, 28 | join, 29 | less, 30 | less_equal, 31 | ljust, 32 | lower, 33 | lstrip, 34 | mod, 35 | multiply, 36 | not_equal, 37 | partition, 38 | replace, 39 | rfind, 40 | rindex, 41 | rjust, 42 | rpartition, 43 | rsplit, 44 | rstrip, 45 | split, 46 | splitlines, 47 | startswith, 48 | str_len, 49 | strip, 50 | swapcase, 51 | title, 52 | translate, 53 | upper, 54 | zfill, 55 | ) 56 | 57 | __all__ = [ 58 | "add", 59 | "array", 60 | "asarray", 61 | "capitalize", 62 | "center", 63 | "chararray", 64 | "compare_chararrays", 65 | "count", 66 | "decode", 67 | "encode", 68 | "endswith", 69 | "equal", 70 | "expandtabs", 71 | "find", 72 | "greater", 73 | "greater_equal", 74 | "index", 75 | "isalnum", 76 | "isalpha", 77 | "isdecimal", 78 | "isdigit", 79 | "islower", 80 | "isnumeric", 81 | "isspace", 82 | "istitle", 83 | "isupper", 84 | "join", 85 | "less", 86 | "less_equal", 87 | "ljust", 88 | "lower", 89 | "lstrip", 90 | "mod", 91 | "multiply", 92 | "not_equal", 93 | "partition", 94 | "replace", 95 | "rfind", 96 | "rindex", 97 | "rjust", 98 | "rpartition", 99 | "rsplit", 100 | "rstrip", 101 | "split", 102 | "splitlines", 103 | "startswith", 104 | "str_len", 105 | "strip", 106 | "swapcase", 107 | "title", 108 | "translate", 109 | "upper", 110 | "zfill", 111 | ] 112 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/einsumfunc.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.einsumfunc import einsum, einsum_path 2 | 3 | __all__ = ["einsum", "einsum_path"] 4 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/fromnumeric.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.fromnumeric import ( 2 | all, 3 | amax, 4 | amin, 5 | any, 6 | argmax, 7 | argmin, 8 | argpartition, 9 | argsort, 10 | around, 11 | choose, 12 | clip, 13 | compress, 14 | cumprod, 15 | cumsum, 16 | cumulative_prod, 17 | cumulative_sum, 18 | diagonal, 19 | matrix_transpose, 20 | max, 21 | mean, 22 | min, 23 | ndim, 24 | nonzero, 25 | partition, 26 | prod, 27 | ptp, 28 | put, 29 | ravel, 30 | repeat, 31 | reshape, 32 | resize, 33 | round, 34 | searchsorted, 35 | shape, 36 | size, 37 | sort, 38 | squeeze, 39 | std, 40 | sum, 41 | swapaxes, 42 | take, 43 | trace, 44 | transpose, 45 | var, 46 | ) 47 | 48 | __all__ = [ 49 | "all", 50 | "amax", 51 | "amin", 52 | "any", 53 | "argmax", 54 | "argmin", 55 | "argpartition", 56 | "argsort", 57 | "around", 58 | "choose", 59 | "clip", 60 | "compress", 61 | "cumprod", 62 | "cumsum", 63 | "cumulative_prod", 64 | "cumulative_sum", 65 | "diagonal", 66 | "matrix_transpose", 67 | "max", 68 | "mean", 69 | "min", 70 | "ndim", 71 | "nonzero", 72 | "partition", 73 | "prod", 74 | "ptp", 75 | "put", 76 | "ravel", 77 | "repeat", 78 | "reshape", 79 | "resize", 80 | "round", 81 | "searchsorted", 82 | "shape", 83 | "size", 84 | "sort", 85 | "squeeze", 86 | "std", 87 | "sum", 88 | "swapaxes", 89 | "take", 90 | "trace", 91 | "transpose", 92 | "var", 93 | ] 94 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/function_base.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.function_base import geomspace, linspace, logspace 2 | 3 | __all__ = ["geomspace", "linspace", "logspace"] 4 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/getlimits.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.getlimits import finfo, iinfo 2 | 3 | __all__ = ["finfo", "iinfo"] 4 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/numerictypes.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.numerictypes import ( 2 | ScalarType, 3 | bool, 4 | bool_, 5 | busday_count, 6 | busday_offset, 7 | busdaycalendar, 8 | byte, 9 | bytes_, 10 | cdouble, 11 | character, 12 | clongdouble, 13 | complex64, 14 | complex128, 15 | complex192, 16 | complex256, 17 | complexfloating, 18 | csingle, 19 | datetime64, 20 | datetime_as_string, 21 | datetime_data, 22 | double, 23 | flexible, 24 | float16, 25 | float32, 26 | float64, 27 | float96, 28 | float128, 29 | floating, 30 | generic, 31 | half, 32 | inexact, 33 | int8, 34 | int16, 35 | int32, 36 | int64, 37 | int_, 38 | intc, 39 | integer, 40 | intp, 41 | is_busday, 42 | isdtype, 43 | issubdtype, 44 | long, 45 | longdouble, 46 | longlong, 47 | number, 48 | object_, 49 | short, 50 | signedinteger, 51 | single, 52 | str_, 53 | timedelta64, 54 | typecodes, 55 | ubyte, 56 | uint, 57 | uint8, 58 | uint16, 59 | uint32, 60 | uint64, 61 | uintc, 62 | uintp, 63 | ulong, 64 | ulonglong, 65 | unsignedinteger, 66 | ushort, 67 | void, 68 | ) 69 | 70 | __all__ = [ # noqa: RUF022 71 | "ScalarType", "typecodes", 72 | "isdtype", "issubdtype", 73 | "datetime_data", "datetime_as_string", 74 | "busday_offset", "busday_count", "is_busday", "busdaycalendar", 75 | "generic", "number", "integer", "inexact", "flexible", 76 | "signedinteger", "unsignedinteger", "floating", "complexfloating", "character", 77 | "bool", "bool_", 78 | "int8", "int16", "int32", "int64", "byte", "short", "intc", "intp", "int_", "long", "longlong", 79 | "uint8", "uint16", "uint32", "uint64", "ubyte", "ushort", "uintc", "uintp", "uint", "ulong", "ulonglong", 80 | "float16", "float32", "float64", "float96", "float128", "half", "single", "double", "longdouble", 81 | "complex64", "complex128", "complex192", "complex256", "csingle", "cdouble", "clongdouble", 82 | "object_", 83 | "bytes_", "str_", "void", 84 | "datetime64", "timedelta64", 85 | ] # fmt: skip 86 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/overrides.pyi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numpy/numtype/83c2f491ba44a2de710bb9fbfb763a39833fb934/src/numpy-stubs/core/overrides.pyi -------------------------------------------------------------------------------- /src/numpy-stubs/core/records.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.records import ( 2 | array, 3 | find_duplicate, 4 | format_parser, 5 | fromarrays, 6 | fromfile, 7 | fromrecords, 8 | fromstring, 9 | recarray, 10 | record, 11 | ) 12 | 13 | __all__ = [ 14 | "array", 15 | "find_duplicate", 16 | "format_parser", 17 | "fromarrays", 18 | "fromfile", 19 | "fromrecords", 20 | "fromstring", 21 | "recarray", 22 | "record", 23 | ] 24 | -------------------------------------------------------------------------------- /src/numpy-stubs/core/shape_base.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.shape_base import atleast_1d, atleast_2d, atleast_3d, block, hstack, stack, unstack, vstack 2 | 3 | __all__ = ["atleast_1d", "atleast_2d", "atleast_3d", "block", "hstack", "stack", "unstack", "vstack"] 4 | -------------------------------------------------------------------------------- /src/numpy-stubs/distutils/__init__.pyi: -------------------------------------------------------------------------------- 1 | from typing import Any 2 | 3 | # TODO(jorenham): remove when the full numpy namespace is defined 4 | # https://github.com/numpy/numtype/issues/41 5 | def __getattr__(name: str) -> Any: ... # pyright: ignore[reportIncompleteStub] 6 | -------------------------------------------------------------------------------- /src/numpy-stubs/distutils/core.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Callable 2 | from typing import Any 3 | 4 | from setuptools import Distribution 5 | 6 | from .extension import Extension as Extension 7 | 8 | have_setuptools: bool 9 | numpy_cmdclass: dict[str, Callable[..., Any]] 10 | 11 | def get_distribution(always: bool = False) -> Distribution | None: ... 12 | def setup(**attr: object) -> Distribution: ... 13 | -------------------------------------------------------------------------------- /src/numpy-stubs/distutils/extension.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import Incomplete 2 | from distutils.extension import Extension as old_Extension 3 | 4 | cxx_ext_re: Incomplete 5 | fortran_pyf_ext_re: Incomplete 6 | 7 | class Extension(old_Extension): 8 | sources: list[str] 9 | swig_opts: Incomplete 10 | depends: Incomplete 11 | language: Incomplete 12 | f2py_options: list[str] 13 | module_dirs: Incomplete 14 | extra_c_compile_args: list[str] 15 | extra_cxx_compile_args: list[str] 16 | extra_f77_compile_args: list[str] 17 | extra_f90_compile_args: list[str] 18 | def __init__( 19 | self, 20 | /, 21 | name: str, 22 | sources: list[str], 23 | include_dirs: Incomplete | None = None, 24 | define_macros: Incomplete | None = None, 25 | undef_macros: Incomplete | None = None, 26 | library_dirs: Incomplete | None = None, 27 | libraries: Incomplete | None = None, 28 | runtime_library_dirs: Incomplete | None = None, 29 | extra_objects: Incomplete | None = None, 30 | extra_compile_args: list[str] | None = None, 31 | extra_link_args: Incomplete | None = None, 32 | export_symbols: Incomplete | None = None, 33 | swig_opts: Incomplete | None = None, 34 | depends: Incomplete | None = None, 35 | language: Incomplete | None = None, 36 | f2py_options: Incomplete | None = None, 37 | module_dirs: Incomplete | None = None, 38 | extra_c_compile_args: list[str] | None = None, 39 | extra_cxx_compile_args: list[str] | None = None, 40 | extra_f77_compile_args: list[str] | None = None, 41 | extra_f90_compile_args: list[str] | None = None, 42 | ) -> None: ... 43 | def has_cxx_sources(self) -> bool: ... 44 | def has_f2py_sources(self) -> bool: ... 45 | -------------------------------------------------------------------------------- /src/numpy-stubs/distutils/system_info.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import Incomplete 2 | 3 | __all__ = ["system_info"] 4 | 5 | class system_info: 6 | search_static_first: int 7 | section: str 8 | def __init__(self, default_lib_dirs: list[str] = ..., default_include_dirs: list[str] = ...) -> None: ... 9 | def parse_config_files(self) -> None: ... 10 | def calc_libraries_info(self) -> None: ... 11 | def calc_extra_info(self) -> None: ... 12 | def get_option_single(self, *options: object) -> None: ... 13 | def has_info(self) -> bool: ... 14 | def get_info(self, notfound_action: int = 0) -> dict[str, Incomplete]: ... 15 | def set_info(self, **info: Incomplete) -> None: ... 16 | def get_paths(self, section: Incomplete, key: str) -> Incomplete: ... 17 | def get_lib_dirs(self, key: str = "library_dirs") -> Incomplete: ... 18 | def get_runtime_lib_dirs(self, key: str = "runtime_library_dirs") -> Incomplete: ... 19 | def get_include_dirs(self, key: str = "include_dirs") -> Incomplete: ... 20 | def get_src_dirs(self, key: str = "src_dirs") -> Incomplete: ... 21 | def get_libs(self, key: str, default: Incomplete) -> Incomplete: ... 22 | def get_libraries(self, key: str = "libraries") -> Incomplete: ... 23 | def library_extensions(self) -> Incomplete: ... 24 | def check_libs(self, lib_dirs: Incomplete, libs: Incomplete, opt_libs: list[Incomplete] = []) -> Incomplete: ... 25 | def check_libs2(self, lib_dirs: Incomplete, libs: Incomplete, opt_libs: list[Incomplete] = []) -> Incomplete: ... 26 | def combine_paths(self, *args: Incomplete) -> Incomplete: ... 27 | -------------------------------------------------------------------------------- /src/numpy-stubs/exceptions.pyi: -------------------------------------------------------------------------------- 1 | from typing import overload 2 | 3 | __all__ = [ 4 | "AxisError", 5 | "ComplexWarning", 6 | "DTypePromotionError", 7 | "ModuleDeprecationWarning", 8 | "TooHardError", 9 | "VisibleDeprecationWarning", 10 | ] 11 | 12 | class ComplexWarning(RuntimeWarning): ... 13 | class ModuleDeprecationWarning(DeprecationWarning): ... 14 | class VisibleDeprecationWarning(UserWarning): ... 15 | class RankWarning(RuntimeWarning): ... 16 | class TooHardError(RuntimeError): ... 17 | class DTypePromotionError(TypeError): ... 18 | 19 | class AxisError(ValueError, IndexError): 20 | axis: int | None 21 | ndim: int | None 22 | @overload 23 | def __init__(self, axis: str, ndim: None = ..., msg_prefix: None = ...) -> None: ... 24 | @overload 25 | def __init__(self, axis: int, ndim: int, msg_prefix: str | None = ...) -> None: ... 26 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/__init__.pyi: -------------------------------------------------------------------------------- 1 | from .f2py2e import main as main, run_main 2 | 3 | __all__ = ["get_include", "run_main"] 4 | 5 | def get_include() -> str: ... 6 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/__version__.pyi: -------------------------------------------------------------------------------- 1 | from numpy.version import version as version 2 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/_backends/__init__.pyi: -------------------------------------------------------------------------------- 1 | from typing import Literal as L 2 | 3 | from ._backend import Backend 4 | 5 | def f2py_build_generator(name: L["distutils", "meson"]) -> Backend: ... 6 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/_backends/_backend.pyi: -------------------------------------------------------------------------------- 1 | import abc 2 | from pathlib import Path 3 | from typing import Any, Final 4 | 5 | class Backend(abc.ABC): 6 | modulename: Final[str] 7 | sources: Final[list[str | Path]] 8 | extra_objects: Final[list[str]] 9 | build_dir: Final[str | Path] 10 | include_dirs: Final[list[str | Path]] 11 | library_dirs: Final[list[str | Path]] 12 | libraries: Final[list[str]] 13 | define_macros: Final[list[tuple[str, str | None]]] 14 | undef_macros: Final[list[str]] 15 | f2py_flags: Final[list[str]] 16 | sysinfo_flags: Final[list[str]] 17 | fc_flags: Final[list[str]] 18 | flib_flags: Final[list[str]] 19 | setup_flags: Final[list[str]] 20 | remove_build_dir: Final[bool] 21 | extra_dat: Final[dict[str, Any]] 22 | 23 | def __init__( 24 | self, 25 | /, 26 | modulename: str, 27 | sources: list[str | Path], 28 | extra_objects: list[str], 29 | build_dir: str | Path, 30 | include_dirs: list[str | Path], 31 | library_dirs: list[str | Path], 32 | libraries: list[str], 33 | define_macros: list[tuple[str, str | None]], 34 | undef_macros: list[str], 35 | f2py_flags: list[str], 36 | sysinfo_flags: list[str], 37 | fc_flags: list[str], 38 | flib_flags: list[str], 39 | setup_flags: list[str], 40 | remove_build_dir: bool, 41 | extra_dat: dict[str, Any], 42 | ) -> None: ... 43 | 44 | # 45 | @abc.abstractmethod 46 | def compile(self) -> None: ... 47 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/_backends/_distutils.pyi: -------------------------------------------------------------------------------- 1 | from typing_extensions import deprecated, override 2 | 3 | from ._backend import Backend 4 | 5 | class DistutilsBackend(Backend): 6 | @deprecated( 7 | "distutils has been deprecated since NumPy 1.26.x. Use the Meson backend instead, " 8 | "or generate wrappers without -c and use a custom build script" 9 | ) 10 | # NOTE: the `sef` typo matches runtime 11 | def __init__(sef, *args: object, **kwargs: object) -> None: ... 12 | @override 13 | def compile(self) -> None: ... 14 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/_backends/_meson.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Callable 2 | from pathlib import Path 3 | from typing import Final, Literal as L 4 | from typing_extensions import override 5 | 6 | from ._backend import Backend 7 | 8 | class MesonTemplate: 9 | modulename: Final[str] 10 | build_template_path: Final[Path] 11 | sources: Final[list[str | Path]] 12 | deps: Final[list[str]] 13 | libraries: Final[list[str]] 14 | library_dirs: Final[list[str | Path]] 15 | include_dirs: Final[list[str | Path]] 16 | substitutions: Final[dict[str, str]] 17 | objects: Final[list[str | Path]] 18 | fortran_args: Final[list[str]] 19 | pipeline: Final[list[Callable[[], None]]] 20 | build_type: Final[str] 21 | python_exe: Final[str] 22 | indent: Final[str] 23 | 24 | def __init__( 25 | self, 26 | /, 27 | modulename: str, 28 | sources: list[Path], 29 | deps: list[str], 30 | libraries: list[str], 31 | library_dirs: list[str | Path], 32 | include_dirs: list[str | Path], 33 | object_files: list[str | Path], 34 | linker_args: list[str], 35 | fortran_args: list[str], 36 | build_type: str, 37 | python_exe: str, 38 | ) -> None: ... 39 | 40 | # 41 | def initialize_template(self) -> None: ... 42 | def sources_substitution(self) -> None: ... 43 | def deps_substitution(self) -> None: ... 44 | def libraries_substitution(self) -> None: ... 45 | def include_substitution(self) -> None: ... 46 | def fortran_args_substitution(self) -> None: ... 47 | 48 | # 49 | def meson_build_template(self) -> str: ... 50 | def generate_meson_build(self) -> str: ... 51 | 52 | class MesonBackend(Backend): 53 | dependencies: list[str] 54 | meson_build_dir: L["bdir"] 55 | build_type: L["debug", "release"] 56 | 57 | def __init__(self, /, *args: object, **kwargs: object) -> None: ... 58 | def write_meson_build(self, /, build_dir: Path) -> None: ... 59 | def run_meson(self, /, build_dir: Path) -> None: ... 60 | @override 61 | def compile(self) -> None: ... 62 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/_isocbind.pyi: -------------------------------------------------------------------------------- 1 | from typing import Any, Final 2 | 3 | iso_c_binding_map: Final[dict[str, dict[str, str]]] = ... 4 | 5 | isoc_c2pycode_map: Final[dict[str, Any]] = {} # not implemented 6 | iso_c2py_map: Final[dict[str, Any]] = {} # not implemented 7 | 8 | isoc_kindmap: Final[dict[str, str]] = ... 9 | 10 | # namespace pollution 11 | c_type: str 12 | c_type_dict: dict[str, str] 13 | fortran_type: str 14 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/_src_pyf.pyi: -------------------------------------------------------------------------------- 1 | import re 2 | from _typeshed import StrOrBytesPath 3 | from collections.abc import Mapping 4 | from typing import Final 5 | 6 | routine_start_re: Final[re.Pattern[str]] = ... 7 | routine_end_re: Final[re.Pattern[str]] = ... 8 | function_start_re: Final[re.Pattern[str]] = ... 9 | template_re: Final[re.Pattern[str]] = ... 10 | named_re: Final[re.Pattern[str]] = ... 11 | list_re: Final[re.Pattern[str]] = ... 12 | item_re: Final[re.Pattern[str]] = ... 13 | template_name_re: Final[re.Pattern[str]] = ... 14 | include_src_re: Final[re.Pattern[str]] = ... 15 | 16 | def parse_structure(astr: str) -> list[tuple[int, int]]: ... 17 | def find_repl_patterns(astr: str) -> dict[str, str]: ... 18 | def find_and_remove_repl_patterns(astr: str) -> tuple[str, dict[str, str]]: ... 19 | def conv(astr: str) -> str: ... 20 | 21 | # 22 | def unique_key(adict: Mapping[str, object]) -> str: ... 23 | def expand_sub(substr: str, names: dict[str, str]) -> str: ... 24 | def process_str(allstr: str) -> str: ... 25 | 26 | # 27 | def resolve_includes(source: StrOrBytesPath) -> list[str]: ... 28 | def process_file(source: StrOrBytesPath) -> str: ... 29 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/capi_maps.pyi: -------------------------------------------------------------------------------- 1 | from .auxfuncs import _ROut, _Var, process_f2cmap_dict 2 | 3 | __all__ = [ 4 | "cb_routsign2map", 5 | "cb_sign2map", 6 | "common_sign2map", 7 | "getarrdims", 8 | "getarrdocsign", 9 | "getctype", 10 | "getinit", 11 | "getpydocsign", 12 | "getstrlength", 13 | "modsign2map", 14 | "process_f2cmap_dict", 15 | "routsign2map", 16 | "sign2map", 17 | ] 18 | 19 | ### 20 | 21 | def getctype(var: _Var) -> str: ... 22 | def f2cexpr(expr: str) -> str: ... 23 | def getstrlength(var: _Var) -> str: ... 24 | def getarrdims(a: str, var: _Var, verbose: int = 0) -> dict[str, str]: ... 25 | def getpydocsign(a: str, var: _Var) -> tuple[str, str]: ... 26 | def getarrdocsign(a: str, var: _Var) -> str: ... 27 | def getinit(a: str, var: _Var) -> tuple[str, str]: ... 28 | def sign2map(a: str, var: _Var) -> dict[str, str]: ... 29 | def routsign2map(rout: _ROut) -> dict[str, str]: ... 30 | def modsign2map(m: _ROut) -> dict[str, str]: ... 31 | def cb_sign2map(a: str, var: _Var, index: object | None = None) -> dict[str, str]: ... 32 | def cb_routsign2map(rout: _ROut, um: str) -> dict[str, str]: ... 33 | def common_sign2map(a: str, var: _Var) -> dict[str, str]: ... # obsolete 34 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/cb_rules.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Mapping 2 | from typing import Any, Final 3 | 4 | from .__version__ import version 5 | 6 | ## 7 | 8 | f2py_version: Final = version 9 | 10 | cb_routine_rules: Final[dict[str, str | list[str]]] = ... 11 | cb_rout_rules: Final[list[dict[str, str | Any]]] = ... 12 | cb_arg_rules: Final[list[dict[str, str | Any]]] = ... 13 | 14 | cb_map: Final[dict[str, list[list[str]]]] = ... 15 | 16 | def buildcallbacks(m: Mapping[str, object]) -> None: ... 17 | def buildcallback(rout: Mapping[str, object], um: Mapping[str, object]) -> None: ... 18 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/cfuncs.pyi: -------------------------------------------------------------------------------- 1 | from typing import Final, TypeAlias 2 | 3 | from .__version__ import version 4 | 5 | ### 6 | 7 | _NeedListDict: TypeAlias = dict[str, list[str]] 8 | _NeedDict: TypeAlias = dict[str, str] 9 | 10 | ### 11 | 12 | f2py_version: Final = version 13 | 14 | outneeds: Final[_NeedListDict] = ... 15 | needs: Final[_NeedListDict] = ... 16 | 17 | includes0: Final[_NeedDict] = ... 18 | includes: Final[_NeedDict] = ... 19 | userincludes: Final[_NeedDict] = ... 20 | typedefs: Final[_NeedDict] = ... 21 | typedefs_generated: Final[_NeedDict] = ... 22 | cppmacros: Final[_NeedDict] = ... 23 | cfuncs: Final[_NeedDict] = ... 24 | callbacks: Final[_NeedDict] = ... 25 | f90modhooks: Final[_NeedDict] = ... 26 | commonhooks: Final[_NeedDict] = ... 27 | 28 | def errmess(s: str) -> None: ... 29 | def buildcfuncs() -> None: ... 30 | def get_needs() -> _NeedListDict: ... 31 | def append_needs(need: str | list[str], flag: int = 1) -> _NeedListDict: ... 32 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/common_rules.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Mapping 2 | from typing import Any, Final 3 | 4 | from .__version__ import version 5 | 6 | f2py_version: Final = version 7 | 8 | def findcommonblocks(block: Mapping[str, object], top: int = 1) -> list[tuple[str, list[str], dict[str, Any]]]: ... 9 | def buildhooks(m: Mapping[str, object]) -> tuple[dict[str, Any], str]: ... 10 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/diagnose.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import StrOrBytesPath 2 | 3 | def run_command(cmd: StrOrBytesPath) -> None: ... 4 | def run() -> None: ... 5 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/f90mod_rules.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Mapping 2 | from typing import Any, Final 3 | 4 | from .auxfuncs import isintent_dict as isintent_dict 5 | 6 | __version__: Final[str] = ... 7 | f2py_version: Final = "See `f2py -v`" 8 | 9 | options: Final[dict[str, bool]] 10 | 11 | fgetdims1: Final[str] = ... 12 | fgetdims2: Final[str] = ... 13 | fgetdims2_sa: Final[str] = ... 14 | 15 | def findf90modules(m: Mapping[str, object]) -> list[dict[str, Any]]: ... 16 | def buildhooks(pymod: Mapping[str, object]) -> dict[str, Any]: ... 17 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/func2subr.pyi: -------------------------------------------------------------------------------- 1 | from .auxfuncs import _Bool, _ROut, _Var 2 | 3 | def var2fixfortran(vars: _Var, a: str, fa: str | None = None, f90mode: _Bool | None = None) -> str: ... 4 | def useiso_c_binding(rout: _ROut) -> bool: ... 5 | def createfuncwrapper(rout: _ROut, signature: int = 0) -> str: ... 6 | def createsubrwrapper(rout: _ROut, signature: int = 0) -> str: ... 7 | def assubr(rout: _ROut) -> tuple[dict[str, str], str]: ... 8 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/rules.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Callable, Iterable, Mapping 2 | from typing import Any, Final, Literal as L, TypeAlias 3 | from typing_extensions import TypeVar 4 | 5 | from .__version__ import version 6 | from .auxfuncs import _Bool, _Var 7 | 8 | ### 9 | 10 | _VT = TypeVar("_VT", default=str) 11 | 12 | _Predicate: TypeAlias = Callable[[_Var], _Bool] 13 | _RuleDict: TypeAlias = dict[str, _VT] 14 | _DefDict: TypeAlias = dict[_Predicate, _VT] 15 | 16 | ### 17 | 18 | f2py_version: Final = version 19 | numpy_version: Final = version 20 | 21 | options: Final[dict[str, bool]] = ... 22 | sepdict: Final[dict[str, str]] = ... 23 | 24 | generationtime: Final[int] = ... 25 | typedef_need_dict: Final[_DefDict[str]] = ... 26 | 27 | module_rules: Final[_RuleDict[str | list[str] | _RuleDict]] = ... 28 | routine_rules: Final[_RuleDict[str | list[str] | _DefDict | _RuleDict]] = ... 29 | defmod_rules: Final[list[_RuleDict[str | _DefDict]]] = ... 30 | rout_rules: Final[list[_RuleDict[str | Any]]] = ... 31 | aux_rules: Final[list[_RuleDict[str | Any]]] = ... 32 | arg_rules: Final[list[_RuleDict[str | Any]]] = ... 33 | check_rules: Final[list[_RuleDict[str | Any]]] = ... 34 | 35 | stnd: Final[dict[L[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], L["st", "nd", "rd", "th"]]] = ... 36 | 37 | def buildmodule(m: Mapping[str, str | Any], um: Iterable[Mapping[str, str | Any]]) -> _RuleDict: ... 38 | def buildapi(rout: Mapping[str, str]) -> tuple[_RuleDict, str]: ... 39 | 40 | # namespace pollution 41 | k: str 42 | -------------------------------------------------------------------------------- /src/numpy-stubs/f2py/use_rules.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Mapping 2 | from typing import Any, Final 3 | 4 | __version__: Final[str] = ... 5 | f2py_version: Final = "See `f2py -v`" 6 | usemodule_rules: Final[dict[str, str | list[str]]] = ... 7 | 8 | def buildusevars(m: Mapping[str, object], r: Mapping[str, Mapping[str, object]]) -> dict[str, Any]: ... 9 | def buildusevar( 10 | name: str, realname: str, vars: Mapping[str, Mapping[str, object]], usemodulename: str 11 | ) -> dict[str, Any]: ... 12 | -------------------------------------------------------------------------------- /src/numpy-stubs/fft/__init__.pyi: -------------------------------------------------------------------------------- 1 | from ._helper import fftfreq, fftshift, ifftshift, rfftfreq 2 | from ._pocketfft import fft, fft2, fftn, hfft, ifft, ifft2, ifftn, ihfft, irfft, irfft2, irfftn, rfft, rfft2, rfftn 3 | 4 | __all__ = [ 5 | "fft", 6 | "fft2", 7 | "fftfreq", 8 | "fftn", 9 | "fftshift", 10 | "hfft", 11 | "ifft", 12 | "ifft2", 13 | "ifftn", 14 | "ifftshift", 15 | "ihfft", 16 | "irfft", 17 | "irfft2", 18 | "irfftn", 19 | "rfft", 20 | "rfft2", 21 | "rfftfreq", 22 | "rfftn", 23 | ] 24 | -------------------------------------------------------------------------------- /src/numpy-stubs/fft/helper.pyi: -------------------------------------------------------------------------------- 1 | from typing_extensions import deprecated 2 | 3 | import _numtype as _nt 4 | from numpy._typing import ArrayLike, _ShapeLike 5 | 6 | from ._helper import _Device, _Int, integer_types as integer_types 7 | 8 | __all__ = ["fftfreq", "fftshift", "ifftshift", "rfftfreq"] 9 | 10 | ### 11 | 12 | @deprecated("Please use `numpy.fft.fftshift` instead.") 13 | def fftshift(x: ArrayLike, axes: _ShapeLike | None = None) -> _nt.Array: ... 14 | @deprecated("Please use `numpy.fft.ifftshift` instead.") 15 | def ifftshift(x: ArrayLike, axes: _ShapeLike | None = None) -> _nt.Array: ... 16 | @deprecated("Please use `numpy.fft.fftfreq` instead.") 17 | def fftfreq(n: _Int, d: ArrayLike = 1.0, device: _Device | None = None) -> _nt.Array: ... 18 | @deprecated("Please use `numpy.fft.rfftfreq` instead.") 19 | def rfftfreq(n: _Int, d: ArrayLike = 1.0, device: _Device | None = None) -> _nt.Array: ... 20 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/__init__.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.function_base import add_newdoc 2 | from numpy._core.multiarray import add_docstring, tracemalloc_domain 3 | 4 | from . import ( 5 | _array_utils_impl as _array_utils_impl, 6 | _arraypad_impl as _arraypad_impl, 7 | _arraysetops_impl as _arraysetops_impl, 8 | _arrayterator_impl as _arrayterator_impl, 9 | _datasource as _datasource, 10 | _function_base_impl as _function_base_impl, 11 | _histograms_impl as _histograms_impl, 12 | _index_tricks_impl as _index_tricks_impl, 13 | _iotools as _iotools, 14 | _nanfunctions_impl as _nanfunctions_impl, 15 | _npyio_impl as _npyio_impl, 16 | _polynomial_impl as _polynomial_impl, 17 | _scimath_impl as _scimath_impl, 18 | _shape_base_impl as _shape_base_impl, 19 | _stride_tricks_impl as _stride_tricks_impl, 20 | _twodim_base_impl as _twodim_base_impl, 21 | _type_check_impl as _type_check_impl, 22 | _ufunclike_impl as _ufunclike_impl, 23 | _utils_impl as _utils_impl, 24 | _version as _version, 25 | array_utils, 26 | format as format, 27 | introspect, 28 | mixins, 29 | npyio, 30 | scimath, 31 | stride_tricks, 32 | ) 33 | from ._arrayterator_impl import Arrayterator 34 | from ._version import NumpyVersion 35 | 36 | __all__ = [ 37 | "Arrayterator", 38 | "NumpyVersion", 39 | "add_docstring", 40 | "add_newdoc", 41 | "array_utils", 42 | "introspect", 43 | "mixins", 44 | "npyio", 45 | "scimath", 46 | "stride_tricks", 47 | "tracemalloc_domain", 48 | ] 49 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/_array_utils_impl.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Iterable, Mapping 2 | from typing import Any, Protocol, type_check_only 3 | 4 | __all__ = ["byte_bounds", "normalize_axis_index", "normalize_axis_tuple"] 5 | 6 | ### 7 | 8 | @type_check_only 9 | class _HasSizeAndArrayInterface(Protocol): 10 | @property 11 | def size(self, /) -> int: ... 12 | @property # `TypedDict` cannot be used because it rejects `dict[str, Any]` 13 | def __array_interface__(self, /) -> Mapping[str, Any]: ... 14 | 15 | ### 16 | 17 | # NOTE: In practice `byte_bounds` can (potentially) take any object 18 | # implementing the `__array_interface__` protocol. The caveat is 19 | # that certain keys, marked as optional in the spec, must be present for 20 | # `byte_bounds`. This concerns `"strides"` and `"data"`. 21 | def byte_bounds(a: _HasSizeAndArrayInterface) -> tuple[int, int]: ... 22 | 23 | ### 24 | def normalize_axis_index(axis: int, ndim: int, msg_prefix: str | None = None) -> int: ... 25 | def normalize_axis_tuple( 26 | axis: int | Iterable[int], ndim: int, argname: str | None = None, allow_duplicate: bool = False 27 | ) -> tuple[int, ...]: ... 28 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/_arraypad_impl.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import Incomplete 2 | from collections.abc import Mapping 3 | from typing import Literal as L, Protocol, TypeAlias, overload, type_check_only 4 | from typing_extensions import TypeVar 5 | 6 | import _numtype as _nt 7 | import numpy as np 8 | from numpy._typing import ArrayLike, _ArrayLike, _ArrayLikeInt 9 | 10 | __all__ = ["pad"] 11 | 12 | ### 13 | 14 | _ScalarT = TypeVar("_ScalarT", bound=np.generic) 15 | 16 | _ModeKind: TypeAlias = L[ 17 | "constant", "edge", "linear_ramp", "maximum", "mean", "median", "minimum", "reflect", "symmetric", "wrap", "empty" 18 | ] 19 | 20 | @type_check_only 21 | class _ModeFunc(Protocol): 22 | def __call__( 23 | self, vector: _nt.Array[Incomplete], pad: tuple[int, int], iaxis: int, kwargs: Mapping[str, object], / 24 | ) -> None: ... 25 | 26 | ### 27 | 28 | # TODO: In practice each keyword argument is exclusive to one or more 29 | # specific modes. Consider adding more overloads to express this in the future. 30 | @overload 31 | def pad( 32 | array: _ArrayLike[_ScalarT], 33 | pad_width: _ArrayLikeInt, 34 | mode: _ModeKind = ..., 35 | *, 36 | stat_length: _ArrayLikeInt | None = ..., 37 | constant_values: ArrayLike = ..., 38 | end_values: ArrayLike = ..., 39 | reflect_type: L["odd", "even"] = ..., 40 | ) -> _nt.Array[_ScalarT]: ... 41 | @overload 42 | def pad( 43 | array: ArrayLike, 44 | pad_width: _ArrayLikeInt, 45 | mode: _ModeKind = ..., 46 | *, 47 | stat_length: _ArrayLikeInt | None = ..., 48 | constant_values: ArrayLike = ..., 49 | end_values: ArrayLike = ..., 50 | reflect_type: L["odd", "even"] = ..., 51 | ) -> _nt.Array[Incomplete]: ... 52 | @overload 53 | def pad( 54 | array: _ArrayLike[_ScalarT], pad_width: _ArrayLikeInt, mode: _ModeFunc, **kwargs: object 55 | ) -> _nt.Array[_ScalarT]: ... 56 | @overload 57 | def pad(array: ArrayLike, pad_width: _ArrayLikeInt, mode: _ModeFunc, **kwargs: object) -> _nt.Array[Incomplete]: ... 58 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/_datasource.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import OpenBinaryMode, OpenTextMode 2 | from pathlib import Path 3 | from typing import IO, Any, TypeAlias 4 | 5 | _Mode: TypeAlias = OpenBinaryMode | OpenTextMode 6 | 7 | ### 8 | 9 | # exported in numpy.lib.nppyio 10 | class DataSource: 11 | def __init__(self, /, destpath: Path | str | None = ...) -> None: ... 12 | def __del__(self, /) -> None: ... 13 | def abspath(self, /, path: str) -> str: ... 14 | def exists(self, /, path: str) -> bool: ... 15 | 16 | # Whether the file-object is opened in string or bytes mode (by default) 17 | # depends on the file-extension of `path` 18 | def open( 19 | self, /, path: str, mode: _Mode = "r", encoding: str | None = None, newline: str | None = None 20 | ) -> IO[Any]: ... 21 | 22 | class Repository(DataSource): 23 | def __init__(self, /, baseurl: str, destpath: str | None = ...) -> None: ... 24 | def listdir(self, /) -> list[str]: ... 25 | 26 | def open( 27 | path: str, mode: _Mode = "r", destpath: str | None = ..., encoding: str | None = None, newline: str | None = None 28 | ) -> IO[Any]: ... 29 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/_histograms_impl.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import Incomplete 2 | from collections.abc import Sequence 3 | from typing import Literal as L, SupportsIndex, TypeAlias 4 | 5 | import _numtype as _nt 6 | from numpy._typing import ArrayLike 7 | 8 | __all__ = ["histogram", "histogram_bin_edges", "histogramdd"] 9 | 10 | ### 11 | 12 | _BinKind: TypeAlias = L["stone", "auto", "doane", "fd", "rice", "scott", "sqrt", "sturges"] 13 | 14 | ### 15 | 16 | def histogram_bin_edges( 17 | a: ArrayLike, 18 | bins: _BinKind | SupportsIndex | ArrayLike = 10, 19 | range: tuple[float, float] | None = None, 20 | weights: ArrayLike | None = None, 21 | ) -> _nt.Array[Incomplete]: ... 22 | 23 | # 24 | def histogram( 25 | a: ArrayLike, 26 | bins: _BinKind | SupportsIndex | ArrayLike = 10, 27 | range: tuple[float, float] | None = None, 28 | density: bool | None = None, 29 | weights: ArrayLike | None = None, 30 | ) -> tuple[_nt.Array[Incomplete], _nt.Array[Incomplete]]: ... 31 | 32 | # 33 | def histogramdd( 34 | sample: ArrayLike, 35 | bins: SupportsIndex | ArrayLike = 10, 36 | range: Sequence[tuple[float, float]] | None = None, 37 | density: bool | None = None, 38 | weights: ArrayLike | None = None, 39 | ) -> tuple[_nt.Array[Incomplete], tuple[_nt.Array[Incomplete], ...]]: ... 40 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/_stride_tricks_impl.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Iterable 2 | from typing import Any, SupportsIndex, overload 3 | from typing_extensions import TypeVar 4 | 5 | import _numtype as _nt 6 | import numpy as np 7 | from numpy._typing import ArrayLike, _ArrayLike, _ShapeLike 8 | 9 | __all__ = ["broadcast_arrays", "broadcast_shapes", "broadcast_to"] 10 | 11 | _ScalarT = TypeVar("_ScalarT", bound=np.generic) 12 | 13 | class DummyArray: 14 | __array_interface__: dict[str, Any] 15 | base: _nt.Array | None 16 | def __init__(self, interface: dict[str, Any], base: _nt.Array | None = ...) -> None: ... 17 | 18 | @overload 19 | def as_strided( 20 | x: _ArrayLike[_ScalarT], 21 | shape: Iterable[int] | None = ..., 22 | strides: Iterable[int] | None = ..., 23 | subok: bool = ..., 24 | writeable: bool = ..., 25 | ) -> _nt.Array[_ScalarT]: ... 26 | @overload 27 | def as_strided( 28 | x: ArrayLike, 29 | shape: Iterable[int] | None = ..., 30 | strides: Iterable[int] | None = ..., 31 | subok: bool = ..., 32 | writeable: bool = ..., 33 | ) -> _nt.Array: ... 34 | @overload 35 | def sliding_window_view( 36 | x: _ArrayLike[_ScalarT], 37 | window_shape: _ShapeLike, 38 | axis: SupportsIndex | None = ..., 39 | *, 40 | subok: bool = ..., 41 | writeable: bool = ..., 42 | ) -> _nt.Array[_ScalarT]: ... 43 | @overload 44 | def sliding_window_view( 45 | x: ArrayLike, 46 | window_shape: _ShapeLike, 47 | axis: SupportsIndex | None = ..., 48 | *, 49 | subok: bool = ..., 50 | writeable: bool = ..., 51 | ) -> _nt.Array: ... 52 | @overload 53 | def broadcast_to(array: _ArrayLike[_ScalarT], shape: _ShapeLike, subok: bool = ...) -> _nt.Array[_ScalarT]: ... 54 | @overload 55 | def broadcast_to(array: ArrayLike, shape: _ShapeLike, subok: bool = ...) -> _nt.Array: ... 56 | def broadcast_shapes(*args: _ShapeLike) -> _nt.Shape: ... 57 | def broadcast_arrays(*args: ArrayLike, subok: bool = ...) -> tuple[_nt.Array, ...]: ... 58 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/_utils_impl.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import SupportsWrite as CanWrite 2 | from typing import LiteralString 3 | from typing_extensions import TypeVar 4 | 5 | import numpy as np 6 | 7 | __all__ = ["get_include", "info", "show_runtime"] 8 | 9 | _DTypeT = TypeVar("_DTypeT", bound=np.dtype) 10 | 11 | ### 12 | 13 | # 14 | def get_include() -> LiteralString: ... 15 | def show_runtime() -> None: ... 16 | def info( 17 | object: object = None, maxwidth: int = 76, output: CanWrite[str] | None = None, toplevel: str = "numpy" 18 | ) -> None: ... 19 | def drop_metadata(dtype: _DTypeT, /) -> _DTypeT: ... 20 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/_version.pyi: -------------------------------------------------------------------------------- 1 | from typing import Final 2 | from typing_extensions import override 3 | 4 | __all__ = ["NumpyVersion"] 5 | 6 | class NumpyVersion: 7 | vstring: Final[str] 8 | version: Final[str] 9 | major: Final[int] 10 | minor: Final[int] 11 | bugfix: Final[int] 12 | pre_release: Final[str] 13 | is_devversion: Final[bool] 14 | 15 | def __init__(self, /, vstring: str) -> None: ... 16 | def __lt__(self, other: str | NumpyVersion, /) -> bool: ... 17 | def __le__(self, other: str | NumpyVersion, /) -> bool: ... 18 | @override 19 | def __eq__(self, other: str | NumpyVersion, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] 20 | @override 21 | def __ne__(self, other: str | NumpyVersion, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] 22 | def __gt__(self, other: str | NumpyVersion, /) -> bool: ... 23 | def __ge__(self, other: str | NumpyVersion, /) -> bool: ... 24 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/array_utils.pyi: -------------------------------------------------------------------------------- 1 | from ._array_utils_impl import ( 2 | __all__ as __all__, 3 | byte_bounds as byte_bounds, 4 | normalize_axis_index as normalize_axis_index, 5 | normalize_axis_tuple as normalize_axis_tuple, 6 | ) 7 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/introspect.pyi: -------------------------------------------------------------------------------- 1 | __all__ = ["opt_func_info"] 2 | 3 | def opt_func_info( 4 | func_name: str | None = None, signature: str | None = None 5 | ) -> dict[str, dict[str, dict[str, str]]]: ... 6 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/npyio.pyi: -------------------------------------------------------------------------------- 1 | from numpy.lib._npyio_impl import DataSource as DataSource, NpzFile as NpzFile, __doc__ as __doc__ 2 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/scimath.pyi: -------------------------------------------------------------------------------- 1 | from ._scimath_impl import arccos, arcsin, arctanh, log, log2, log10, logn, power, sqrt 2 | 3 | __all__ = ["arccos", "arcsin", "arctanh", "log", "log2", "log10", "logn", "power", "sqrt"] 4 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/stride_tricks.pyi: -------------------------------------------------------------------------------- 1 | from numpy.lib._stride_tricks_impl import as_strided as as_strided, sliding_window_view as sliding_window_view 2 | -------------------------------------------------------------------------------- /src/numpy-stubs/lib/user_array.pyi: -------------------------------------------------------------------------------- 1 | from ._user_array_impl import container as container 2 | -------------------------------------------------------------------------------- /src/numpy-stubs/linalg/__init__.pyi: -------------------------------------------------------------------------------- 1 | from . import _linalg as _linalg, _umath_linalg as _umath_linalg, linalg as linalg 2 | from ._linalg import ( 3 | LinAlgError, 4 | cholesky, 5 | cond, 6 | cross, 7 | det, 8 | diagonal, 9 | eig, 10 | eigh, 11 | eigvals, 12 | eigvalsh, 13 | inv, 14 | lstsq, 15 | matmul, 16 | matrix_norm, 17 | matrix_power, 18 | matrix_rank, 19 | matrix_transpose, 20 | multi_dot, 21 | norm, 22 | outer, 23 | pinv, 24 | qr, 25 | slogdet, 26 | solve, 27 | svd, 28 | svdvals, 29 | tensordot, 30 | tensorinv, 31 | tensorsolve, 32 | trace, 33 | vecdot, 34 | vector_norm, 35 | ) 36 | 37 | __all__ = [ 38 | "LinAlgError", 39 | "cholesky", 40 | "cond", 41 | "cross", 42 | "det", 43 | "diagonal", 44 | "eig", 45 | "eigh", 46 | "eigvals", 47 | "eigvalsh", 48 | "inv", 49 | "lstsq", 50 | "matmul", 51 | "matrix_norm", 52 | "matrix_power", 53 | "matrix_rank", 54 | "matrix_transpose", 55 | "multi_dot", 56 | "norm", 57 | "outer", 58 | "pinv", 59 | "qr", 60 | "slogdet", 61 | "solve", 62 | "svd", 63 | "svdvals", 64 | "tensordot", 65 | "tensorinv", 66 | "tensorsolve", 67 | "trace", 68 | "vecdot", 69 | "vector_norm", 70 | ] 71 | -------------------------------------------------------------------------------- /src/numpy-stubs/linalg/linalg.pyi: -------------------------------------------------------------------------------- 1 | from ._linalg import ( 2 | LinAlgError, 3 | cholesky, 4 | cond, 5 | cross, 6 | det, 7 | diagonal, 8 | eig, 9 | eigh, 10 | eigvals, 11 | eigvalsh, 12 | inv, 13 | lstsq, 14 | matmul, 15 | matrix_norm, 16 | matrix_power, 17 | matrix_rank, 18 | matrix_transpose, 19 | multi_dot, 20 | norm, 21 | outer, 22 | pinv, 23 | qr, 24 | slogdet, 25 | solve, 26 | svd, 27 | svdvals, 28 | tensordot, 29 | tensorinv, 30 | tensorsolve, 31 | trace, 32 | vecdot, 33 | vector_norm, 34 | ) 35 | 36 | __all__ = [ 37 | "LinAlgError", 38 | "cholesky", 39 | "cond", 40 | "cross", 41 | "det", 42 | "diagonal", 43 | "eig", 44 | "eigh", 45 | "eigvals", 46 | "eigvalsh", 47 | "inv", 48 | "lstsq", 49 | "matmul", 50 | "matrix_norm", 51 | "matrix_power", 52 | "matrix_rank", 53 | "matrix_transpose", 54 | "multi_dot", 55 | "norm", 56 | "outer", 57 | "pinv", 58 | "qr", 59 | "slogdet", 60 | "solve", 61 | "svd", 62 | "svdvals", 63 | "tensordot", 64 | "tensorinv", 65 | "tensorsolve", 66 | "trace", 67 | "vecdot", 68 | "vector_norm", 69 | ] 70 | -------------------------------------------------------------------------------- /src/numpy-stubs/ma/timer_comparison.pyi: -------------------------------------------------------------------------------- 1 | from _typeshed import Incomplete 2 | 3 | pi: float = ... 4 | 5 | class ModuleTester: 6 | module: Incomplete = ... 7 | allequal: Incomplete = ... 8 | arange: Incomplete = ... 9 | array: Incomplete = ... 10 | concatenate: Incomplete = ... 11 | count: Incomplete = ... 12 | equal: Incomplete = ... 13 | filled: Incomplete = ... 14 | getmask: Incomplete = ... 15 | getmaskarray: Incomplete = ... 16 | id: Incomplete = ... 17 | inner: Incomplete = ... 18 | make_mask: Incomplete = ... 19 | masked: Incomplete = ... 20 | masked_array: Incomplete = ... 21 | masked_values: Incomplete = ... 22 | mask_or: Incomplete = ... 23 | nomask: Incomplete = ... 24 | ones: Incomplete = ... 25 | outer: Incomplete = ... 26 | repeat: Incomplete = ... 27 | resize: Incomplete = ... 28 | sort: Incomplete = ... 29 | take: Incomplete = ... 30 | transpose: Incomplete = ... 31 | zeros: Incomplete = ... 32 | MaskType: Incomplete = ... 33 | umath: Incomplete = ... 34 | testnames: list[str] = ... 35 | 36 | def __init__(self, module: Incomplete) -> None: ... 37 | def assert_array_compare( 38 | self, 39 | comparison: Incomplete, 40 | x: Incomplete, 41 | y: Incomplete, 42 | err_msg: str = ..., 43 | header: str = ..., 44 | fill_value: bool = ..., 45 | ) -> None: ... 46 | def assert_array_equal(self, x: Incomplete, y: Incomplete, err_msg: str = ...) -> None: ... 47 | 48 | # 49 | def test_0(self) -> None: ... 50 | def test_1(self) -> None: ... 51 | def test_2(self) -> None: ... 52 | def test_3(self) -> None: ... 53 | def test_4(self) -> None: ... 54 | def test_5(self) -> None: ... 55 | def test_6(self) -> None: ... 56 | def test_7(self) -> None: ... 57 | def test_99(self) -> None: ... 58 | def test_A(self) -> None: ... 59 | -------------------------------------------------------------------------------- /src/numpy-stubs/matrixlib/__init__.pyi: -------------------------------------------------------------------------------- 1 | from .defmatrix import asmatrix, bmat, matrix 2 | 3 | __all__ = ["asmatrix", "bmat", "matrix"] 4 | -------------------------------------------------------------------------------- /src/numpy-stubs/polynomial/__init__.pyi: -------------------------------------------------------------------------------- 1 | from typing import Final, Literal 2 | 3 | from numpy._pytesttester import PytestTester as _PytestTester 4 | 5 | from . import chebyshev, hermite, hermite_e, laguerre, legendre, polynomial 6 | from .chebyshev import Chebyshev 7 | from .hermite import Hermite 8 | from .hermite_e import HermiteE 9 | from .laguerre import Laguerre 10 | from .legendre import Legendre 11 | from .polynomial import Polynomial 12 | 13 | __all__ = [ 14 | "Chebyshev", 15 | "Hermite", 16 | "HermiteE", 17 | "Laguerre", 18 | "Legendre", 19 | "Polynomial", 20 | "chebyshev", 21 | "hermite", 22 | "hermite_e", 23 | "laguerre", 24 | "legendre", 25 | "polynomial", 26 | "set_default_printstyle", 27 | ] 28 | 29 | def set_default_printstyle(style: Literal["ascii", "unicode"]) -> None: ... 30 | 31 | test: Final[_PytestTester] = ... # undocumented 32 | -------------------------------------------------------------------------------- /src/numpy-stubs/polynomial/laguerre.pyi: -------------------------------------------------------------------------------- 1 | from typing import Final, Literal as L 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | 6 | from ._polybase import ABCPolyBase 7 | from .legendre import ( 8 | leg2poly as lag2poly, 9 | legadd as lagadd, 10 | legcompanion as lagcompanion, 11 | legder as lagder, 12 | legdiv as lagdiv, 13 | legfit as lagfit, 14 | legfromroots as lagfromroots, 15 | leggauss as laggauss, 16 | leggrid2d as laggrid2d, 17 | leggrid3d as laggrid3d, 18 | legint as lagint, 19 | legline as lagline, 20 | legmul as lagmul, 21 | legmulx as lagmulx, 22 | legpow as lagpow, 23 | legroots as lagroots, 24 | legsub as lagsub, 25 | legtrim as lagtrim, 26 | legval as lagval, 27 | legval2d as lagval2d, 28 | legval3d as lagval3d, 29 | legvander as lagvander, 30 | legvander2d as lagvander2d, 31 | legvander3d as lagvander3d, 32 | legweight as lagweight, 33 | poly2leg as poly2lag, 34 | ) 35 | 36 | __all__ = [ 37 | "Laguerre", 38 | "lag2poly", 39 | "lagadd", 40 | "lagcompanion", 41 | "lagder", 42 | "lagdiv", 43 | "lagdomain", 44 | "lagfit", 45 | "lagfromroots", 46 | "laggauss", 47 | "laggrid2d", 48 | "laggrid3d", 49 | "lagint", 50 | "lagline", 51 | "lagmul", 52 | "lagmulx", 53 | "lagone", 54 | "lagpow", 55 | "lagroots", 56 | "lagsub", 57 | "lagtrim", 58 | "lagval", 59 | "lagval2d", 60 | "lagval3d", 61 | "lagvander", 62 | "lagvander2d", 63 | "lagvander3d", 64 | "lagweight", 65 | "lagx", 66 | "lagzero", 67 | "poly2lag", 68 | ] 69 | 70 | ### 71 | 72 | lagdomain: Final[_nt.Array1D[np.float64]] = ... 73 | lagzero: Final[_nt.Array1D[np.intp]] = ... 74 | lagone: Final[_nt.Array1D[np.intp]] = ... 75 | lagx: Final[_nt.Array1D[np.intp]] = ... 76 | 77 | class Laguerre(ABCPolyBase): 78 | domain: _nt.Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride] 79 | window: _nt.Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride] 80 | basis_name: L["L"] = "L" # pyright: ignore[reportIncompatibleMethodOverride] 81 | -------------------------------------------------------------------------------- /src/numpy-stubs/random/_bounded_integers.pyi: -------------------------------------------------------------------------------- 1 | __all__: list[str] = [] 2 | -------------------------------------------------------------------------------- /src/numpy-stubs/random/_common.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Callable 2 | from typing import Any, NamedTuple, TypeAlias 3 | 4 | import numpy as np 5 | 6 | __all__: list[str] = ["interface"] 7 | 8 | _CDataVoidPointer: TypeAlias = Any 9 | 10 | class interface(NamedTuple): 11 | state_address: int 12 | state: _CDataVoidPointer 13 | next_uint64: Callable[..., np.uint64] 14 | next_uint32: Callable[..., np.uint32] 15 | next_double: Callable[..., np.float64] 16 | bit_generator: _CDataVoidPointer 17 | -------------------------------------------------------------------------------- /src/numpy-stubs/random/_mt19937.pyi: -------------------------------------------------------------------------------- 1 | from typing import Self, TypedDict, type_check_only 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | from numpy._typing import _ArrayLikeInt_co 6 | from numpy.random.bit_generator import BitGenerator 7 | 8 | __all__ = ["MT19937"] 9 | 10 | ### 11 | 12 | @type_check_only 13 | class _MT19937Internal(TypedDict): 14 | key: _nt.Array[np.uint32] 15 | pos: int 16 | 17 | @type_check_only 18 | class _MT19937State(TypedDict): 19 | bit_generator: str 20 | state: _MT19937Internal 21 | 22 | ### 23 | 24 | class MT19937(BitGenerator[_MT19937State]): 25 | def _legacy_seeding(self, seed: _ArrayLikeInt_co) -> None: ... 26 | def jumped(self, jumps: int = ...) -> Self: ... 27 | -------------------------------------------------------------------------------- /src/numpy-stubs/random/_pcg64.pyi: -------------------------------------------------------------------------------- 1 | from typing import Self, TypedDict, type_check_only 2 | 3 | from numpy.random.bit_generator import BitGenerator 4 | 5 | __all__ = ["PCG64"] 6 | 7 | ### 8 | 9 | @type_check_only 10 | class _PCG64Internal(TypedDict): 11 | state: int 12 | inc: int 13 | 14 | @type_check_only 15 | class _PCG64State(TypedDict): 16 | bit_generator: str 17 | state: _PCG64Internal 18 | has_uint32: int 19 | uinteger: int 20 | 21 | ### 22 | 23 | class PCG64(BitGenerator[_PCG64State]): 24 | def jumped(self, jumps: int = ...) -> Self: ... 25 | def advance(self, delta: int) -> Self: ... 26 | 27 | class PCG64DXSM(BitGenerator[_PCG64State]): 28 | def jumped(self, jumps: int = ...) -> Self: ... 29 | def advance(self, delta: int) -> Self: ... 30 | -------------------------------------------------------------------------------- /src/numpy-stubs/random/_philox.pyi: -------------------------------------------------------------------------------- 1 | from typing import Self, TypedDict, type_check_only 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | from numpy.random.bit_generator import BitGenerator, SeedSequence 6 | 7 | __all__ = ["Philox"] 8 | 9 | ### 10 | 11 | @type_check_only 12 | class _PhiloxInternal(TypedDict): 13 | counter: _nt.Array[np.uint64] 14 | key: _nt.Array[np.uint64] 15 | 16 | @type_check_only 17 | class _PhiloxState(TypedDict): 18 | bit_generator: str 19 | state: _PhiloxInternal 20 | buffer: _nt.Array[np.uint64] 21 | buffer_pos: int 22 | has_uint32: int 23 | uinteger: int 24 | 25 | ### 26 | 27 | class Philox(BitGenerator[_PhiloxState]): 28 | def __init__( 29 | self, 30 | /, 31 | seed: _nt.ToInteger_nd | SeedSequence | None = None, 32 | counter: _nt.ToInteger_nd | None = None, 33 | key: _nt.ToInteger_nd | None = None, 34 | ) -> None: ... 35 | def jumped(self, jumps: int = ...) -> Self: ... 36 | def advance(self, delta: int) -> Self: ... 37 | -------------------------------------------------------------------------------- /src/numpy-stubs/random/_pickle.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Callable 2 | from typing import Final, Literal, TypeVar, TypedDict, overload, type_check_only 3 | 4 | from numpy.random._generator import Generator 5 | from numpy.random._mt19937 import MT19937 6 | from numpy.random._pcg64 import PCG64, PCG64DXSM 7 | from numpy.random._philox import Philox 8 | from numpy.random._sfc64 import SFC64 9 | from numpy.random.bit_generator import BitGenerator 10 | from numpy.random.mtrand import RandomState 11 | 12 | _T = TypeVar("_T", bound=BitGenerator) 13 | 14 | @type_check_only 15 | class _BitGenerators(TypedDict): 16 | MT19937: type[MT19937] 17 | PCG64: type[PCG64] 18 | PCG64DXSM: type[PCG64DXSM] 19 | Philox: type[Philox] 20 | SFC64: type[SFC64] 21 | 22 | BitGenerators: Final[_BitGenerators] = ... 23 | 24 | @overload 25 | def __bit_generator_ctor(bit_generator: Literal["MT19937"] = "MT19937") -> MT19937: ... 26 | @overload 27 | def __bit_generator_ctor(bit_generator: Literal["PCG64"]) -> PCG64: ... 28 | @overload 29 | def __bit_generator_ctor(bit_generator: Literal["PCG64DXSM"]) -> PCG64DXSM: ... 30 | @overload 31 | def __bit_generator_ctor(bit_generator: Literal["Philox"]) -> Philox: ... 32 | @overload 33 | def __bit_generator_ctor(bit_generator: Literal["SFC64"]) -> SFC64: ... 34 | @overload 35 | def __bit_generator_ctor(bit_generator: type[_T]) -> _T: ... 36 | def __generator_ctor( 37 | bit_generator_name: str | type[BitGenerator] | BitGenerator = "MT19937", 38 | bit_generator_ctor: Callable[[str | type[BitGenerator]], BitGenerator] = ..., 39 | ) -> Generator: ... 40 | def __randomstate_ctor( 41 | bit_generator_name: str | type[BitGenerator] | BitGenerator = "MT19937", 42 | bit_generator_ctor: Callable[[str | type[BitGenerator]], BitGenerator] = ..., 43 | ) -> RandomState: ... 44 | -------------------------------------------------------------------------------- /src/numpy-stubs/random/_sfc64.pyi: -------------------------------------------------------------------------------- 1 | from typing import TypedDict, type_check_only 2 | 3 | import _numtype as _nt 4 | import numpy as np 5 | from numpy.random.bit_generator import BitGenerator 6 | 7 | __all__ = ["SFC64"] 8 | 9 | ### 10 | 11 | @type_check_only 12 | class _SFC64Internal(TypedDict): 13 | state: _nt.Array[np.uint64] 14 | 15 | @type_check_only 16 | class _SFC64State(TypedDict): 17 | bit_generator: str 18 | state: _SFC64Internal 19 | has_uint32: int 20 | uinteger: int 21 | 22 | ### 23 | 24 | class SFC64(BitGenerator[_SFC64State]): ... 25 | -------------------------------------------------------------------------------- /src/numpy-stubs/rec/__init__.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.records import ( 2 | array, 3 | find_duplicate, 4 | format_parser, 5 | fromarrays, 6 | fromfile, 7 | fromrecords, 8 | fromstring, 9 | recarray, 10 | record, 11 | ) 12 | 13 | __all__ = [ 14 | "array", 15 | "find_duplicate", 16 | "format_parser", 17 | "fromarrays", 18 | "fromfile", 19 | "fromrecords", 20 | "fromstring", 21 | "recarray", 22 | "record", 23 | ] 24 | -------------------------------------------------------------------------------- /src/numpy-stubs/strings/__init__.pyi: -------------------------------------------------------------------------------- 1 | from numpy._core.strings import ( 2 | add, 3 | capitalize, 4 | center, 5 | count, 6 | decode, 7 | encode, 8 | endswith, 9 | equal, 10 | expandtabs, 11 | find, 12 | greater, 13 | greater_equal, 14 | index, 15 | isalnum, 16 | isalpha, 17 | isdecimal, 18 | isdigit, 19 | islower, 20 | isnumeric, 21 | isspace, 22 | istitle, 23 | isupper, 24 | less, 25 | less_equal, 26 | ljust, 27 | lower, 28 | lstrip, 29 | mod, 30 | multiply, 31 | not_equal, 32 | partition, 33 | replace, 34 | rfind, 35 | rindex, 36 | rjust, 37 | rpartition, 38 | rstrip, 39 | startswith, 40 | str_len, 41 | strip, 42 | swapcase, 43 | title, 44 | translate, 45 | upper, 46 | zfill, 47 | ) 48 | 49 | __all__ = [ 50 | "add", 51 | "capitalize", 52 | "center", 53 | "count", 54 | "decode", 55 | "encode", 56 | "endswith", 57 | "equal", 58 | "expandtabs", 59 | "find", 60 | "greater", 61 | "greater_equal", 62 | "index", 63 | "isalnum", 64 | "isalpha", 65 | "isdecimal", 66 | "isdigit", 67 | "islower", 68 | "isnumeric", 69 | "isspace", 70 | "istitle", 71 | "isupper", 72 | "less", 73 | "less_equal", 74 | "ljust", 75 | "lower", 76 | "lstrip", 77 | "mod", 78 | "multiply", 79 | "not_equal", 80 | "partition", 81 | "replace", 82 | "rfind", 83 | "rindex", 84 | "rjust", 85 | "rpartition", 86 | "rstrip", 87 | "startswith", 88 | "str_len", 89 | "strip", 90 | "swapcase", 91 | "title", 92 | "translate", 93 | "upper", 94 | "zfill", 95 | ] 96 | -------------------------------------------------------------------------------- /src/numpy-stubs/testing/_private/__init__.pyi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numpy/numtype/83c2f491ba44a2de710bb9fbfb763a39833fb934/src/numpy-stubs/testing/_private/__init__.pyi -------------------------------------------------------------------------------- /src/numpy-stubs/testing/_private/extbuild.pyi: -------------------------------------------------------------------------------- 1 | import pathlib 2 | import types 3 | from collections.abc import Sequence 4 | 5 | __all__ = ["build_and_import_extension", "compile_extension_module"] 6 | 7 | def build_and_import_extension( 8 | modname: str, 9 | functions: Sequence[tuple[str, str, str]], 10 | *, 11 | prologue: str = "", 12 | build_dir: pathlib.Path | None = None, 13 | include_dirs: Sequence[str] = [], 14 | more_init: str = "", 15 | ) -> types.ModuleType: ... 16 | 17 | # 18 | def compile_extension_module( 19 | name: str, 20 | builddir: pathlib.Path, 21 | include_dirs: Sequence[str], 22 | source_string: str, 23 | libraries: Sequence[str] = [], 24 | library_dirs: Sequence[str] = [], 25 | ) -> pathlib.Path: ... 26 | -------------------------------------------------------------------------------- /src/numpy-stubs/testing/overrides.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Callable, Hashable 2 | from typing import Any 3 | from typing_extensions import TypeIs 4 | 5 | import numpy as np 6 | 7 | def get_overridable_numpy_ufuncs() -> set[np.ufunc]: ... 8 | def get_overridable_numpy_array_functions() -> set[Callable[..., Any]]: ... 9 | def allows_array_ufunc_override(func: object) -> TypeIs[np.ufunc]: ... 10 | def allows_array_function_override(func: Hashable) -> bool: ... 11 | -------------------------------------------------------------------------------- /src/numpy-stubs/testing/print_coercion_tables.pyi: -------------------------------------------------------------------------------- 1 | from collections.abc import Iterable 2 | from typing import ClassVar, Generic, Self 3 | from typing_extensions import TypeVar 4 | 5 | import numpy as np 6 | 7 | _VT_co = TypeVar("_VT_co", default=object, covariant=True) 8 | 9 | # undocumented 10 | class GenericObject(Generic[_VT_co]): 11 | dtype: ClassVar[np.dtype[np.object_]] = ... 12 | v: _VT_co 13 | 14 | def __init__(self, /, v: _VT_co) -> None: ... 15 | def __add__(self, other: object, /) -> Self: ... 16 | def __radd__(self, other: object, /) -> Self: ... 17 | 18 | def print_cancast_table(ntypes: Iterable[str]) -> None: ... 19 | def print_coercion_table( 20 | ntypes: Iterable[str], 21 | inputfirstvalue: int, 22 | inputsecondvalue: int, 23 | firstarray: bool, 24 | use_promote_types: bool = False, 25 | ) -> None: ... 26 | def print_new_cast_table(*, can_cast: bool = True, legacy: bool = False, flags: bool = False) -> None: ... 27 | -------------------------------------------------------------------------------- /src/numpy-stubs/typing/__init__.pyi: -------------------------------------------------------------------------------- 1 | from typing import Never 2 | 3 | from numpy._typing import ArrayLike, DTypeLike, NDArray 4 | 5 | __all__ = ["ArrayLike", "DTypeLike", "NBitBase", "NDArray"] 6 | 7 | NBitBase = Never 8 | -------------------------------------------------------------------------------- /src/numpy-stubs/version.pyi: -------------------------------------------------------------------------------- 1 | from typing import Final, LiteralString 2 | 3 | __version__: Final[LiteralString] = ... 4 | version: Final[LiteralString] = ... 5 | full_version: Final[LiteralString] = ... 6 | short_version: Final[LiteralString] = ... 7 | 8 | release: Final[bool] = ... 9 | git_revision: Final[LiteralString] = ... 10 | -------------------------------------------------------------------------------- /src/numtype/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../../pyproject.toml" 2 | line-length = 88 3 | -------------------------------------------------------------------------------- /src/numtype/@test/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../.ruff.toml" 2 | 3 | [lint] 4 | extend-ignore = [ 5 | "D", # pydocstyle 6 | "S101", # flake8-bandit: assert 7 | ] 8 | -------------------------------------------------------------------------------- /src/numtype/@test/test_numtype.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import numpy as np 4 | import numpy.typing as npt 5 | import numtype as nt 6 | 7 | NPT_DIR = tuple(k for k in npt.__all__ if k != "NBitBase") 8 | 9 | 10 | def test_superset() -> None: 11 | assert set(nt.__all__) > set(NPT_DIR) 12 | 13 | 14 | @pytest.mark.parametrize("name", NPT_DIR) 15 | def test_reexport(name: str) -> None: 16 | assert getattr(nt, name) is getattr(npt, name) 17 | 18 | 19 | def test_version() -> None: 20 | assert nt.__version__.startswith(np.__version__) 21 | -------------------------------------------------------------------------------- /src/numtype/__init__.py: -------------------------------------------------------------------------------- 1 | """A superset of `numpy.typing`. Will be expanded in the future.""" 2 | 3 | from numpy.typing import ArrayLike, DTypeLike, NDArray # noqa: ICN003 4 | 5 | from .version import __version__ 6 | 7 | __all__ = ["ArrayLike", "DTypeLike", "NDArray", "__version__"] 8 | -------------------------------------------------------------------------------- /src/numtype/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numpy/numtype/83c2f491ba44a2de710bb9fbfb763a39833fb934/src/numtype/py.typed -------------------------------------------------------------------------------- /src/numtype/version.py: -------------------------------------------------------------------------------- 1 | """Module to expose more detailed version info for the installed `numtype`.""" 2 | 3 | import importlib.metadata 4 | from typing import Final 5 | 6 | __all__ = ["__version__"] 7 | __version__: Final = importlib.metadata.version(__package__ or __file__.split("/")[-1]) 8 | -------------------------------------------------------------------------------- /tool/.ruff.toml: -------------------------------------------------------------------------------- 1 | extend = "../pyproject.toml" 2 | line-length = 88 3 | 4 | [lint] 5 | extend-ignore = [ 6 | "TRY003", # tryceratops: raise-vanilla-args 7 | "TD003", # flake8-todos: missing-todo-link 8 | "S101", # flake8-bandit: assert 9 | "S404", # flake8-bandit: suspicious-subprocess-import 10 | "S603", # flake8-bandit: subprocess-without-shell-equals-true 11 | "EM", # flake8-errmsg 12 | "T201", # flake8-print: print 13 | "PLR2004", # pylint/refactor: magic-value-comparison 14 | ] 15 | -------------------------------------------------------------------------------- /tool/README.md: -------------------------------------------------------------------------------- 1 | # NumType development tools 2 | 3 | ## ufunc.py 4 | 5 | Introspect NumPy universal functions (ufuncs) by examining their type signatures. 6 | 7 | ```shell 8 | uv run tool/ufunc.py [-h] [-p] [-f ] 9 | ``` 10 | 11 | ## promotion.py 12 | 13 | Introspect NumPy's scalar promotion rules, as a markdown table (default) or mermaid graph. 14 | 15 | ```shell 16 | uv run promotion.py [-h] [-f {table,graph}] [-d DTYPES] 17 | ``` 18 | 19 | ## testgen.py 20 | 21 | Generate type tests for NumType's NumPy integration. 22 | 23 | ```shell 24 | uv run tool/testgen.py 25 | ``` 26 | 27 | ## stubtest.py 28 | 29 | Test type stubs against actual implementations using MyPy's stubtest. 30 | 31 | ```shell 32 | uv run tool/stubtest.py 33 | ``` 34 | 35 | ## unstub.py 36 | 37 | Remove all `.pyi` files from the NumPy site-packages directory. 38 | 39 | ```shell 40 | uv run tool/unstub.py 41 | ``` 42 | 43 | ## format_ignores.py 44 | 45 | Format pyright ignore comments to ensure they are alphabetically sorted with proper spacing. 46 | 47 | ```shell 48 | uv run tool/format_ignores.py [-h] [--pattern PATTERN] [--check] [PATH] 49 | ``` 50 | -------------------------------------------------------------------------------- /tool/__init__.py: -------------------------------------------------------------------------------- 1 | """Tooling for the project.""" 2 | -------------------------------------------------------------------------------- /tool/_ruff.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | from pathlib import Path 3 | from typing import TYPE_CHECKING 4 | 5 | if TYPE_CHECKING: 6 | # ruff should be optional during type-checking 7 | def find_ruff_bin() -> str: ... 8 | 9 | else: 10 | # see https://github.com/astral-sh/ruff/pull/18224 11 | from ruff.__main__ import ( # type: ignore[import-untyped] 12 | find_ruff_bin, # noqa: PLC2701 13 | ) 14 | 15 | 16 | def ruff_format(source: str) -> str: 17 | result = subprocess.run( 18 | [find_ruff_bin(), "format", "-"], 19 | input=source, 20 | text=True, 21 | capture_output=True, 22 | check=True, 23 | cwd=Path.cwd(), 24 | ) 25 | result.check_returncode() 26 | return result.stdout 27 | -------------------------------------------------------------------------------- /tool/allowlists/common.txt: -------------------------------------------------------------------------------- 1 | # intentional type-check-only deviations from runtime 2 | numpy\.__numtype__ 3 | numpy\._typing.* 4 | numpy\.typing\.NBitBase 5 | 6 | # internal testing code 7 | numpy\.conftest 8 | numpy(\.\w+)?\.tests.* 9 | numpy\.random\._generator\.__test__ 10 | 11 | # workaround for the `dtype.type` generic class-attribute that's `None` unless instantiated 12 | numpy(\..+)?\.dtype\.type 13 | 14 | # system-dependent extended precision types 15 | numpy(\..+)?\.float(96|128) 16 | numpy(\..+)?\.complex(192|256) 17 | 18 | # these are always either missing float96/complex192 or float128/complex256 19 | numpy\.__all__ 20 | numpy\._?core\.__all__ 21 | numpy\._?core\.numeric\.__all__ 22 | numpy\._?core\.numerictypes\.__all__ 23 | numpy\.matlib\.__all__ 24 | 25 | # requires numpy/_core/code_generators to be on the PYTHONPATH when running stubtest 26 | numpy\._core\.cversions 27 | 28 | # mypy plugin 29 | numpy\.typing\.mypy_plugin 30 | 31 | # raises SystemExit on import 32 | numpy\.f2py\.__main__ 33 | 34 | # does not exist 35 | numpy\.distutils\.\w+ 36 | 37 | # stdlib re-exports with incorrect typeshed stubs 38 | numpy\.compat(\.py3k)?\.os_PathLike\.__class_getitem__ 39 | -------------------------------------------------------------------------------- /tool/allowlists/ge-py312.txt: -------------------------------------------------------------------------------- 1 | # python >= 3.12 2 | 3 | numpy\.distutils 4 | numpy\.f2py\._backends\._distutils 5 | -------------------------------------------------------------------------------- /tool/allowlists/lt-py312.txt: -------------------------------------------------------------------------------- 1 | # python < 3.12 2 | 3 | # blame typeshed 4 | numpy\.compat(\.py3k)?\.bytes\.__buffer__ 5 | 6 | # distutils is deprecated and does not exist on python>=3.12 7 | numpy\.distutils\.command\.\w+ 8 | numpy\.distutils\.fcompiler\.\w+ 9 | numpy\.distutils\.system_info.system_info\.\w+ 10 | -------------------------------------------------------------------------------- /tool/allowlists/simd.txt: -------------------------------------------------------------------------------- 1 | # only defined on systems with an intel processor 2 | numpy\._core\._simd\.SSE42 3 | numpy\._core\._simd\.FMA3 4 | numpy\._core\._simd\.AVX2 5 | numpy\._core\._simd\.AVX512F 6 | numpy\._core\._simd\.AVX512_SKX 7 | -------------------------------------------------------------------------------- /tool/test/__init__.py: -------------------------------------------------------------------------------- 1 | """Test suite for the tool.""" 2 | -------------------------------------------------------------------------------- /tool/unstub.py: -------------------------------------------------------------------------------- 1 | """ 2 | Delete all `__init__.pyi` files in the `numpy` site-packages directory. 3 | 4 | This is a workaround for https://github.com/python/mypy/issues/18997 on `mypy<1.16.0` 5 | 6 | Run with `uv run tool/unstub.py`. 7 | """ 8 | 9 | import sysconfig 10 | from pathlib import Path 11 | 12 | package = Path(sysconfig.get_paths()["purelib"]) / "numpy" 13 | assert package.is_dir(), package 14 | 15 | bodycount = sum(not pyi.unlink() for pyi in package.rglob("__init__.pyi")) # type: ignore[func-returns-value] 16 | print(f"{bodycount} files deleted from {package.relative_to(Path.cwd())}") 17 | --------------------------------------------------------------------------------