pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False positive with scipy/scikit-learn

Open elirnm opened this issue 8 years ago • 1 comments

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
  1. 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 avatar Apr 21 '17 23:04 elirnm

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

elirnm avatar Apr 27 '17 10:04 elirnm