pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.32k stars 1.14k forks source link

False positive with scipy/scikit-learn #1439

Open elirnm opened 7 years ago

elirnm commented 7 years ago

Steps to reproduce

  1. Put the following code in a file
    
    from sklearn.feature_extraction.text import TfidfVectorizer

def average_tfidf(sents): vec = TfidfVectorizer()

convert raw text to scipy sparse matrix (csr) of tfidf values

word_tfidf = vec.fit_transform(sents)
result = []
for sent in word_tfidf:
    avg = sent.sum() / sent.getnnz()
    result.append(avg)
return result
2. Run pylint on the file

### Current behavior
The `avg = sent.sum() / sent.getnnz()` produces four errors:

E: 22,14: Instance of 'float' has no 'sum' member (no-member) E: 22,14: Instance of 'str' has no 'sum' member (no-member) E: 22,27: Instance of 'float' has no 'getnnz' member (no-member) E: 22,27: Instance of 'str' has no 'getnnz' member (no-member)


### Expected behavior
No errors should be produced.

### pylint --version output

No config file found, using default configuration pylint 1.6.5, astroid 1.4.9 Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)]

elirnm commented 7 years ago

This doesn't occur by default in 1.7.1, but still appears if run with --ignore-on-opaque-inference=n.