Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Pylance complaining for sklearn.datasets.load_iris()

$
0
0

I am using Pylance with Type Checking Mode: Basic and I am loading the iris dataset with sklearn.datasets.load_iris().

from sklearn.datasets import load_irisdef main():    iris = load_iris()    data = iris.data

This code works for the Python interpreter but Pylance complains giving:

Cannot access member "data" for type "tuple[Bunch, tuple[Unknown, ...]]"Member "data" is unknown Pylance(reportAttributeAccessIssue)

So I tried type hinting hope to solve the issue adding

from sklearn.utils import Bunch    iris: Bunch = load_iris()

And now I get:

Expression of type "tuple[Bunch, tuple[Unknown, ...]]" cannot be assigned to declared type "Bunch""tuple[Bunch, tuple[Unknown, ...]]" is incompatible with "Bunch" Pylance(reportAssignmentType)

If instead I follow the suggestion of Pylance and unpack it as it was a tuple (which is not according to the docs) and do:

iris: Bunchiris, _ = load_iris()

Pylance warnings disappear but the code no longer works with error:

Traceback (most recent call last):File ".../main.py", line 10, in main()File ".../main.py", line 6, in mainiris, _ = load_iris()^^^^^^^ValueError: too many values to unpack (expected 2)

Looking at the source and the docs load_iris() should return a Bunch object not a tuple of two nor a tuple with more than two elements.

I would like to fix this with something other than # type: ignore and to fully understand the issue.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>