microsoft / python-type-stubs

A set of type stubs for popular Python packages. These are works in progress from the Microsoft Python team and others, with the intent that they are contributed to typeshed or to the associated packages once sufficiently complete.
MIT License
252 stars 99 forks source link

Add overload function for sklearn to deal with sparse matrices #316

Closed ClementPinard closed 2 months ago

ClementPinard commented 2 months ago

Got in the situation where I used some rescaling with StandardScaler and numpy arrays, and pylance kept saying me that the output was possibly a sparse matrix.

I added overload for functions and classes in sklearn/preprocessing/_data.pyi to indicate that the output of those functions is only sparse when the input is itself sparse (up to some details, depending on the functions).

ClementPinard commented 2 months ago

@microsoft-github-policy-service agree

debonte commented 2 months ago

@ClementPinard, thanks for your contribution! There were a couple issues with the return_norm parameter on normalize. I fixed them and added tests.