Skip to content
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

numpy.ma.masked_where() return object not recognized as numpy.ma.MaskedArray #3342

Closed
yumasheta opened this issue Jan 12, 2020 · 5 comments · Fixed by pylint-dev/astroid#1148 or pylint-dev/astroid#1176
Assignees
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@yumasheta
Copy link
Contributor

Steps to reproduce

Consider this short python script:

"""Quick test to show pylint error."""

import numpy as np

DATA = np.array([1, 2, 3])
DATA = np.ma.masked_where([1, 0, 0], DATA)
print(DATA.mask)
assert isinstance(DATA, np.ma.MaskedArray)

DATA = np.ma.array([1, 2, 3], mask=[1, 0, 0])
print(DATA.mask)
assert isinstance(DATA, np.ma.MaskedArray)

With output:

[ True False False]
[ True False False]

Running pylint on that code returns:

7:6: E1101: Instance of 'ndarray' has no 'mask' member (no-member)

Current behavior

The object returned by numpy.ma.masked_where() is an instance of numpy.ma.MaskedArray, just as the object returned by numpy.ma.array() is. However, pylint does not recognize the return value of numpy.ma.masked_where() as such.

Expected behavior

Pylint should recognize that numpy.ma.masked_where() returns a numpy.ma.MaskedArray.

pylint --version output

pylint 2.4.4
astroid 2.3.3
Python 3.8.1 (default, Dec 21 2019, 20:57:38) 
[GCC 9.2.0]
@AWhetter AWhetter added Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Bug 🪲 labels Jan 15, 2020
@hippo91 hippo91 self-assigned this Jan 18, 2020
@hippo91
Copy link
Contributor

hippo91 commented Jan 18, 2020

@yumasheta thanks for this bug report. I'll investigate ASAP.

@hippo91
Copy link
Contributor

hippo91 commented Feb 10, 2020

@yumasheta the problem comes from the fact that there is not a brain for numpy.ma module in astroid yet. I put it on my todo list but i'm really busy right now so it will take a long time before seeing it in astroid.
Feel free to add it through a PR. I'll be happy to help you if needed.

@hippo91
Copy link
Contributor

hippo91 commented Aug 25, 2021

@yumasheta this bug should be fixed once pylint-dev/astroid#1148 will be merged and by authorizing pylint to dynamically load numpy with --extension-pkg-allow-list=numpy option.
If however you don't want to authorize this loading, then an improvement of astroid's numpy brain is required but may take a very long time to be set up.

@hippo91
Copy link
Contributor

hippo91 commented Sep 16, 2021

I'm reopening the issue because what was made in pylint-dev/astroid#1148 was not wise.

@hippo91
Copy link
Contributor

hippo91 commented Sep 16, 2021

The problem will be fixed definitively through an update of astroid numpy brain modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants