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

Skip to content

TYP: ma.ones_like and ma.zeros_like not found by mypy because missing in ma/__init__.pyi #27318

Closed
@sebschub

Description

@sebschub

Describe the issue:

mypy produces for both, ma.ones_like and ma.zeros_like the error: Module has no attribute. The apparent reason is that both are not listed in ma/__init__.pyi. Is this a simple omission? ma/core.pyi includes both, though, so ma.core.ones_like or ma.core.zeros_like work.

Reproduce the code example:

import numpy as np
import numpy.ma as ma
import numpy.ma.core as mac

x: ma.MaskedArray = ma.MaskedArray([1.0, 3.0, 5.0])
# x = ma.MaskedArray([1.0, 3.0, 5.0])
print(ma.ones_like(x))
print(ma.zeros_like(x))

print(np.ones_like(x))

print(mac.ones_like(x))
print(mac.zeros_like(x))

Error message:

test.py:7: error: Module has no attribute "ones_like"  [attr-defined]
test.py:8: error: Module has no attribute "zeros_like"  [attr-defined]
Found 2 errors in 1 file (checked 1 source file)

Python and NumPy Versions:

2.1.0
3.12.5 (main, Aug 7 2024, 00:00:00) [GCC 14.2.1 20240801 (Red Hat 14.2.1-1)]

Type-checker version and settings:

mypy 1.11.2 (compiled: yes)

Additional typing packages.

No response

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