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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sebschub opened this issue Aug 31, 2024 · 2 comments · Fixed by #27323
Closed

Comments

@sebschub
Copy link

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

@luxedo
Copy link
Contributor

luxedo commented Sep 2, 2024

The ma module is not completely typed yet.

There's already a list for typing (#26404) but I think that other functions may have slipped through.

I pushed a PR that solves this issue: #27323

@sebschub
Copy link
Author

sebschub commented Sep 2, 2024

Thank you for the explanation and the PR!

@jorenham jorenham linked a pull request Sep 2, 2024 that will close this issue
@jorenham jorenham closed this as completed Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@sebschub @jorenham @luxedo and others