Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: add type annotations to numpy.ma #26404

Open
@johnthagen

Description

@johnthagen

Describe the issue:

Running Mypy on some functions within numpy.ma lead to type checking errors due to missing annotations.

Reproduce the code example:

import numpy

a = numpy.ma.array([1, 2, 3, 4], mask=[0, 0, 1, 0])
b = numpy.ma.masked_array([1, 2, 3, 4], mask=[0, 0, 1, 0])

Error message:

$ mypy test.py 
test.py:3: error: Call to untyped function "array" in typed context  [no-untyped-call]
test.py:4: error: Call to untyped function "MaskedArray" in typed context  [no-untyped-call]

Python and NumPy Versions:

1.26.4
3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]

Runtime Environment:

[{'numpy_version': '1.26.4',
  'python': '3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 '
            '(clang-1500.1.0.2.5)]',
  'uname': uname_result(system='Darwin', node='M2DF94775W-ML', release='23.4.0', version='Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:37 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6031', machine='arm64')},
 {'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
                      'found': ['ASIMDHP'],
                      'not_found': ['ASIMDFHM']}},
 {'architecture': 'armv8',
  'filepath': '/Users/hagenjt1/Library/Caches/pypoetry/virtualenvs/non-package-mode-eSjUyYda-py3.12/lib/python3.12/site-packages/numpy/.dylibs/libopenblas64_.0.dylib',
  'internal_api': 'openblas',
  'num_threads': 16,
  'prefix': 'libopenblas',
  'threading_layer': 'pthreads',
  'user_api': 'blas',
  'version': '0.3.23.dev'}]
None

Context for the issue:

We rely on type checking to find bugs in our software that uses Numpy before it is executed. This enables higher code quality and reliability. False positive type errors cost time to track down and can distract from real issues.

Type annotations also help IDEs such as PyCharm and VS Code perform better intellisense during development.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions