Pylint: Pylint giving a false positive E1101 for sklearn

Created on 30 Apr 2018  路  5Comments  路  Source: PyCQA/pylint

Steps to reproduce

  1. Tested it out on the following code:
from sklearn.datasets import load_iris
iris = load_iris()
print(iris.feature_names)
print(iris.target_names)
print(iris.data[0])
print(dir(iris))

Output in terminal -

['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']
['setosa' 'versicolor' 'virginica']
[5.1 3.5 1.4 0.2]
['DESCR', 'data', 'feature_names', 'target', 'target_names']

Current behaviour

$ pylint scikitlearn.py
No config file found, using default configuration
************* Module scikitlearn
C:  8, 0: Final newline missing (missing-final-newline)
C:  1, 0: Missing module docstring (missing-docstring)
C:  3, 0: Constant name "iris" doesn't conform to UPPER_CASE naming style (invalid-name)
E:  4, 6: Instance of 'tuple' has no 'feature_names' member (no-member)
E:  5, 6: Instance of 'tuple' has no 'target_names' member (no-member)
E:  6, 6: Instance of 'tuple' has no 'data' member (no-member)

----------------------------------------------------------------------
Your code has been rated at -20.00/10 (previous run: -15.00/10, -5.00)`

Expected behavior

Pylint displaying a false positive for the above code

pylint --version output

$ pylint --version
No config file found, using default configuration
pylint 1.8.4,
astroid 1.6.2
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
astroid brain bug

Most helpful comment

@maxkleiner
Please use
X = iris["data"]
Y = iris["target"]

All 5 comments

Thanks for the issue, I can reproduce it. I'm not sure why pylint considers the return of load_iris to be a tuple instead of a Bunch object, but we could probably fix it with an astroid brain tip.

thanx for fix

iris = datasets.load_iris()
X = iris.data
y = iris.target
class_names = iris.target_names
print(class_names)
df = pd.DataFrame(X, columns=iris.feature_names)
print(df.head())
print(df.describe())

@maxkleiner This is currently not fixed, the issue is still present.

@maxkleiner
Please use
X = iris["data"]
Y = iris["target"]

@yogendrabagoriya Thank you for the solution!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hubro picture Hubro  路  3Comments

ethanchewy picture ethanchewy  路  3Comments

GergelyKalmar picture GergelyKalmar  路  3Comments

glmdgrielson picture glmdgrielson  路  3Comments

adamtheturtle picture adamtheturtle  路  3Comments